-
Notifications
You must be signed in to change notification settings - Fork 6.1k
planner: Add tidb_max_estimated_cost to prevent trying to run too expensive queries #64580
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
base: master
Are you sure you want to change the base?
Conversation
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: 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 |
|
Hi @mjonss. Thanks for your PR. PRs from untrusted users cannot be marked as trusted with 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. |
There was a problem hiding this 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_costas 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 Report❌ Patch coverage is 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
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
|
/retest |
|
@mjonss: Cannot trigger testing until a trusted user reviews the PR and leaves an In response to this:
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. |
|
@mjonss: The following tests failed, say
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. |
What problem does this PR solve?
Issue Number: close #64052
Problem Summary:
What changed and how does it work?
Check List
Tests
Side effects
Documentation
Release note
Please refer to Release Notes Language Style Guide to write a quality release note.