Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid re-executing the sub-query over again in PostgreSQL #3545

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

praiskup
Copy link
Member

@praiskup praiskup commented Dec 4, 2024

No description provided.

@praiskup praiskup changed the title WIP Avoid re-executing the sub-query over again in PostgreSQL Dec 4, 2024
@praiskup praiskup force-pushed the praiskup-postgres-wth branch from dd6c795 to 6c16025 Compare December 4, 2024 15:45
@praiskup
Copy link
Member Author

praiskup commented Dec 4, 2024

coprdb=# explain analyze SELECT build.memory_reqs AS build_memory_reqs, build.timeout AS build_timeout, build.enable_net AS build_enable_net, build.source_type AS build_source_type, build.source_json AS build_source_json, build.fail_type AS build_fail_type, build.is_background AS build_is_background, build.source_status AS build_source_status, build.srpm_url AS build_srpm_url, build.isolation AS build_isolation, build.bootstrap AS build_bootstrap, build.user_id AS build_user_id, build.copr_id AS build_copr_id, build.package_id AS build_package_id, build.webhook_history_id AS build_webhook_history_id, build.batch_id AS build_batch_id, build.module_id AS build_module_id, build.copr_dir_id AS build_copr_dir_id, build.scm_object_id AS build_scm_object_id, build.scm_object_type AS build_scm_object_type, build.scm_object_url AS build_scm_object_url, build.update_callback AS build_update_callback, build.submitted_by AS build_submitted_by, build.ssh_public_keys AS build_ssh_public_keys, build.resubmitted_from_id AS build_resubmitted_from_id                 FROM build 
        WHERE NOT build.canceled AND (build.id IN (SELECT build_chroot.build_id 
        FROM build_chroot                                                       
        WHERE build_chroot.status IN (3, 4, 6, 7, 9)) OR build.source_status IN (3, 4, 6, 7)) AND build.batch_id IS NOT NULL;
┌──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
│                                                                                QUERY PLAN                                                                                │
├──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┤
│ Index Scan using build_canceled on build  (cost=5755.92..592901781077.60 rows=958236 width=374) (actual time=66058.008..79360.870 rows=28 loops=1)                       │
│   Index Cond: (canceled = false)                                                                                                                                         │
│   Filter: ((batch_id IS NOT NULL) AND ((SubPlan 1) OR (source_status = ANY ('{3,4,6,7}'::integer[]))))                                                                   │
│   Rows Removed by Filter: 3743360                                                                                                                                        │
│   SubPlan 1                                                                                                                                                              │
│     ->  Materialize  (cost=5755.49..632909.76 rows=322750 width=4) (actual time=0.000..0.083 rows=1077 loops=393164)                                                     │
│           ->  Gather  (cost=5755.49..630035.01 rows=322750 width=4) (actual time=2.641..7.814 rows=1077 loops=1)                                                         │
│                 Workers Planned: 2                                                                                                                                       │
│                 Workers Launched: 2                                                                                                                                      │
│                 ->  Parallel Bitmap Heap Scan on build_chroot  (cost=4755.49..596760.01 rows=134479 width=4) (actual time=0.689..1.474 rows=359 loops=3)                 │
│                       Recheck Cond: (status = ANY ('{3,4,6,7,9}'::integer[]))                                                                                            │
│                       Heap Blocks: exact=299                                                                                                                             │
│                       ->  Bitmap Index Scan on build_chroot_status_started_on_idx  (cost=0.00..4674.80 rows=322750 width=0) (actual time=1.734..1.734 rows=8507 loops=1) │
│                             Index Cond: (status = ANY ('{3,4,6,7,9}'::integer[]))                                                                                        │
│ Planning Time: 2.462 ms                                                                                                                                                  │
│ Execution Time: 79360.997 ms                                                                                                                                             │
└──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘
(16 rows)

@nikromen nikromen marked this pull request as draft December 9, 2024 11:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants