Reduce query for popular worker ExpireJobCacheWorker
What does this MR do?
Reduce query for popular worker ExpireJobCacheWorker
Related issues:
Queries before
SELECT "ci_builds".* FROM "ci_builds" INNER JOIN "ci_pipelines" ON "ci_pipelines"."id" = "ci_builds"."commit_id" INNER JOIN "projects" ON "projects"."id" = "ci_builds"."project_id" WHERE "ci_builds"."id" = 1 LIMIT 1 /*application:test*/
SELECT "ci_pipelines".* FROM "ci_pipelines" WHERE "ci_pipelines"."id" = 1 LIMIT 1 /*application:test*/
SELECT "projects".* FROM "projects" WHERE "projects"."id" = 1 LIMIT 1 /*application:test*/
SELECT "namespaces".* FROM "namespaces" WHERE "namespaces"."id" = 1 LIMIT 1 /*application:test*/
SELECT "routes".* FROM "routes" WHERE "routes"."source_id" = 1 AND "routes"."source_type" = 'Namespace' LIMIT 1 /*application:test*/
- https://console.postgres.ai/gitlab/gitlab-production-tunnel/sessions/3038/commands/9989
- https://console.postgres.ai/gitlab/gitlab-production-tunnel/sessions/2928/commands/9334
- https://console.postgres.ai/gitlab/gitlab-production-tunnel/sessions/2928/commands/9335
- https://console.postgres.ai/gitlab/gitlab-production-tunnel/sessions/2928/commands/9336
- https://console.postgres.ai/gitlab/gitlab-production-tunnel/sessions/2928/commands/9337
Planning time (24.371 + 4.797 + 4.852 + 2.070 + 0.913): 37.003 ms Execution time (36.057 + 0.318 + 13.662 + 6.183 + 7.995): 64.215 ms
Queries after
SELECT "ci_builds"."id" AS t0_r0, "ci_builds"."status" AS t0_r1, "ci_builds"."finished_at" AS t0_r2, "ci_builds"."trace" AS t0_r3, "ci_builds"."created_at" AS t0_r4, "ci_builds"."updated_at" AS t0_r5, "ci_builds"."started_at" AS t0_r6, "ci_builds"."runner_id" AS t0_r7, "ci_builds"."coverage" AS t0_r8, "ci_builds"."commit_id" AS t0_r9, "ci_builds"."name" AS t0_r10, "ci_builds"."options" AS t0_r11, "ci_builds"."allow_failure" AS t0_r12, "ci_builds"."stage" AS t0_r13, "ci_builds"."trigger_request_id" AS t0_r14, "ci_builds"."stage_idx" AS t0_r15, "ci_builds"."tag" AS t0_r16, "ci_builds"."ref" AS t0_r17, "ci_builds"."user_id" AS t0_r18, "ci_builds"."type" AS t0_r19, "ci_builds"."target_url" AS t0_r20, "ci_builds"."description" AS t0_r21, "ci_builds"."project_id" AS t0_r22, "ci_builds"."erased_by_id" AS t0_r23, "ci_builds"."erased_at" AS t0_r24, "ci_builds"."artifacts_expire_at" AS t0_r25, "ci_builds"."environment" AS t0_r26, "ci_builds"."when" AS t0_r27, "ci_builds"."yaml_variables" AS t0_r28, "ci_builds"."queued_at" AS t0_r29, "ci_builds"."token" AS t0_r30, "ci_builds"."lock_version" AS t0_r31, "ci_builds"."coverage_regex" AS t0_r32, "ci_builds"."auto_canceled_by_id" AS t0_r33, "ci_builds"."retried" AS t0_r34, "ci_builds"."stage_id" AS t0_r35, "ci_builds"."protected" AS t0_r36, "ci_builds"."failure_reason" AS t0_r37, "ci_builds"."scheduled_at" AS t0_r38, "ci_builds"."token_encrypted" AS t0_r39, "ci_builds"."upstream_pipeline_id" AS t0_r40, "ci_builds"."resource_group_id" AS t0_r41, "ci_builds"."waiting_for_resource_at" AS t0_r42, "ci_builds"."processed" AS t0_r43, "ci_builds"."scheduling_type" AS t0_r44, "ci_pipelines"."id" AS t1_r0, "ci_pipelines"."ref" AS t1_r1, "ci_pipelines"."sha" AS t1_r2, "ci_pipelines"."before_sha" AS t1_r3, "ci_pipelines"."created_at" AS t1_r4, "ci_pipelines"."updated_at" AS t1_r5, "ci_pipelines"."tag" AS t1_r6, "ci_pipelines"."yaml_errors" AS t1_r7, "ci_pipelines"."committed_at" AS t1_r8, "ci_pipelines"."project_id" AS t1_r9, "ci_pipelines"."status" AS t1_r10, "ci_pipelines"."started_at" AS t1_r11, "ci_pipelines"."finished_at" AS t1_r12, "ci_pipelines"."duration" AS t1_r13, "ci_pipelines"."user_id" AS t1_r14, "ci_pipelines"."lock_version" AS t1_r15, "ci_pipelines"."auto_canceled_by_id" AS t1_r16, "ci_pipelines"."pipeline_schedule_id" AS t1_r17, "ci_pipelines"."source" AS t1_r18, "ci_pipelines"."config_source" AS t1_r19, "ci_pipelines"."protected" AS t1_r20, "ci_pipelines"."failure_reason" AS t1_r21, "ci_pipelines"."iid" AS t1_r22, "ci_pipelines"."merge_request_id" AS t1_r23, "ci_pipelines"."source_sha" AS t1_r24, "ci_pipelines"."target_sha" AS t1_r25, "ci_pipelines"."external_pull_request_id" AS t1_r26, "ci_pipelines"."ci_ref_id" AS t1_r27, "ci_pipelines"."locked" AS t1_r28, "projects"."id" AS t2_r0, "projects"."name" AS t2_r1, "projects"."path" AS t2_r2, "projects"."description" AS t2_r3, "projects"."created_at" AS t2_r4, "projects"."updated_at" AS t2_r5, "projects"."creator_id" AS t2_r6, "projects"."namespace_id" AS t2_r7, "projects"."last_activity_at" AS t2_r8, "projects"."import_url" AS t2_r9, "projects"."visibility_level" AS t2_r10, "projects"."archived" AS t2_r11, "projects"."avatar" AS t2_r12, "projects"."merge_requests_template" AS t2_r13, "projects"."star_count" AS t2_r14, "projects"."merge_requests_rebase_enabled" AS t2_r15, "projects"."import_type" AS t2_r16, "projects"."import_source" AS t2_r17, "projects"."approvals_before_merge" AS t2_r18, "projects"."reset_approvals_on_push" AS t2_r19, "projects"."merge_requests_ff_only_enabled" AS t2_r20, "projects"."issues_template" AS t2_r21, "projects"."mirror" AS t2_r22, "projects"."mirror_last_update_at" AS t2_r23, "projects"."mirror_last_successful_update_at" AS t2_r24, "projects"."mirror_user_id" AS t2_r25, "projects"."shared_runners_enabled" AS t2_r26, "projects"."runners_token" AS t2_r27, "projects"."build_coverage_regex" AS t2_r28, "projects"."build_allow_git_fetch" AS t2_r29, "projects"."build_timeout" AS t2_r30, "projects"."mirror_trigger_builds" AS t2_r31, "projects"."pending_delete" AS t2_r32, "projects"."public_builds" AS t2_r33, "projects"."last_repository_check_failed" AS t2_r34, "projects"."last_repository_check_at" AS t2_r35, "projects"."container_registry_enabled" AS t2_r36, "projects"."only_allow_merge_if_pipeline_succeeds" AS t2_r37, "projects"."has_external_issue_tracker" AS t2_r38, "projects"."repository_storage" AS t2_r39, "projects"."repository_read_only" AS t2_r40, "projects"."request_access_enabled" AS t2_r41, "projects"."has_external_wiki" AS t2_r42, "projects"."ci_config_path" AS t2_r43, "projects"."lfs_enabled" AS t2_r44, "projects"."description_html" AS t2_r45, "projects"."only_allow_merge_if_all_discussions_are_resolved" AS t2_r46, "projects"."repository_size_limit" AS t2_r47, "projects"."printing_merge_request_link_enabled" AS t2_r48, "projects"."auto_cancel_pending_pipelines" AS t2_r49, "projects"."service_desk_enabled" AS t2_r50, "projects"."cached_markdown_version" AS t2_r51, "projects"."delete_error" AS t2_r52, "projects"."last_repository_updated_at" AS t2_r53, "projects"."disable_overriding_approvers_per_merge_request" AS t2_r54, "projects"."storage_version" AS t2_r55, "projects"."resolve_outdated_diff_discussions" AS t2_r56, "projects"."remote_mirror_available_overridden" AS t2_r57, "projects"."only_mirror_protected_branches" AS t2_r58, "projects"."pull_mirror_available_overridden" AS t2_r59, "projects"."jobs_cache_index" AS t2_r60, "projects"."external_authorization_classification_label" AS t2_r61, "projects"."mirror_overwrites_diverged_branches" AS t2_r62, "projects"."pages_https_only" AS t2_r63, "projects"."external_webhook_token" AS t2_r64, "projects"."packages_enabled" AS t2_r65, "projects"."merge_requests_author_approval" AS t2_r66, "projects"."pool_repository_id" AS t2_r67, "projects"."runners_token_encrypted" AS t2_r68, "projects"."bfg_object_map" AS t2_r69, "projects"."detected_repository_languages" AS t2_r70, "projects"."merge_requests_disable_committers_approval" AS t2_r71, "projects"."require_password_to_approve" AS t2_r72, "projects"."emails_disabled" AS t2_r73, "projects"."max_pages_size" AS t2_r74, "projects"."max_artifacts_size" AS t2_r75, "projects"."pull_mirror_branch_prefix" AS t2_r76, "projects"."remove_source_branch_after_merge" AS t2_r77, "projects"."marked_for_deletion_at" AS t2_r78, "projects"."marked_for_deletion_by_user_id" AS t2_r79, "projects"."autoclose_referenced_issues" AS t2_r80, "projects"."suggestion_commit_message" AS t2_r81, "namespaces"."id" AS t3_r0, "namespaces"."name" AS t3_r1, "namespaces"."path" AS t3_r2, "namespaces"."owner_id" AS t3_r3, "namespaces"."created_at" AS t3_r4, "namespaces"."updated_at" AS t3_r5, "namespaces"."type" AS t3_r6, "namespaces"."description" AS t3_r7, "namespaces"."avatar" AS t3_r8, "namespaces"."membership_lock" AS t3_r9, "namespaces"."share_with_group_lock" AS t3_r10, "namespaces"."visibility_level" AS t3_r11, "namespaces"."request_access_enabled" AS t3_r12, "namespaces"."ldap_sync_status" AS t3_r13, "namespaces"."ldap_sync_error" AS t3_r14, "namespaces"."ldap_sync_last_update_at" AS t3_r15, "namespaces"."ldap_sync_last_successful_update_at" AS t3_r16, "namespaces"."ldap_sync_last_sync_at" AS t3_r17, "namespaces"."description_html" AS t3_r18, "namespaces"."lfs_enabled" AS t3_r19, "namespaces"."parent_id" AS t3_r20, "namespaces"."shared_runners_minutes_limit" AS t3_r21, "namespaces"."repository_size_limit" AS t3_r22, "namespaces"."require_two_factor_authentication" AS t3_r23, "namespaces"."two_factor_grace_period" AS t3_r24, "namespaces"."cached_markdown_version" AS t3_r25, "namespaces"."project_creation_level" AS t3_r26, "namespaces"."runners_token" AS t3_r27, "namespaces"."file_template_project_id" AS t3_r28, "namespaces"."saml_discovery_token" AS t3_r29, "namespaces"."runners_token_encrypted" AS t3_r30, "namespaces"."custom_project_templates_group_id" AS t3_r31, "namespaces"."auto_devops_enabled" AS t3_r32, "namespaces"."extra_shared_runners_minutes_limit" AS t3_r33, "namespaces"."last_ci_minutes_notification_at" AS t3_r34, "namespaces"."last_ci_minutes_usage_notification_level" AS t3_r35, "namespaces"."subgroup_creation_level" AS t3_r36, "namespaces"."emails_disabled" AS t3_r37, "namespaces"."max_pages_size" AS t3_r38, "namespaces"."max_artifacts_size" AS t3_r39, "namespaces"."mentions_disabled" AS t3_r40, "namespaces"."default_branch_protection" AS t3_r41, "namespaces"."unlock_membership_to_ldap" AS t3_r42, "namespaces"."max_personal_access_token_lifetime" AS t3_r43, "namespaces"."push_rule_id" AS t3_r44, "namespaces"."shared_runners_enabled" AS t3_r45, "namespaces"."allow_descendants_override_disabled_shared_runners" AS t3_r46, "namespaces"."traversal_ids" AS t3_r47, "routes"."id" AS t4_r0, "routes"."source_id" AS t4_r1, "routes"."source_type" AS t4_r2, "routes"."path" AS t4_r3, "routes"."created_at" AS t4_r4, "routes"."updated_at" AS t4_r5, "routes"."name" AS t4_r6 FROM "ci_builds" LEFT OUTER JOIN "ci_pipelines" ON "ci_pipelines"."id" = "ci_builds"."commit_id" LEFT OUTER JOIN "projects" ON "projects"."id" = "ci_builds"."project_id" LEFT OUTER JOIN "namespaces" ON "namespaces"."id" = "projects"."namespace_id" LEFT OUTER JOIN "routes" ON "routes"."source_type" = 'Namespace' AND "routes"."source_id" = "namespaces"."id" WHERE "ci_builds"."id" = 1 LIMIT 1 /*application:test*/
https://console.postgres.ai/gitlab/gitlab-production-tunnel/sessions/3038/commands/9990
Time: 18.968 ms
- planning: 6.957 ms
- execution: 12.011 ms
- I/O read: 11.122 ms
- I/O write: N/A
Shared buffers:
- hits: 18 (~144.00 KiB) from the buffer pool
- reads: 7 (~56.00 KiB) from the OS file cache, including disk I/O
- dirtied: 0
- writes: 0
Does this MR meet the acceptance criteria?
Conformity
-
📋 Does this MR need a changelog?-
I have included a changelog entry. - [-] I have not included a changelog entry because _____.
-
- [-] Documentation (if required)
-
Code review guidelines -
Merge request performance guidelines -
Style guides -
Database guides - [-] Separation of EE specific content
Availability and Testing
-
Review and add/update tests for this feature/bug. Consider all test levels. See the Test Planning Process.
Edited by Thong Kuah