Skip to content

Conversation

@terry1purcell
Copy link
Contributor

What problem does this PR solve?

Issue Number: ref #64378

Problem Summary:

What changed and how does it work?

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. component/statistics sig/planner SIG: Planner size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Nov 16, 2025
@tiprow
Copy link

tiprow bot commented Nov 16, 2025

Hi @terry1purcell. 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.

@codecov
Copy link

codecov bot commented Nov 16, 2025

Codecov Report

❌ Patch coverage is 91.89189% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 73.6265%. Comparing base (e10a603) to head (d17339f).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files
@@               Coverage Diff                @@
##             master     #64510        +/-   ##
================================================
+ Coverage   72.6816%   73.6265%   +0.9448%     
================================================
  Files          1866       1889        +23     
  Lines        506282     514399      +8117     
================================================
+ Hits         367974     378734     +10760     
+ Misses       115918     112741      -3177     
- Partials      22390      22924       +534     
Flag Coverage Δ
integration 44.4912% <70.2702%> (?)
unit 72.5417% <91.8918%> (+0.2825%) ⬆️

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

Components Coverage Δ
dumpling 52.8700% <ø> (ø)
parser ∅ <ø> (∅)
br 46.2563% <ø> (+0.0951%) ⬆️
🚀 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.

@ti-chi-bot ti-chi-bot bot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Nov 16, 2025
@ti-chi-bot
Copy link

ti-chi-bot bot commented Nov 17, 2025

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign 0xpoe for approval. For more information see the Code Review Process.
Please ensure that each of them provides their approval before proceeding.

The full list of commands accepted by this bot can be found 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

@terry1purcell terry1purcell changed the title planner: out of range common prefix planner: out of range common prefix | tidb-test=pr/2630 Nov 17, 2025
@terry1purcell
Copy link
Contributor Author

/retest-required

@tiprow
Copy link

tiprow bot commented Nov 17, 2025

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

In response to this:

/retest-required

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

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR addresses issue #64378 related to "out of range common prefix" estimation in the query planner. The fix improves cardinality estimation when query ranges fall outside histogram bounds, particularly for string/byte comparisons where common prefix comparison results in equal scalar values (l == r).

Key changes:

  • Added highIsOpenEnded parameter to OutOfRangeRowCount to detect open-ended ranges (e.g., when upper bound is MaxValue)
  • Moved addedRows and modifyCount calculations earlier in the function to enable their use in the l == r case
  • Added special handling for l == r scenario with different estimates based on whether the range is open-ended
  • Changed the condition from l >= r to separate l > r and l == r cases for more accurate handling

Reviewed Changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.

Show a summary per file
File Description
pkg/statistics/histogram.go Core logic changes: added highIsOpenEnded parameter, moved calculations, and added special handling for l == r case
pkg/planner/cardinality/row_count_index.go Updated all call sites to detect and pass highIsOpenEnded flag based on index range high values
pkg/planner/cardinality/row_count_column.go Updated call site to detect and pass highIsOpenEnded flag based on column range high values
tests/integrationtest/r/planner/cardinality/selectivity.result Updated expected test results showing increased row count estimates from 1.00 to 2.00 for various queries
tests/integrationtest/r/imdbload.result Updated expected test results showing increased row count estimates (e.g., from 2.00 to 6.65, from 1.00 to 3.32)

Copy link
Contributor

@mjonss mjonss left a comment

Choose a reason for hiding this comment

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

So this will only change the estimate for open ended queries like WHERE b > 6 but not WHERE b BETWEEN 6 AND 2000000?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

component/statistics 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.

2 participants