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: add more test cases for non-prep plan cache #41914

Merged
merged 5 commits into from
Mar 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions planner/core/plan_cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,17 @@ func TestNonPreparedPlanCacheInListChange(t *testing.T) {
tk.MustQuery("select @@last_plan_from_cache").Check(testkit.Rows("1"))
}

func TestNonPreparedPlanCacheMemoryTable(t *testing.T) {
store := testkit.CreateMockStore(t)
tk := testkit.NewTestKit(t, store)
tk.MustExec(`use test`)
tk.MustExec("set tidb_enable_non_prepared_plan_cache=1")

tk.MustExec(`select data_type from INFORMATION_SCHEMA.columns where table_name = 'v'`)
tk.MustExec(`select data_type from INFORMATION_SCHEMA.columns where table_name = 'v'`)
tk.MustQuery(`select @@last_plan_from_cache`).Check(testkit.Rows("0"))
}

func TestNonPreparedPlanCacheTooManyConsts(t *testing.T) {
store := testkit.CreateMockStore(t)
tk := testkit.NewTestKit(t, store)
Expand Down
33 changes: 23 additions & 10 deletions planner/core/plan_cacheable_checker.go
Original file line number Diff line number Diff line change
Expand Up @@ -306,21 +306,38 @@ func (checker *nonPreparedPlanCacheableChecker) Enter(in ast.Node) (out ast.Node
case *ast.TableName:
checker.tableNode = node
if checker.schema != nil {
if isPartitionTable(checker.schema, node) {
tb, err := checker.schema.TableByName(node.Schema, node.Name)
if err != nil {
checker.cacheable = false
checker.reason = "queries that access partitioning table are not supported"
checker.reason = "table cannot be found in schema"
return in, !checker.cacheable
}
if hasGeneratedCol(checker.schema, node) {
if tb.Meta().GetPartitionInfo() != nil {
checker.cacheable = false
checker.reason = "queries that have generated columns are not supported"
checker.reason = "queries that access partitioning table are not supported"
return in, !checker.cacheable
}
if isTempTable(checker.schema, node) {
for _, col := range tb.Cols() {
if col.IsGenerated() {
checker.cacheable = false
checker.reason = "queries that have generated columns are not supported"
return in, !checker.cacheable
}
}
if tb.Meta().TempTableType != model.TempTableNone {
checker.cacheable = false
checker.reason = "queries that access temporary tables are not supported"
return in, !checker.cacheable
}
if isView(checker.schema, node) {
if tb.Meta().IsView() {
checker.cacheable = false
checker.reason = "queries that access views are not supported"
return in, !checker.cacheable
}
if !tb.Type().IsNormalTable() {
checker.cacheable = false
checker.reason = "queries that access in-memory tables"
return in, !checker.cacheable
}
}
return in, !checker.cacheable
Expand Down Expand Up @@ -376,10 +393,6 @@ func getColType(schema infoschema.InfoSchema, tbl *ast.TableName, col *ast.Colum
return 0, false
}

func isView(schema infoschema.InfoSchema, tn *ast.TableName) bool {
return schema.TableIsView(tn.Schema, tn.Name)
}

func isTempTable(schema infoschema.InfoSchema, tn *ast.TableName) bool {
tb, err := schema.TableByName(tn.Schema, tn.Name)
if err != nil {
Expand Down