tidb
tidb copied to clipboard
expression, planner: make the `Value` field of the `Constant` struct private | tidb-test=pr/2355
What problem does this PR solve?
Issue Number: close #53504
Problem Summary:
Using .Value directly can easily cause wrong result and dangerous bug, especially for plan cache. We have found #53504 #53505 (and potentially many others). It's not possible to depend on test cases to avoid making mistakes in the future. Therefore, I propose to make .Value private.
What changed and how does it work?
However, it's not simple to make .Value private, because:
- The
Constantis always constructed directly, likeConstant{Value:..., ...}. If we avoid using.Valuedirectly, all these codes need to be changed. - The
expressionpkg is too big, and we also need to ensure the codes inexpressionpkg cannot access the.Value. However, golang allows the codes in the same package to access the private field.
Therefore, I wrote a linter to filter out all selector expression to get the .Value.
It's also hard to keep the correctness. I've considered the following three situations:
- I just want to get the
.Valuefield, and I'm sure it's not a parameter and deferred function. - I want to get the
.Valuefield. If the current context is not in plan cache, evaluating parameter and deferred function is also fine. - I want to evaluate the parameter, deferred function, or simply return the value.
For most of the codes in optimizing stage, it should call 2. For the code in executing stage, it usually should call 3. We provide GetValue(), GetValueWithoutOverOptimization(), and .Eval for these three circumstances.
Check List
Tests
- [ ] Unit test
- [x] Integration test
- [ ] Manual test (add detailed scripts or steps below)
- [ ] No need to test
- [ ] I checked and no code files have been changed.
Release note
Please refer to Release Notes Language Style Guide to write a quality release note.
Fix the issue that in some situation, the result is different if the query is using plan cache.
[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 hawkingrei, xuhuaiyu for approval, ensuring that each of them provides their approval before proceeding. For more information see the Code Review Process.
The full list of commands accepted by this bot can be found here.
Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment
Codecov Report
:x: Patch coverage is 23.16716% with 262 lines in your changes missing coverage. Please review.
:white_check_mark: Project coverage is 50.8441%. Comparing base (1469fcf) to head (8a1cd57).
:warning: Report is 2979 commits behind head on master.
Additional details and impacted files
@@ Coverage Diff @@
## master #54244 +/- ##
=================================================
- Coverage 74.7940% 50.8441% -23.9499%
=================================================
Files 1523 1643 +120
Lines 361510 608416 +246906
=================================================
+ Hits 270388 309344 +38956
- Misses 71504 275391 +203887
- Partials 19618 23681 +4063
| Flag | Coverage Δ | |
|---|---|---|
| integration | 29.2449% <23.1671%> (?) |
Flags with carried forward coverage won't be shown. Click here to find out more.
| Components | Coverage Δ | |
|---|---|---|
| dumpling | ∅ <ø> (∅) |
|
| parser | ∅ <ø> (∅) |
|
| br | 48.6883% <ø> (+0.0328%) |
:arrow_up: |
:rocket: New features to boost your workflow:
- :snowflake: Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
- :package: JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.
[FORMAT CHECKER NOTIFICATION]
Notice: To remove the do-not-merge/needs-tests-checked label, please finished the tests then check the finished items in description.
For example:
Tests
- [x] Unit test
- [ ] Integration test
- [ ] Manual test (add detailed scripts or steps below)
- [ ] No code
:open_book: For more info, you can check the "Contribute Code" section in the development guide.
@YangKeao: The following test failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:
| Test name | Commit | Details | Required | Rerun command |
|---|---|---|---|---|
| fast_test_tiprow | 8a1cd5701bd21960ff7237558929150e3d109105 | link | true | /test fast_test_tiprow |
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.
PR needs rebase.
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/test-infra repository.
@YangKeao: 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-mysql-client-test | 8a1cd5701bd21960ff7237558929150e3d109105 | link | true | /test pull-mysql-client-test |
| idc-jenkins-ci-tidb/mysql-test | 8a1cd5701bd21960ff7237558929150e3d109105 | link | true | /test mysql-test |
| idc-jenkins-ci-tidb/check_dev | 8a1cd5701bd21960ff7237558929150e3d109105 | link | true | /test check-dev |
| idc-jenkins-ci-tidb/unit-test | 8a1cd5701bd21960ff7237558929150e3d109105 | link | true | /test unit-test |
| idc-jenkins-ci-tidb/check_dev_2 | 8a1cd5701bd21960ff7237558929150e3d109105 | link | true | /test check-dev2 |
| pull-integration-e2e-test | 8a1cd5701bd21960ff7237558929150e3d109105 | link | true | /test pull-integration-e2e-test |
| pull-integration-realcluster-test-next-gen | 8a1cd5701bd21960ff7237558929150e3d109105 | link | true | /test pull-integration-realcluster-test-next-gen |
| pull-unit-test-next-gen | 8a1cd5701bd21960ff7237558929150e3d109105 | link | true | /test pull-unit-test-next-gen |
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.