Skip to content

Conversation

@mjonss
Copy link
Contributor

@mjonss mjonss commented Nov 19, 2025

What problem does this PR solve?

Issue Number: close #64052

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.

Added `tidb_max_estimated_cost` to not execute queries with too high costs.

@ti-chi-bot ti-chi-bot bot added the release-note Denotes a PR that will be considered when it comes time to generate release notes. label Nov 19, 2025
@ti-chi-bot
Copy link

ti-chi-bot bot commented Nov 19, 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 benmeadowcroft, qw4990 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

@ti-chi-bot ti-chi-bot bot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. sig/planner SIG: Planner labels Nov 19, 2025
@mjonss mjonss requested a review from Copilot November 19, 2025 21:01
@tiprow
Copy link

tiprow bot commented Nov 19, 2025

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

Copilot finished reviewing on behalf of mjonss November 19, 2025 21:04
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 adds a new system variable tidb_max_estimated_cost to prevent execution of queries whose optimizer-estimated cost exceeds a specified threshold. This provides a mechanism to protect the database from running potentially expensive queries that could impact performance.

Key changes:

  • Introduces tidb_max_estimated_cost as a session/global variable with default value 0.0 (disabled)
  • Implements cost validation in both CascadesOptimize and physicalOptimize functions
  • Adds comprehensive tests for the variable configuration and query execution behavior

Reviewed Changes

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

Show a summary per file
File Description
pkg/sessionctx/vardef/tidb_vars.go Defines the new TiDBMaxEstimatedCost variable constant and its default value
pkg/sessionctx/variable/session.go Adds MaxEstimatedCost field to SessionVars to track the threshold
pkg/sessionctx/variable/sysvar.go Registers the system variable with appropriate scope, type, and validation
pkg/sessionctx/variable/sysvar_test.go Tests variable validation, setting session/global values, and error handling
pkg/planner/core/optimizer.go Implements cost checking logic in both optimization paths, rejecting queries that exceed the threshold
pkg/planner/core/plan_cost_ver1_test.go Integration tests verifying cost-based query rejection with different cost models and scenarios

@codecov
Copy link

codecov bot commented Nov 19, 2025

Codecov Report

❌ Patch coverage is 51.85185% with 13 lines in your changes missing coverage. Please review.
✅ Project coverage is 73.0514%. Comparing base (cea660d) to head (3c43b3f).
⚠️ Report is 3 commits behind head on master.

Additional details and impacted files
@@               Coverage Diff                @@
##             master     #64580        +/-   ##
================================================
- Coverage   74.6960%   73.0514%   -1.6447%     
================================================
  Files          1888       1866        -22     
  Lines        514956     506984      -7972     
================================================
- Hits         384652     370359     -14293     
- Misses       106483     114314      +7831     
+ Partials      23821      22311      -1510     
Flag Coverage Δ
integration 41.7349% <51.8518%> (-6.4205%) ⬇️

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

Components Coverage Δ
dumpling 52.8700% <ø> (ø)
parser ∅ <ø> (∅)
br 46.0770% <ø> (-17.1269%) ⬇️
🚀 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.

@mjonss
Copy link
Contributor Author

mjonss commented Nov 21, 2025

/retest

@tiprow
Copy link

tiprow bot commented Nov 21, 2025

@mjonss: 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.

@ti-chi-bot
Copy link

ti-chi-bot bot commented Nov 21, 2025

@mjonss: The following tests failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
pull-unit-test-next-gen 3c43b3f link true /test pull-unit-test-next-gen
idc-jenkins-ci-tidb/unit-test 3c43b3f link true /test unit-test

Full PR test history. Your PR dashboard.

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. I understand the commands that are listed here.

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

Labels

release-note Denotes a PR that will be considered when it comes time to generate release notes. 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.

Add tidb_max_estimated_cost to prevent very expensive queries to start executing

1 participant