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

planner: do not cache prepared plan if optimization depends on mutable constant (#22349) #22353

Merged
merged 5 commits into from
Jan 25, 2021

Conversation

ti-srebot
Copy link
Contributor

@ti-srebot ti-srebot commented Jan 12, 2021

cherry-pick #22349 to release-4.0
You can switch your code base to this Pull Request by using git-extras:

# In tidb repo:
git pr 22353

After apply modifications, you can push your change to this PR via:

git push git@github.com:ti-srebot/tidb.git pr/22353:ti-srebot:release-4.0-e3108df576a7

What problem does this PR solve?

Issue Number: close #22167

Problem Summary:
Incorrectly reuse cached plan which turns outer join to inner join.

What is changed and how it works?

What's Changed & How it Works:
EvaluateExprWithNull is used in several optimizations such as converting outer join to inner join. If the result of EvaluateExprWithNull depends on parameters of execute statement, whether the optimizations can be used is affected by the parameters. When optimizing a prepared plan, if expr passed into EvaluateExprWithNull contains mutable constant, we still do optimization but do not cache the plan.

Related changes

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

Check List

Tests a

  • Unit test
  • Integration test

Release note

  • fix a bug about incorrectly reuse cached plan

Signed-off-by: ti-srebot <ti-srebot@pingcap.com>
@ti-srebot
Copy link
Contributor Author

/run-all-tests

@ti-srebot
Copy link
Contributor Author

@xuyifangreeneyes you're already a collaborator in bot's repo.

@@ -830,3 +830,68 @@ func (s *testPrepareSuite) TestPrepareForGroupByMultiItems(c *C) {
tk.MustExec(`prepare stmt2 from "select sum(b) from t group by ?, ?"`)
tk.MustQuery(`execute stmt2 using @v1, @v2`).Check(testkit.Rows("10"))
}
<<<<<<< HEAD
Copy link
Contributor

Choose a reason for hiding this comment

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

@xuyifangreeneyes
Copy link
Contributor

/run-all-tests

@xuyifangreeneyes
Copy link
Contributor

/run-tics-test

@jebter jebter modified the milestones: v4.0.10, v4.0.11 Jan 18, 2021
Copy link
Contributor

@qw4990 qw4990 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 Jan 25, 2021
@qw4990
Copy link
Contributor

qw4990 commented Jan 25, 2021

PTAL @Reminiscent

@ti-srebot ti-srebot added status/LGT2 Indicates that a PR has LGTM 2. and removed status/LGT1 Indicates that a PR has LGTM 1. labels Jan 25, 2021
@zz-jason
Copy link
Member

/merge

@ti-srebot ti-srebot added the status/can-merge Indicates a PR has been approved by a committer. label Jan 25, 2021
@ti-srebot
Copy link
Contributor Author

Your auto merge job has been accepted, waiting for:

  • 20981
  • 21323
  • 21329
  • 21404
  • 21443
  • 21473
  • 21477
  • 21582
  • 21593
  • 21602
  • 21604
  • 21610
  • 21623
  • 21635
  • 21958
  • 22116
  • 22148

@ti-srebot
Copy link
Contributor Author

/run-all-tests

@ti-srebot ti-srebot merged commit 858a6c9 into pingcap:release-4.0 Jan 25, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component/expression 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/bugfix This PR fixes a bug. type/4.0-cherry-pick
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants