tidb icon indicating copy to clipboard operation
tidb copied to clipboard

expression, planner: make the `Value` field of the `Constant` struct private | tidb-test=pr/2355

Open YangKeao opened this issue 1 year ago • 5 comments

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:

  1. The Constant is always constructed directly, like Constant{Value:..., ...}. If we avoid using .Value directly, all these codes need to be changed.
  2. The expression pkg is too big, and we also need to ensure the codes in expression pkg 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:

  1. I just want to get the .Value field, and I'm sure it's not a parameter and deferred function.
  2. I want to get the .Value field. If the current context is not in plan cache, evaluating parameter and deferred function is also fine.
  3. 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.

YangKeao avatar Jun 26 '24 12:06 YangKeao

[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.

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[bot] avatar Jun 26 '24 12:06 ti-chi-bot[bot]

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.

codecov[bot] avatar Jun 27 '24 07:06 codecov[bot]

[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.

ti-chi-bot[bot] avatar Jun 27 '24 11:06 ti-chi-bot[bot]

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

tiprow[bot] avatar Jun 27 '24 11:06 tiprow[bot]

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.

ti-chi-bot[bot] avatar Jul 05 '24 08:07 ti-chi-bot[bot]

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

ti-chi-bot[bot] avatar Sep 26 '25 15:09 ti-chi-bot[bot]