Skip to content
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

*: differentiate types for user variables #18973

Merged
merged 13 commits into from
Nov 17, 2020
Merged

Conversation

eurekaka
Copy link
Contributor

@eurekaka eurekaka commented Aug 4, 2020

What problem does this PR solve?

Issue Number: close #16820 , close #11212

#16603 and #16362 can be closed by this PR as well.

Problem Summary:

We treated all user variables as string types, so there would be cast functions added which prevent the planner to choose better plans, such as PointGet. The problem is more frequent when plan cache is enabled.

What is changed and how it works?

What's Changed:

Infer types for user variables, if the user variable is not set before, we treat it as string type. The behaviors reference https://dev.mysql.com/doc/refman/8.0/en/user-variables.html.

Related changes

  • PR to update pingcap/docs/pingcap/docs-cn:
  • Need to cherry-pick to the release branch

Check List

Tests

  • Unit test

Side effects

  • Performance regression
    • Consumes more CPU

Release note

  • differentiate types for user variables

@codecov
Copy link

codecov bot commented Aug 5, 2020

Codecov Report

Merging #18973 into master will decrease coverage by 0.0853%.
The diff coverage is 67.8304%.

@@               Coverage Diff                @@
##             master     #18973        +/-   ##
================================================
- Coverage   79.4390%   79.3537%   -0.0853%     
================================================
  Files           546        546                
  Lines        148631     148293       -338     
================================================
- Hits         118071     117676       -395     
- Misses        21075      21102        +27     
- Partials       9485       9515        +30     

tk.MustExec("set @v1 = 3")
tk.MustExec("set @v2 = 3")
tk.MustExec("set @v1 = '3'")
tk.MustExec("set @v2 = '3'")
Copy link
Contributor Author

@eurekaka eurekaka Aug 5, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A related bug: #19002. When the variable type and column type mismatches, point-get with plan-cache enabled would return wrong result. It should be fixed in another PR, so I modify the test cases here first to make the types consistent, since the test purpose here is not on the type mismatch problem.

@eurekaka eurekaka marked this pull request as ready for review August 5, 2020 10:00
@eurekaka eurekaka requested review from a team as code owners August 5, 2020 10:00
@eurekaka eurekaka requested review from qw4990 and winoros and removed request for a team August 5, 2020 10:00
Copy link
Member

@winoros winoros left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@ti-srebot ti-srebot added the status/LGT1 Indicates that a PR has LGTM 1. label Sep 23, 2020
@ghost
Copy link

ghost commented Nov 16, 2020

Aha, that's interesting. @SunRunAway @nullnotnil any thoughts?

LGTM

@lzmhhh123
Copy link
Contributor

/run-all-tests

@lzmhhh123
Copy link
Contributor

I think we can directly convert the user variable to the specified type in the plan cache during the evaluation. Since MySQL handled it in this way.

After the discussion, we decide to support different variable types in the plan cache. And c4bf6d0 (#18973) is to solve it.

@lzmhhh123
Copy link
Contributor

/run-sqllogic-test-2

@lzmhhh123
Copy link
Contributor

/run-all-tests

@lzmhhh123
Copy link
Contributor

/run-build

@lzmhhh123
Copy link
Contributor

/run-all-tests

@lzmhhh123
Copy link
Contributor

/run-unit-test

@lzmhhh123
Copy link
Contributor

/run-all-tests

@lzmhhh123
Copy link
Contributor

/run-check_dev_2

@eurekaka eurekaka merged commit de75e60 into pingcap:master Nov 17, 2020
@ti-challenge-bot
Copy link

@eurekaka, Congratulations, you get 300 in this PR, and your total score is 300 in high-performance challenge program.

Details

Tip : None

Warning:
The pull request merged, eurekaka got the score. But it seems linked issue not picked.

cc: Mentor @lzmhhh123

@ti-srebot
Copy link
Contributor

cherry pick to release-4.0 in PR #21107

eurekaka added a commit to ti-srebot/tidb that referenced this pull request Nov 26, 2020
Signed-off-by: ti-srebot <ti-srebot@pingcap.com>
eurekaka added a commit that referenced this pull request Nov 26, 2020
Signed-off-by: ti-srebot <ti-srebot@pingcap.com>

Co-authored-by: Kenan Yao <cauchy1992@gmail.com>
@wjhuang2016 wjhuang2016 mentioned this pull request Dec 11, 2020
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component/executor component/expression sig/execution SIG execution sig/planner SIG: Planner status/can-merge Indicates a PR has been approved by a committer. status/LGT2 Indicates that a PR has LGTM 2. type/enhancement The issue or PR belongs to an enhancement.
Projects
None yet
7 participants