-
Notifications
You must be signed in to change notification settings - Fork 5.9k
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: prepared plan cache support cached plan with placeholder in limit clause #40196
Merged
+216
−84
Merged
Changes from 46 commits
Commits
Show all changes
48 commits
Select commit
Hold shift + click to select a range
eba19fe
commit
fzzf678 47c4f51
pass stmtNode
fzzf678 544fb69
fix ut
fzzf678 9ce7ca2
fix ut
fzzf678 7d90645
Merge branch 'master' into planCache_limit
fzzf678 505e9c2
Merge remote-tracking branch 'upstream/master' into planCache_limit
fzzf678 2c8f7b6
Merge branch 'planCache_limit' of https://github.com/fzzf678/tidb int…
fzzf678 9a759ee
commit
fzzf678 83f7a9d
Update plan_cache_utils.go
fzzf678 b5f17a4
safe value
fzzf678 07f327f
Merge branch 'master' into planCache_limit
fzzf678 a7a5844
fix
fzzf678 d6482e4
Merge branch 'planCache_limit' of https://github.com/fzzf678/tidb int…
fzzf678 6188f82
Update plan_cache_test.go
fzzf678 b5b90ed
Merge branch 'master' into planCache_limit
fzzf678 fbe23e5
unify error message
fzzf678 190bc29
check limit argument
fzzf678 f1f73db
unify warning message
fzzf678 b75e63e
Merge remote-tracking branch 'upstream/master' into planCache_limit
fzzf678 ed829d1
fix ut
fzzf678 8244f14
revert
fzzf678 03cee83
Merge remote-tracking branch 'upstream/master' into planCache_limit
fzzf678 8258da0
only_int
fzzf678 51d06a4
Update plan_cache_utils.go
fzzf678 5d83cea
only int in limit stmt
fzzf678 aae94e1
fix
fzzf678 0d6335a
replace int by uint in cache key
fzzf678 ab99bb7
Merge branch 'master' into planCache_limit
fzzf678 4305ba1
Update plan_cache_utils_test.go
fzzf678 cc040cb
Merge branch 'planCache_limit' of https://github.com/fzzf678/tidb int…
fzzf678 61b1547
Update prepared_test.go
fzzf678 cd6ca23
Update prepared_test.go
fzzf678 e921a81
Update plan_cache_test.go
fzzf678 9c4df35
Update plan_cache_utils.go
fzzf678 d9eadbd
Merge remote-tracking branch 'upstream/master' into planCache_limit
fzzf678 9dc74fb
use exist function
fzzf678 de1d441
Update plan_cache_test.go
fzzf678 4c05386
move limit params
fzzf678 67f83dc
Update plan_cache_lru_test.go
fzzf678 18c5b47
Merge branch 'master' into planCache_limit
fzzf678 a9ba0e6
fix ut
fzzf678 e1cf8a0
Merge branch 'planCache_limit' of https://github.com/fzzf678/tidb int…
fzzf678 e1b33a4
Update plan_cache_lru.go
fzzf678 8bf7f8b
Merge branch 'master' into planCache_limit
fzzf678 5a985d7
Merge branch 'master' into planCache_limit
fzzf678 64c82da
Merge branch 'master' into planCache_limit
fzzf678 b877d21
fix
fzzf678 54edf40
Merge branch 'master' into planCache_limit
ti-chi-bot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -385,12 +385,6 @@ func TestPlanCacheDiagInfo(t *testing.T) { | |
tk.MustExec("prepare stmt from 'select /*+ ignore_plan_cache() */ * from t'") | ||
tk.MustQuery("show warnings").Check(testkit.Rows("Warning 1105 skip plan-cache: ignore plan cache by hint")) | ||
|
||
tk.MustExec("prepare stmt from 'select * from t limit ?'") | ||
tk.MustQuery("show warnings").Check(testkit.Rows("Warning 1105 skip plan-cache: query has 'limit ?' is un-cacheable")) | ||
|
||
tk.MustExec("prepare stmt from 'select * from t limit ?, 1'") | ||
tk.MustQuery("show warnings").Check(testkit.Rows("Warning 1105 skip plan-cache: query has 'limit ?, 10' is un-cacheable")) | ||
|
||
tk.MustExec("prepare stmt from 'select * from t order by ?'") | ||
tk.MustQuery("show warnings").Check(testkit.Rows("Warning 1105 skip plan-cache: query has 'order by ?' is un-cacheable")) | ||
|
||
|
@@ -463,18 +457,45 @@ func TestIssue40225(t *testing.T) { | |
tk.MustQuery("select @@last_plan_from_binding").Check(testkit.Rows("1")) | ||
} | ||
|
||
func TestUncacheableReason(t *testing.T) { | ||
func TestPlanCacheWithLimit(t *testing.T) { | ||
store := testkit.CreateMockStore(t) | ||
tk := testkit.NewTestKit(t, store) | ||
tk.MustExec("use test") | ||
tk.MustExec("create table t (a int)") | ||
tk.MustExec("drop table if exists t") | ||
tk.MustExec("create table t(a int, b int, key(a))") | ||
|
||
testCases := []struct { | ||
sql string | ||
params []int | ||
}{ | ||
{"prepare stmt from 'select * from t limit ?'", []int{1}}, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please add some cases using There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. All fixed, PTAL again |
||
{"prepare stmt from 'select * from t limit ?, ?'", []int{1, 2}}, | ||
{"prepare stmt from 'delete from t order by a limit ?'", []int{1}}, | ||
{"prepare stmt from 'insert into t select * from t order by a desc limit ?'", []int{1}}, | ||
{"prepare stmt from 'insert into t select * from t order by a desc limit ?, ?'", []int{1, 2}}, | ||
{"prepare stmt from 'update t set a = 1 limit ?'", []int{1}}, | ||
{" prepare stmt from '(select * from t order by a limit ?) union (select * from t order by a desc limit ?)';", []int{1, 2}}, | ||
} | ||
|
||
tk.MustExec("prepare st from 'select * from t limit ?'") | ||
tk.MustQuery("show warnings").Check(testkit.Rows("Warning 1105 skip plan-cache: query has 'limit ?' is un-cacheable")) | ||
for _, testCase := range testCases { | ||
tk.MustExec(testCase.sql) | ||
var using []string | ||
for i, p := range testCase.params { | ||
tk.MustExec(fmt.Sprintf("set @a%d = %d", i, p)) | ||
using = append(using, fmt.Sprintf("@a%d", i)) | ||
} | ||
|
||
tk.MustExec("set @a=1") | ||
tk.MustQuery("execute st using @a").Check(testkit.Rows()) | ||
tk.MustExec("prepare st from 'select * from t limit ?'") | ||
// show the corresponding un-cacheable reason at execute-stage as well | ||
tk.MustQuery("show warnings").Check(testkit.Rows("Warning 1105 skip plan-cache: query has 'limit ?' is un-cacheable")) | ||
tk.MustExec("execute stmt using " + strings.Join(using, ", ")) | ||
tk.MustExec("execute stmt using " + strings.Join(using, ", ")) | ||
tk.MustQuery("select @@last_plan_from_cache").Check(testkit.Rows("1")) | ||
|
||
tk.MustExec("set @a0 = 6") | ||
tk.MustExec("execute stmt using " + strings.Join(using, ", ")) | ||
tk.MustQuery("select @@last_plan_from_cache").Check(testkit.Rows("0")) | ||
} | ||
|
||
tk.MustExec("prepare stmt from 'select * from t limit ?'") | ||
tk.MustExec("set @a = 10001") | ||
tk.MustExec("execute stmt using @a") | ||
tk.MustQuery("show warnings").Check(testkit.Rows("Warning 1105 skip plan-cache: limit count more than 10000")) | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Better to pass
limitCountAndOffset
intogenerateNewPlan
so that we don't need to extract them again.