Skip to content

Conversation

qw4990
Copy link
Contributor

@qw4990 qw4990 commented Jun 9, 2025

What problem does this PR solve?

Issue Number: close #61602

Problem Summary: planner: fix the wrong join estimation depending on missing or uninitialized stats

What changed and how does it work?

planner: fix the wrong join estimation depending on missing or uninitialized stats

It's hard to construct test cases for this issue since it depends on stats cache's status. So I tested it locally, and this PR can work for this scenario:

image

Check List

Tests

  • Unit test
  • Integration test
  • Manual test (add detailed scripts or steps below)
  • No need to test
    • I checked and no code files have been changed.

Side effects

  • Performance regression: Consumes more CPU
  • Performance regression: Consumes more Memory
  • Breaking backward compatibility

Documentation

  • Affects user behaviors
  • Contains syntax changes
  • Contains variable changes
  • Contains experimental features
  • Changes MySQL compatibility

Release note

Please refer to Release Notes Language Style Guide to write a quality release note.

None

@ti-chi-bot ti-chi-bot bot added release-note-none Denotes a PR that doesn't merit a release note. do-not-merge/needs-triage-completed size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. sig/planner SIG: Planner labels Jun 9, 2025
Copy link

tiprow bot commented Jun 9, 2025

Hi @qw4990. Thanks for your PR.

PRs from untrusted users cannot be marked as trusted with /ok-to-test in this repo meaning untrusted PR authors can never trigger tests themselves. Collaborators can still trigger tests on the PR using /test all.

I understand the commands that are listed here.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@hawkingrei
Copy link
Member

/retest

Copy link

codecov bot commented Jun 9, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 73.8131%. Comparing base (07e1f41) to head (975be8f).
Report is 55 commits behind head on master.

Additional details and impacted files
@@               Coverage Diff                @@
##             master     #61604        +/-   ##
================================================
+ Coverage   73.1044%   73.8131%   +0.7086%     
================================================
  Files          1729       1729                
  Lines        481039     484361      +3322     
