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: fix bindings with ignore_plan_cache_hint cannot work #36427

Merged
merged 11 commits into from
Jul 25, 2022

Conversation

fzzf678
Copy link
Contributor

@fzzf678 fzzf678 commented Jul 21, 2022

What problem does this PR solve?

Issue Number: close #34596

Problem Summary:
In the general SQL, using hint /*+ ignore_plan_cache() */ cannot be awared by prepare/execute.

What is changed and how it works?

Add some check in EXECUTE stage.

The switch of prepare's plan cache is open/close in PREPARE stage.But if we CREATE/DROP binding with /*+ ignore_plan_cache() */ , the switch will not change in EXECUTE stage.

Check List

Tests

  • Unit test
  • Integration test
  • Manual test (add detailed scripts or steps below)
  • No code

Side effects

  • Performance regression: Consumes more CPU
  • Performance regression: Consumes more Memory
  • Breaking backward compatibility

Documentation

  • Affects user behaviors
  • Contains syntax changes
  • Contains variable changes
  • Contains experimental features
  • Changes MySQL compatibility

Release note

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

None

@ti-chi-bot
Copy link
Member

ti-chi-bot commented Jul 21, 2022

[REVIEW NOTIFICATION]

This pull request has been approved by:

  • Reminiscent
  • qw4990

To complete the pull request process, please ask the reviewers in the list to review by filling /cc @reviewer in the comment.
After your PR has acquired the required number of LGTMs, you can assign this pull request to the committer in the list by filling /assign @committer in the comment to help you merge this pull request.

The full list of commands accepted by this bot can be found here.

Reviewer can indicate their review by submitting an approval review.
Reviewer can cancel approval by submitting a request changes review.

@ti-chi-bot ti-chi-bot added the release-note-none Denotes a PR that doesn't merit a release note. label Jul 21, 2022
@sre-bot
Copy link
Contributor

sre-bot commented Jul 21, 2022

CLA assistant check
All committers have signed the CLA.

@ti-chi-bot ti-chi-bot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Jul 21, 2022
@sre-bot
Copy link
Contributor

sre-bot commented Jul 21, 2022

Please follow PR Title Format:

  • pkg [, pkg2, pkg3]: what is changed

Or if the count of mainly changed packages are more than 3, use

  • *: what is changed

After you have format title, you can leave a comment /run-check_title to recheck it

@fzzf678
Copy link
Contributor Author

fzzf678 commented Jul 21, 2022

/retitle planner:Fix bindings with ignore_plan_cache_hint cannot work

@ti-chi-bot ti-chi-bot changed the title Fix ignore plan cache cannot work bug planner:Fix bindings with ignore_plan_cache_hint cannot work Jul 21, 2022
@fzzf678
Copy link
Contributor Author

fzzf678 commented Jul 21, 2022

/run-check_title

@sre-bot
Copy link
Contributor

sre-bot commented Jul 21, 2022

Please follow PR Title Format:

  • pkg [, pkg2, pkg3]: what is changed

Or if the count of mainly changed packages are more than 3, use

  • *: what is changed

After you have format title, you can leave a comment /run-check_title to recheck it

@fzzf678
Copy link
Contributor Author

fzzf678 commented Jul 21, 2022

/retitle planner: fix bindings with ignore_plan_cache_hint cannot work

@ti-chi-bot ti-chi-bot changed the title planner:Fix bindings with ignore_plan_cache_hint cannot work planner: fix bindings with ignore_plan_cache_hint cannot work Jul 21, 2022
@fzzf678
Copy link
Contributor Author

fzzf678 commented Jul 21, 2022

/run-check_title

@sre-bot
Copy link
Contributor

sre-bot commented Jul 21, 2022

@fzzf678
Copy link
Contributor Author

fzzf678 commented Jul 21, 2022

/cc @qw4990 @Reminiscent

@ti-chi-bot ti-chi-bot requested review from qw4990 and Reminiscent July 21, 2022 10:10
@fzzf678
Copy link
Contributor Author

fzzf678 commented Jul 21, 2022

/run-unit-test

@fzzf678
Copy link
Contributor Author

fzzf678 commented Jul 21, 2022

/run-check_dev_2

@@ -318,7 +318,7 @@ func (e *Execute) checkPreparedPriv(ctx context.Context, sctx sessionctx.Context
}

