tidb icon indicating copy to clipboard operation
tidb copied to clipboard

expression,*: remove the session context inside `ParamMarker`

Open YangKeao opened this issue 1 year ago • 9 comments

What problem does this PR solve?

Issue Number: close #53533

Problem Summary:

Previously, the code stores a reference to the session context in ParamMarker. It convenient for re-using the expression in the plan cache inside a single session. However, it blocks us from achieving the following goals:

  1. We cannot evaluate the expression whiling the params on session is changing. It will happen if we enabled lazy-cursor fetch.
  2. The plan cache cannot be re-used across different sessions, because the expression will always reference to the session on which it's cached.

This PR depends on #53922 now.

What changed and how does it work?

  1. Remove the session context inside ParamMarker, and pass it through argument.
  2. Add EvalContext argument for GetType and GetUserVar.
  3. Add a new method StringWithCtx to stringify the expression with a given context.

It's also fine to use the StringWithCtx with nil argument directly, but it'll print ? for the params.

The biggest challenge is that the String is implicitly used in many places: like formatter and error / warnings. I wrote a linter to detect all the cases, you can find it in /build/linter/printexpression. It ensures that all struct/interface (and the reference/slice of them) which implements StringWithCtx but doesn't implement String cannot be used as an argument of format function.

Check List

Tests

  • [x] 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.

Release note

Please refer to Release Notes Language Style Guide to write a quality release note.

None

YangKeao avatar May 24 '24 06:05 YangKeao

Skipping CI for Draft Pull Request. If you want CI signal for your change, please convert it to an actual PR. You can still manually trigger a test run with /test all

ti-chi-bot[bot] avatar May 24 '24 06:05 ti-chi-bot[bot]

Skipping CI for Draft Pull Request. If you want CI signal for your change, please convert it to an actual PR. You can still manually trigger a test run with /test all

tiprow[bot] avatar May 24 '24 06:05 tiprow[bot]

Codecov Report

Attention: Patch coverage is 76.08696% with 88 lines in your changes missing coverage. Please review.

Project coverage is 56.0800%. Comparing base (91bf332) to head (bbfa315). Report is 14 commits behind head on master.

Additional details and impacted files
@@                Coverage Diff                @@
##             master     #53534         +/-   ##
=================================================
- Coverage   72.8313%   56.0800%   -16.7514%     
=================================================
  Files          1530       1654        +124     
  Lines        435981     610615     +174634     
=================================================
+ Hits         317531     342433      +24902     
- Misses        98809     244809     +146000     
- Partials      19641      23373       +3732     
Flag Coverage Δ
integration 37.2379% <49.4565%> (?)
unit 71.8274% <71.3483%> (+0.0040%) :arrow_up:

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

Components Coverage Δ
dumpling 52.9656% <ø> (ø)
parser ∅ <ø> (∅)
br 52.5143% <ø> (+6.3727%) :arrow_up:

codecov[bot] avatar May 27 '24 08:05 codecov[bot]

/retest

YangKeao avatar May 28 '24 15:05 YangKeao

[LGTM Timeline notifier]

Timeline:

  • 2024-06-06 06:10:49.939162458 +0000 UTC m=+13003.992474383: :ballot_box_with_check: agreed by qw4990.
  • 2024-06-11 07:42:09.227344304 +0000 UTC m=+450483.280656229: :ballot_box_with_check: agreed by lcwangchao.

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

/retest

YangKeao avatar Jun 11 '24 11:06 YangKeao

/retest

YangKeao avatar Jul 02 '24 08:07 YangKeao

/retest

YangKeao avatar Jul 03 '24 05:07 YangKeao

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: lance6716, lcwangchao, qw4990, XuHuaiyu, zimulala

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[bot] avatar Jul 03 '24 06:07 ti-chi-bot[bot]

/retest

YangKeao avatar Jul 03 '24 07:07 YangKeao

@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
idc-jenkins-ci-tidb/check_dev_2 bbfa315f2735564989449492a0afbc2aba5e8e13 link true /test check-dev2

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

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