Skip to content

fix(query): align profiles with physical plan scope#19963

Draft
dqhl76 wants to merge 2 commits into
databendlabs:mainfrom
dqhl76:fix-m-cte-profiles
Draft

fix(query): align profiles with physical plan scope#19963
dqhl76 wants to merge 2 commits into
databendlabs:mainfrom
dqhl76:fix-m-cte-profiles

Conversation

@dqhl76

@dqhl76 dqhl76 commented Jun 4, 2026

Copy link
Copy Markdown
Collaborator

I hereby agree to the terms of the CLA available at: https://docs.databend.com/dev/policies/cla/

Summary

Fix query profile plan id collisions when a query uses nested executors, such as materialized CTE execution.

Tests

  • Unit Test
  • Logic Test
  • Benchmark Test
  • No Test

Type of change

  • Bug Fix (non-breaking change which fixes an issue)
  • New Feature (non-breaking change which adds functionality)
  • Breaking Change (fix or feature that could cause existing functionality not to work as expected)
  • Documentation Update
  • Refactoring
  • Performance Improvement
  • Other (please describe):

This change is Reviewable

@github-actions github-actions Bot added the pr-bugfix this PR patches a bug in codebase label Jun 4, 2026
@dqhl76 dqhl76 changed the title fix(query): namespace query profiles by executor fix(query): align profiles with physical plan scope Jun 4, 2026
@dqhl76 dqhl76 force-pushed the fix-m-cte-profiles branch 2 times, most recently from 58d8f88 to 18c87e0 Compare June 4, 2026 12:37
@dqhl76 dqhl76 force-pushed the fix-m-cte-profiles branch from 18c87e0 to 24af834 Compare June 8, 2026 06:59
@dqhl76

dqhl76 commented Jun 9, 2026

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: a87a8b9267

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment on lines +38 to +42
pub fn add(&self, profiles: &HashMap<u32, PlanProfile>) {
let mut merged_profiles = self.profiles.lock();

for query_profile in profiles.values() {
match merged_profiles.entry((query_profile.group_id, query_profile.id)) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Preserve profile groups before merging executor results

This store keys by (group_id, plan_id), but add still accepts batches keyed only by u32; the batches produced by RunningGraph::fetch_profiling have already merged all nodes with the same plan_id via plans_profile.entry(*plan_id) before group_id is considered. When one executor contains multiple physical plan trees with overlapping ids (for example source pipelines built from separate plans), the first group's PlanProfile absorbs the other group's statistics, so get_by_group(main_group_id) can return overcounted main profiles while the other group disappears. The executor-side aggregation needs to key by group as well, or this new grouping cannot recover the separated profiles here.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

need to resolved? cc: @dqhl76

@zhang2014 zhang2014 marked this pull request as draft June 12, 2026 10:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-bugfix this PR patches a bug in codebase

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants