Skip to content

planner: set the default of the tidb_cost_model_version correctly #61608

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

Merged
merged 1 commit into from
Jun 10, 2025

Conversation

hawkingrei
Copy link
Member

@hawkingrei hawkingrei commented Jun 9, 2025

What problem does this PR solve?

Issue Number: close #61565

Problem Summary:

What changed and how does it work?

We don't set the default of the tidb_cost_model_version in the right place. so it led many problems in the internal SQL. The internal SQL will not use the cost model v2.

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.

planner: rightly set the default of the tidb_cost_model_version

正确设置 tidb_cost_model_version 的默认值

Signed-off-by: Weizhen Wang <wangweizhen@pingcap.com>
@ti-chi-bot ti-chi-bot bot added do-not-merge/needs-tests-checked release-note-none Denotes a PR that doesn't merit a release note. sig/planner SIG: Planner size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. and removed do-not-merge/needs-tests-checked labels Jun 9, 2025
@hawkingrei hawkingrei changed the title planner: rightly set the tidb_cost_model_version planner: rightly set the default of the tidb_cost_model_version Jun 9, 2025
@ti-chi-bot ti-chi-bot bot added release-note Denotes a PR that will be considered when it comes time to generate release notes. and removed release-note-none Denotes a PR that doesn't merit a release note. labels Jun 9, 2025
@@ -87,6 +88,7 @@ func (p *PhysicalProjection) GetCost(count float64) float64 {

// GetPlanCostVer1 calculates the cost of the plan if it has not been calculated yet and returns the cost.
func (p *PhysicalProjection) GetPlanCostVer1(taskType property.TaskType, option *optimizetrace.PlanCostOption) (float64, error) {
intest.Assert(p.SCtx().GetSessionVars().CostModelVersion != 0)
Copy link
Member Author

Choose a reason for hiding this comment

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

CostModelVersion's value is only 1 or 2, so if we get 0, it has a problem.

Copy link

codecov bot commented Jun 9, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 73.5543%. Comparing base (07e1f41) to head (5c824ed).
Report is 4 commits behind head on master.

Additional details and impacted files
@@               Coverage Diff                @@
##             master     #61608        +/-   ##
================================================
+ Coverage   73.1044%   73.5543%   +0.4498%     
================================================
  Files          1729       1729                
  Lines        481039     481130        +91     
================================================
+ Hits         351661     353892      +2231     
+ Misses       107839     105751      -2088     
+ Partials      21539      21487        -52     
Flag Coverage Δ
integration 42.4119% <100.0000%> (?)
unit 72.4211% <100.0000%> (+0.0520%) ⬆️

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

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

@tiancaiamao tiancaiamao changed the title planner: rightly set the default of the tidb_cost_model_version planner: set the default of the tidb_cost_model_version correctly Jun 10, 2025
@ti-chi-bot ti-chi-bot bot added the needs-1-more-lgtm Indicates a PR needs 1 more LGTM. label Jun 10, 2025
@ti-chi-bot ti-chi-bot bot added lgtm and removed needs-1-more-lgtm Indicates a PR needs 1 more LGTM. labels Jun 10, 2025
Copy link

ti-chi-bot bot commented Jun 10, 2025

[LGTM Timeline notifier]

Timeline:

  • 2025-06-10 00:57:04.805632586 +0000 UTC m=+316603.033947835: ☑️ agreed by qw4990.
  • 2025-06-10 01:11:58.090288939 +0000 UTC m=+317496.318604200: ☑️ agreed by tiancaiamao.

Copy link

ti-chi-bot bot commented Jun 10, 2025

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: qw4990, tiancaiamao, yudongusa

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 the approved label Jun 10, 2025
@ti-chi-bot ti-chi-bot bot merged commit 1ef4c26 into pingcap:master Jun 10, 2025
24 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved lgtm release-note Denotes a PR that will be considered when it comes time to generate release notes. sig/planner SIG: Planner size/XS Denotes a PR that changes 0-9 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

internal SQL wrongly use get plan cost v1
4 participants