================================================
+ Hits         351661     357522      +5861     
+ Misses       107839     105383      -2456     
+ Partials      21539      21456        -83     
Flag Coverage Δ
integration 42.3901% <100.0000%> (?)
unit 72.6912% <100.0000%> (+0.3222%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Components Coverage Δ
dumpling 52.7804% <ø> (ø)
parser ∅ <ø> (∅)
br 47.1658% <ø> (+0.2081%) ⬆️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@qw4990
Copy link
Contributor Author

qw4990 commented Jun 9, 2025

/retest

Copy link

tiprow bot commented Jun 9, 2025

@qw4990: Cannot trigger testing until a trusted user reviews the PR and leaves an /ok-to-test message.

In response to this:

/retest

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@@ -472,7 +472,7 @@ func getGroupNDVs(ds *logicalop.DataSource) []property.GroupNDV {
break
}
}
if match {
Copy link
Contributor

Choose a reason for hiding this comment

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

If there is no stats in the cache which means that it will return false in here. So what is the behavior of this situation ?

@0xPoe
Copy link
Member

0xPoe commented Jun 9, 2025

/cc

@ti-chi-bot ti-chi-bot bot requested a review from 0xPoe June 9, 2025 14:24
@ti-chi-bot ti-chi-bot bot added approved needs-1-more-lgtm Indicates a PR needs 1 more LGTM. needs-cherry-pick-release-8.1 Should cherry pick this PR to release-8.1 branch. needs-cherry-pick-release-7.5 Should cherry pick this PR to release-7.5 branch. needs-cherry-pick-release-7.1 Should cherry pick this PR to release-7.1 branch. needs-cherry-pick-release-6.5 Should cherry pick this PR to release-6.5 branch. labels Jun 10, 2025
@ti-chi-bot ti-chi-bot bot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. labels Jun 10, 2025
├─IndexRangeScan(Build) 10000.00 cop[tikv] table:t2, index:PRIMARY(a, b, c) range: decided by [eq(executor__index_lookup_merge_join.t2.a, executor__index_lookup_merge_join.t1.a) eq(executor__index_lookup_merge_join.t2.b, executor__index_lookup_merge_join.t1.b) eq(executor__index_lookup_merge_join.t2.c, executor__index_lookup_merge_join.t1.c)], keep order:false, stats:pseudo
└─TableRowIDScan(Probe) 10000.00 cop[tikv] table:t2 keep order:false, stats:pseudo
Sort 12500.00 root executor__index_lookup_merge_join.t1.a:desc
└─HashJoin 12500.00 root left outer join, left side:TableReader, equal:[eq(executor__index_lookup_merge_join.t1.a, executor__index_lookup_merge_join.t2.a) eq(executor__index_lookup_merge_join.t1.c, executor__index_lookup_merge_join.t2.c) eq(executor__index_lookup_merge_join.t1.b, executor__index_lookup_merge_join.t2.b)]
Copy link
Contributor Author

Choose a reason for hiding this comment

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

12500 seems more reasonable, the prior 100000000.00 it not accurate.

Copy link
Member

@0xPoe 0xPoe left a comment

Choose a reason for hiding this comment

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

Thanks!

@@ -472,7 +472,7 @@ func getGroupNDVs(ds *logicalop.DataSource) []property.GroupNDV {
break
}
}
if match {
if match && idx.IsEssentialStatsLoaded() {
Copy link
Member

Choose a reason for hiding this comment

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

Can we add some comments to explain why we need this extra check? Thanks!

@qw4990
Copy link
Contributor Author

qw4990 commented Jun 11, 2025

/retest

Copy link

tiprow bot commented Jun 11, 2025

@qw4990: Cannot trigger testing until a trusted user reviews the PR and leaves an /ok-to-test message.

In response to this:

/retest

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

Copy link

ti-chi-bot bot commented Jun 11, 2025

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: AilinKid, hawkingrei

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@ti-chi-bot ti-chi-bot bot added lgtm and removed needs-1-more-lgtm Indicates a PR needs 1 more LGTM. labels Jun 11, 2025
Copy link

ti-chi-bot bot commented Jun 11, 2025

[LGTM Timeline notifier]

Timeline:

  • 2025-06-10 02:33:58.265942424 +0000 UTC m=+322416.494257684: ☑️ agreed by AilinKid.
  • 2025-06-11 10:42:38.040751054 +0000 UTC m=+438136.269066318: ☑️ agreed by hawkingrei.

@ti-chi-bot ti-chi-bot bot merged commit 8d02f1f into pingcap:master Jun 11, 2025
24 checks passed
ti-chi-bot pushed a commit to ti-chi-bot/tidb that referenced this pull request Jun 11, 2025
@ti-chi-bot
Copy link
Member

In response to a cherrypick label: new pull request created to branch release-8.1: #61673.
But this PR has conflicts, please resolve them!

@ti-chi-bot
Copy link
Member

In response to a cherrypick label: new pull request created to branch release-6.5: #61674.
But this PR has conflicts, please resolve them!

ti-chi-bot pushed a commit to ti-chi-bot/tidb that referenced this pull request Jun 11, 2025
ti-chi-bot pushed a commit to ti-chi-bot/tidb that referenced this pull request Jun 11, 2025
@ti-chi-bot
Copy link
Member

In response to a cherrypick label: new pull request created to branch release-7.1: #61675.
But this PR has conflicts, please resolve them!

@ti-chi-bot
Copy link
Member

In response to a cherrypick label: new pull request created to branch release-7.5: #61676.
But this PR has conflicts, please resolve them!

@ti-chi-bot
Copy link
Member

In response to a cherrypick label: new pull request created to branch release-8.5: #61857.
But this PR has conflicts, please resolve them!

ti-chi-bot pushed a commit to ti-chi-bot/tidb that referenced this pull request Jun 19, 2025
ti-chi-bot bot pushed a commit that referenced this pull request Jul 9, 2025
ti-chi-bot bot pushed a commit that referenced this pull request Jul 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved lgtm needs-cherry-pick-release-6.5 Should cherry pick this PR to release-6.5 branch. needs-cherry-pick-release-7.1 Should cherry pick this PR to release-7.1 branch. needs-cherry-pick-release-7.5 Should cherry pick this PR to release-7.5 branch. needs-cherry-pick-release-8.1 Should cherry pick this PR to release-8.1 branch. needs-cherry-pick-release-8.5 Should cherry pick this PR to release-8.5 branch. release-note-none Denotes a PR that doesn't merit a release note. sig/planner SIG: Planner size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

planner: wrong Join estimation depending on uninitialized or missing stats
6 participants