// GetBindSQL4PlanCache used to get the bindSQL for plan cache to build the plan cache key.
func GetBindSQL4PlanCache(sctx sessionctx.Context, preparedStmt *CachedPrepareStmt) string {
func GetBindSQL4PlanCache(sctx sessionctx.Context, preparedStmt *CachedPrepareStmt, ignore *bool) string {
Copy link
Contributor

@Reminiscent Reminiscent Jul 22, 2022

Choose a reason for hiding this comment

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

Why not treat the ignore as the return value?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

thks, i'm adapting golang‘s idiomatic syntax

@@ -1174,6 +1174,31 @@ func TestHint4PlanCache(t *testing.T) {
tk.MustQuery("select @@last_plan_from_cache;").Check(testkit.Rows("0"))
}

func TestIgnorePlanCacheWithPrepare(t *testing.T) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Please add some test cases like:

create binding for ... using select /*+ use_index(..) */ ..        // some useful hint
execute stmt;
select @@last_plan_from_binding; // check binding
execute stmt;
select @@last_plan_from_cache; // check the plan cache

create binding for ... using select /*+ ignore_plan_cache() */ ..
execute;
select @@last_plan_from_cache;
execute;
select @@last_plan_from_binding;

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@Reminiscent PTAL agian and by the way Am I putting UnitTest code in the right place(*.go)?

@fzzf678 fzzf678 requested a review from Reminiscent July 22, 2022 05:45
tk.MustQuery("select @@last_plan_from_cache;").Check(testkit.Rows("0"))
tk.MustQuery("execute stmt;").Check(testkit.Rows())
tk.MustQuery("select @@last_plan_from_binding;").Check(testkit.Rows("1"))

Copy link
Contributor

Choose a reason for hiding this comment

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

Please add one more test case like:

create binding for ... using select /*+ use_index(t, idx_a) */ ... -- remove the ignore_plan_cahce hint
execute stmt;
execute stmt;
select @@last_plan_from_cache; -- the plan cache can work again
select @@last_plan_from_binding;

add test case
@ti-chi-bot ti-chi-bot added the status/LGT1 Indicates that a PR has LGTM 1. label Jul 25, 2022
@ti-chi-bot ti-chi-bot added status/LGT2 Indicates that a PR has LGTM 2. and removed status/LGT1 Indicates that a PR has LGTM 1. labels Jul 25, 2022
@Reminiscent
Copy link
Contributor

/merge

@ti-chi-bot
Copy link
Member

This pull request has been accepted and is ready to merge.

Commit hash: 6135e5a

@ti-chi-bot ti-chi-bot added the status/can-merge Indicates a PR has been approved by a committer. label Jul 25, 2022
@fzzf678
Copy link
Contributor Author

fzzf678 commented Jul 25, 2022

/run-unit-test

@ti-chi-bot ti-chi-bot merged commit 1923d33 into pingcap:master Jul 25, 2022
@fzzf678
Copy link
Contributor Author

fzzf678 commented Jul 25, 2022

/retitle planner: fix bindings with ignore_plan_cache() hint cannot work

@sre-bot
Copy link
Contributor

sre-bot commented Jul 25, 2022

TiDB MergeCI notify

🔴 Bad News! New failing [1] after this pr merged.
These new failed integration tests seem to be caused by the current PR, please try to fix these new failed integration tests, thanks!

CI Name Result Duration Compare with Parent commit
idc-jenkins-ci-tidb/integration-common-test 🟥 failed 1, success 10, total 11 56 min New failing
idc-jenkins-ci/integration-cdc-test 🟢 all 36 tests passed 44 min Existing passed
idc-jenkins-ci-tidb/common-test 🟢 all 12 tests passed 24 min Existing passed
idc-jenkins-ci-tidb/tics-test 🟢 all 1 tests passed 7 min 11 sec Existing passed
idc-jenkins-ci-tidb/integration-compatibility-test 🟢 all 1 tests passed 6 min 32 sec Existing passed
idc-jenkins-ci-tidb/integration-ddl-test 🟢 all 6 tests passed 6 min 2 sec Existing passed
idc-jenkins-ci-tidb/sqllogic-test-2 🟢 all 28 tests passed 5 min 42 sec Existing passed
idc-jenkins-ci-tidb/sqllogic-test-1 🟢 all 26 tests passed 5 min 23 sec Existing passed
idc-jenkins-ci-tidb/mybatis-test 🟢 all 1 tests passed 3 min 53 sec Existing passed
idc-jenkins-ci-tidb/plugin-test 🟢 build success, plugin test success 4min Existing passed

@jebter jebter added the needs-cherry-pick-release-6.1 Should cherry pick this PR to release-6.1 branch. label Aug 19, 2022
ti-srebot pushed a commit to ti-srebot/tidb that referenced this pull request Aug 19, 2022
@ti-srebot
Copy link
Contributor

cherry pick to release-6.1 in PR #37231

@fzzf678 fzzf678 added the type/bugfix This PR fixes a bug. label Mar 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs-cherry-pick-release-6.1 Should cherry pick this PR to release-6.1 branch. release-note-none Denotes a PR that doesn't merit a release note. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. 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.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

bindings with ignore_plan_cache_hint cannot work
7 participants