From 8772821e97e708b9c02abcf1272c7890941a3ee5 Mon Sep 17 00:00:00 2001 From: YangKeao Date: Sun, 8 Oct 2023 15:19:52 +0800 Subject: [PATCH] planner, tests: migrate tests for `plan_cache` into the integrationtest (#47443) close pingcap/tidb#47173 --- planner/core/BUILD.bazel | 1 - planner/core/plan_cache_test.go | 1517 +---------- .../planner/core/integration_partition.result | 2 +- .../r/planner/core/plan_cache.result | 2282 +++++++++++++++++ .../t/planner/core/integration_partition.test | 1 + .../t/planner/core/plan_cache.test | 1431 +++++++++++ 6 files changed, 3721 insertions(+), 1513 deletions(-) create mode 100644 tests/integrationtest/r/planner/core/plan_cache.result create mode 100644 tests/integrationtest/t/planner/core/plan_cache.test diff --git a/planner/core/BUILD.bazel b/planner/core/BUILD.bazel index 0d3f413e512af..42469d2413ebf 100644 --- a/planner/core/BUILD.bazel +++ b/planner/core/BUILD.bazel @@ -277,7 +277,6 @@ go_test( "//util/plancodec", "//util/ranger", "//util/set", - "//util/size", "//util/stmtsummary", "//util/tracing", "@com_github_golang_snappy//:snappy", diff --git a/planner/core/plan_cache_test.go b/planner/core/plan_cache_test.go index 9454a325e3f0b..2f9910c5c3c4c 100644 --- a/planner/core/plan_cache_test.go +++ b/planner/core/plan_cache_test.go @@ -37,7 +37,6 @@ import ( "github.com/pingcap/tidb/types" driver "github.com/pingcap/tidb/types/parser_driver" "github.com/pingcap/tidb/util" - "github.com/pingcap/tidb/util/size" "github.com/stretchr/testify/require" ) @@ -64,92 +63,6 @@ func TestIssue45086(t *testing.T) { require.Equal(t, len(tk.MustQuery(`EXECUTE stmt`).Rows()), 1) } -func TestIssue43311(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec(`use test`) - tk.MustExec(`create table test.t (id int, value decimal(7,4), c1 int, c2 int)`) - tk.MustExec(`insert into test.t values (1,1.9285,54,28), (1,1.9286,54,28)`) - - tk.MustExec(`set session tidb_enable_non_prepared_plan_cache=0`) - tk.MustQuery(`select * from t where value = 54 / 28`).Check(testkit.Rows()) // empty - - tk.MustExec(`set session tidb_enable_non_prepared_plan_cache=1`) - tk.MustQuery(`select * from t where value = 54 / 28`).Check(testkit.Rows()) // empty - tk.MustQuery(`select * from t where value = 54 / 28`).Check(testkit.Rows()) // empty - - tk.MustExec(`prepare st from 'select * from t where value = ? / ?'`) - tk.MustExec(`set @a=54, @b=28`) - tk.MustQuery(`execute st using @a, @b`).Check(testkit.Rows()) // empty - tk.MustQuery(`execute st using @a, @b`).Check(testkit.Rows()) // empty -} - -func TestIssue44830(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec(`use test`) - tk.MustExec(`set @@tidb_opt_fix_control = "44830:ON"`) - tk.MustExec(`create table t (a int, primary key(a))`) - tk.MustExec(`create table t1 (a int, b int, primary key(a, b))`) // multiple-column primary key - tk.MustExec(`insert into t values (1), (2), (3)`) - tk.MustExec(`insert into t1 values (1, 1), (2, 2), (3, 3)`) - tk.MustExec(`set @a=1, @b=2, @c=3`) - - // single-column primary key cases - tk.MustExec(`prepare st from 'select * from t where 1=1 and a in (?, ?, ?)'`) - tk.MustQuery(`execute st using @a, @b, @c`).Sort().Check(testkit.Rows("1", "2", "3")) - tk.MustQuery(`execute st using @a, @b, @c`).Sort().Check(testkit.Rows("1", "2", "3")) - tk.MustQuery(`select @@last_plan_from_cache`).Check(testkit.Rows("1")) - tk.MustQuery(`execute st using @a, @b, @b`).Sort().Check(testkit.Rows("1", "2")) - tk.MustQuery(`select @@last_plan_from_cache`).Check(testkit.Rows("0")) // range length changed - tk.MustQuery(`execute st using @b, @b, @b`).Sort().Check(testkit.Rows("2")) - tk.MustQuery(`select @@last_plan_from_cache`).Check(testkit.Rows("0")) // range length changed - tk.MustQuery(`execute st using @a, @b, @c`).Sort().Check(testkit.Rows("1", "2", "3")) - tk.MustQuery(`execute st using @a, @b, @b`).Sort().Check(testkit.Rows("1", "2")) - tk.MustQuery(`execute st using @a, @b, @b`).Sort().Check(testkit.Rows("1", "2")) - tk.MustQuery(`select @@last_plan_from_cache`).Check(testkit.Rows("0")) // contain duplicated values in the in-list - - // multi-column primary key cases - tk.MustExec(`prepare st from 'select * from t1 where 1=1 and (a, b) in ((?, ?), (?, ?), (?, ?))'`) - tk.MustQuery(`execute st using @a, @a, @b, @b, @c, @c`).Sort().Check(testkit.Rows("1 1", "2 2", "3 3")) - tk.MustQuery(`execute st using @a, @a, @b, @b, @c, @c`).Sort().Check(testkit.Rows("1 1", "2 2", "3 3")) - tk.MustQuery(`select @@last_plan_from_cache`).Check(testkit.Rows("1")) - tk.MustQuery(`execute st using @a, @a, @b, @b, @b, @b`).Sort().Check(testkit.Rows("1 1", "2 2")) - tk.MustQuery(`select @@last_plan_from_cache`).Check(testkit.Rows("0")) // range length changed - tk.MustQuery(`execute st using @b, @b, @b, @b, @b, @b`).Sort().Check(testkit.Rows("2 2")) - tk.MustQuery(`select @@last_plan_from_cache`).Check(testkit.Rows("0")) // range length changed - tk.MustQuery(`execute st using @b, @b, @b, @b, @c, @c`).Sort().Check(testkit.Rows("2 2", "3 3")) - tk.MustQuery(`select @@last_plan_from_cache`).Check(testkit.Rows("0")) // range length changed - tk.MustQuery(`execute st using @a, @a, @a, @a, @a, @a`).Sort().Check(testkit.Rows("1 1")) - tk.MustQuery(`execute st using @a, @a, @a, @a, @a, @a`).Sort().Check(testkit.Rows("1 1")) - tk.MustQuery(`select @@last_plan_from_cache`).Check(testkit.Rows("0")) // contain duplicated values in the in-list - tk.MustQuery(`execute st using @a, @a, @b, @b, @b, @b`).Sort().Check(testkit.Rows("1 1", "2 2")) - tk.MustQuery(`execute st using @a, @a, @b, @b, @b, @b`).Sort().Check(testkit.Rows("1 1", "2 2")) - tk.MustQuery(`select @@last_plan_from_cache`).Check(testkit.Rows("0")) // contain duplicated values in the in-list -} - -func TestIssue44830NonPrep(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(`set @@tidb_opt_fix_control = "44830:ON"`) - tk.MustExec(`create table t1 (a int, b int, primary key(a, b))`) // multiple-column primary key - tk.MustExec(`insert into t1 values (1, 1), (2, 2), (3, 3)`) - tk.MustExec(`set @a=1, @b=2, @c=3`) - - tk.MustQuery(`select * from t1 where 1=1 and (a, b) in ((1, 1), (2, 2), (3, 3))`).Sort().Check(testkit.Rows("1 1", "2 2", "3 3")) - tk.MustQuery(`select * from t1 where 1=1 and (a, b) in ((1, 1), (2, 2), (3, 3))`).Sort().Check(testkit.Rows("1 1", "2 2", "3 3")) - tk.MustQuery(`select @@last_plan_from_cache`).Check(testkit.Rows("1")) - tk.MustQuery(`select * from t1 where 1=1 and (a, b) in ((1, 1), (2, 2), (2, 2))`).Sort().Check(testkit.Rows("1 1", "2 2")) - tk.MustQuery(`select @@last_plan_from_cache`).Check(testkit.Rows("0")) - tk.MustQuery(`select * from t1 where 1=1 and (a, b) in ((2, 2), (2, 2), (2, 2))`).Sort().Check(testkit.Rows("2 2")) - tk.MustQuery(`select @@last_plan_from_cache`).Check(testkit.Rows("0")) - tk.MustQuery(`select * from t1 where 1=1 and (a, b) in ((1, 1), (1, 1), (1, 1))`).Sort().Check(testkit.Rows("1 1")) - tk.MustQuery(`select * from t1 where 1=1 and (a, b) in ((1, 1), (1, 1), (1, 1))`).Sort().Check(testkit.Rows("1 1")) - tk.MustQuery(`select @@last_plan_from_cache`).Check(testkit.Rows("0")) -} - func TestPlanCacheSizeSwitch(t *testing.T) { store := testkit.CreateMockStore(t) tk := testkit.NewTestKit(t, store) @@ -177,206 +90,6 @@ func TestPlanCacheSizeSwitch(t *testing.T) { tk2.MustQuery(`select @@tidb_session_plan_cache_size`).Check(testkit.Rows("500")) } -func TestPlanCacheUnsafeRange(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec(`use test`) - tk.MustExec(`create table t (a int unsigned, key(a))`) - tk.MustExec(`prepare st from 'select a from t use index(a) where a= 659971401668884663953087553591534913868320924.5040396 and col2 = 869042976700631943559871054704914143535627349.9659934`) - require.ErrorContains(t, err, "value is out of range in") -} - -func TestIssue14875(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec(`use test`) - tk.MustExec(`create table t(a varchar(8) not null, b varchar(8) not null)`) - tk.MustExec(`insert into t values('1','1')`) - tk.MustExec(`prepare stmt from "select count(1) from t t1, t t2 where t1.a = t2.a and t2.b = '1' and t2.b = ?"`) - tk.MustExec(`set @a = '1'`) - tk.MustQuery(`execute stmt using @a`).Check(testkit.Rows("1")) - tk.MustExec(`set @a = '2'`) - tk.MustQuery(`execute stmt using @a`).Check(testkit.Rows("0")) - - tk.MustExec(`prepare stmt from "select count(1) from t t1, t t2 where t1.a = t2.a and t1.a > ?"`) - tk.MustExec(`set @a = '1'`) - tk.MustQuery(`execute stmt using @a`).Check(testkit.Rows("0")) - tk.MustExec(`set @a = '0'`) - tk.MustQuery(`execute stmt using @a`).Check(testkit.Rows("1")) -} - -func TestIssue14871(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec(`use test`) - tk.MustExec(`create table t(a varchar(8), b varchar(8))`) - tk.MustExec(`insert into t values('1','1')`) - tk.MustExec(`prepare stmt from "select count(1) from t t1 left join t t2 on t1.a = t2.a where t2.b = ? and t2.b = ?"`) - tk.MustExec(`set @p0 = '1', @p1 = '2'`) - tk.MustQuery(`execute stmt using @p0, @p1`).Check(testkit.Rows("0")) - tk.MustExec(`set @p0 = '1', @p1 = '1'`) - tk.MustQuery(`execute stmt using @p0, @p1`).Check(testkit.Rows("1")) -} - -func TestNonPreparedPlanCacheDMLHints(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(`set @@tidb_enable_non_prepared_plan_cache=1`) - tk.MustExec(`set @@tidb_enable_non_prepared_plan_cache_for_dml=1`) - - tk.MustExec(`insert into t values (1)`) - tk.MustExec(`insert into t values (1)`) - tk.MustQuery(`select @@last_plan_from_cache`).Check(testkit.Rows("1")) - tk.MustExec(`update t set a=1`) - tk.MustExec(`update t set a=1`) - tk.MustQuery(`select @@last_plan_from_cache`).Check(testkit.Rows("1")) - tk.MustExec(`delete from t where a=1`) - tk.MustExec(`delete from t where a=1`) - tk.MustQuery(`select @@last_plan_from_cache`).Check(testkit.Rows("1")) - - tk.MustExec(`insert /*+ ignore_plan_cache() */ into t values (1)`) - tk.MustExec(`insert /*+ ignore_plan_cache() */ into t values (1)`) - tk.MustQuery(`select @@last_plan_from_cache`).Check(testkit.Rows("0")) - tk.MustExec(`update /*+ ignore_plan_cache() */ t set a=1`) - tk.MustExec(`update /*+ ignore_plan_cache() */ t set a=1`) - tk.MustQuery(`select @@last_plan_from_cache`).Check(testkit.Rows("0")) - tk.MustExec(`delete /*+ ignore_plan_cache() */ from t where a=1`) - tk.MustExec(`delete /*+ ignore_plan_cache() */ from t where a=1`) - tk.MustQuery(`select @@last_plan_from_cache`).Check(testkit.Rows("0")) - - tk.MustExec(`insert into t values (1)`) - tk.MustQuery(`select @@last_plan_from_cache`).Check(testkit.Rows("1")) - tk.MustExec(`update t set a=1`) - tk.MustQuery(`select @@last_plan_from_cache`).Check(testkit.Rows("1")) - tk.MustExec(`delete from t where a=1`) - tk.MustQuery(`select @@last_plan_from_cache`).Check(testkit.Rows("1")) -} - func TestNonPreparedPlanCachePlanString(t *testing.T) { store := testkit.CreateMockStore(t) tk := testkit.NewTestKit(t, store) @@ -406,424 +119,6 @@ func TestNonPreparedPlanCachePlanString(t *testing.T) { tk.MustQuery(`select @@last_plan_from_cache`).Check(testkit.Rows("1")) } -func TestNonPreparedPlanCacheJSONFilter(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec(`use test`) - tk.MustExec("create table t(a int, b json)") - tk.MustExec("set tidb_enable_non_prepared_plan_cache=1") - - tk.MustExec(`select * from t where a<1`) - tk.MustExec(`select * from t where a<2`) - tk.MustQuery("select @@last_plan_from_cache").Check(testkit.Rows("1")) - - // queries with filters with JSON columns are not supported - tk.MustExec(`select * from t where b<1`) - tk.MustExec(`select * from t where b<2`) - tk.MustQuery("select @@last_plan_from_cache").Check(testkit.Rows("0")) - - tk.MustExec(`select b from t where a<1`) - tk.MustExec(`select b from t where a<2`) - tk.MustQuery("select @@last_plan_from_cache").Check(testkit.Rows("1")) -} - -func TestNonPreparedPlanCacheEnumFilter(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec(`use test`) - tk.MustExec("create table t(a int, b enum('1', '2', '3'))") - tk.MustExec("set tidb_enable_non_prepared_plan_cache=1") - - tk.MustExec(`select * from t where a<1`) - tk.MustExec(`select * from t where a<2`) - tk.MustQuery("select @@last_plan_from_cache").Check(testkit.Rows("1")) - - // queries with filters with enum columns are not supported - tk.MustExec(`select * from t where b='1'`) - tk.MustExec(`select * from t where b='2'`) - tk.MustQuery("select @@last_plan_from_cache").Check(testkit.Rows("0")) - - tk.MustExec(`select b from t where a<1`) - tk.MustExec(`select b from t where a<2`) - tk.MustQuery("select @@last_plan_from_cache").Check(testkit.Rows("1")) -} - -func TestNonPreparedPlanCacheDateFormat(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(`create table t1 (s1 char(20) character set latin1)`) - tk.MustExec(`insert into t1 values (date_format('2004-02-02','%M'))`) // no error - tk.MustQuery(`select * from t1`).Check(testkit.Rows(`February`)) -} - -func TestNonPreparedPlanCacheNullValue(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("set tidb_enable_non_prepared_plan_cache=1") - - tk.MustExec(`select * from t where a=1`) - tk.MustExec(`select * from t where a=2`) - tk.MustQuery("select @@last_plan_from_cache").Check(testkit.Rows("1")) - - tk.MustExec(`select * from t where a=null`) // query with null value cannot hit - tk.MustQuery("select @@last_plan_from_cache").Check(testkit.Rows("0")) - - tk.MustExec(`select * from t where a=2`) - tk.MustQuery("select @@last_plan_from_cache").Check(testkit.Rows("1")) -} - -func TestNonPreparedPlanCacheInListChange(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("set tidb_enable_non_prepared_plan_cache=1") - - tk.MustExec(`select * from t where a in (1, 2, 3)`) - tk.MustExec(`select * from t where a in (2, 3, 4)`) - tk.MustQuery("select @@last_plan_from_cache").Check(testkit.Rows("1")) - - tk.MustExec(`select * from t where a in (2, 3, 4, 5)`) // cannot hit the previous plan - tk.MustQuery("select @@last_plan_from_cache").Check(testkit.Rows("0")) - tk.MustExec(`select * from t where a in (1, 2, 3, 4)`) - 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) - tk.MustExec(`use test`) - tk.MustExec("create table t(a int)") - tk.MustExec("set tidb_enable_non_prepared_plan_cache=1") - - var x []string - for i := 0; i < 201; i++ { - x = append(x, fmt.Sprintf("%v", i)) - } - list1 := strings.Join(x[:199], ", ") - list2 := strings.Join(x[:200], ", ") - list3 := strings.Join(x[:201], ", ") - - tk.MustExec(fmt.Sprintf(`select * from t where a in (%v)`, list1)) - tk.MustExec(fmt.Sprintf(`select * from t where a in (%v)`, list1)) - tk.MustQuery("select @@last_plan_from_cache").Check(testkit.Rows("1")) - tk.MustExec(fmt.Sprintf(`select * from t where a in (%v)`, list2)) - tk.MustExec(fmt.Sprintf(`select * from t where a in (%v)`, list2)) - tk.MustQuery("select @@last_plan_from_cache").Check(testkit.Rows("1")) - - // query has more than 50 consts cannot hit - tk.MustExec(fmt.Sprintf(`select * from t where a in (%v)`, list3)) - tk.MustExec(fmt.Sprintf(`select * from t where a in (%v)`, list3)) - tk.MustQuery("select @@last_plan_from_cache").Check(testkit.Rows("0")) -} - -func TestNonPreparedPlanCacheSchemaChange(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("set tidb_enable_non_prepared_plan_cache=1") - - tk.MustExec("select * from t where a=1") - tk.MustExec("select * from t where a=1") - tk.MustQuery("select @@last_plan_from_cache").Check(testkit.Rows("1")) - - tk.MustExec("alter table t add index idx_a(a)") - tk.MustExec("select * from t where a=1") - tk.MustQuery("select @@last_plan_from_cache").Check(testkit.Rows("0")) // cannot hit since the schema changed - tk.MustExec("select * from t where a=1") - tk.MustQuery("select @@last_plan_from_cache").Check(testkit.Rows("1")) -} - -func TestNonPreparedCacheWithPreparedCache(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("set tidb_enable_non_prepared_plan_cache=1") - - tk.MustExec(`prepare st from 'select * from t where a=1'`) - tk.MustExec(`execute st`) - tk.MustExec(`execute st`) - tk.MustQuery("select @@last_plan_from_cache").Check(testkit.Rows("1")) - - tk.MustExec(`select * from t where a=1`) // cannot hit since these 2 plan cache are separated - tk.MustQuery("select @@last_plan_from_cache").Check(testkit.Rows("0")) - tk.MustExec(`select * from t where a=1`) - tk.MustQuery("select @@last_plan_from_cache").Check(testkit.Rows("1")) -} - -func TestNonPreparedPlanCacheSwitch(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("set tidb_enable_non_prepared_plan_cache=1") - - tk.MustExec(`select * from t where a=1`) - tk.MustExec(`select * from t where a=1`) - tk.MustQuery("select @@last_plan_from_cache").Check(testkit.Rows("1")) - tk.MustExec("set tidb_enable_non_prepared_plan_cache=0") - tk.MustExec(`select * from t where a=1`) // the session-level switch can take effect in real time - tk.MustQuery("select @@last_plan_from_cache").Check(testkit.Rows("0")) -} - -func TestNonPreparedPlanCacheSwitch2(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec(`use test`) - - for nonPrep := 0; nonPrep <= 1; nonPrep++ { - for prep := 0; prep <= 1; prep++ { - tk.MustExec("create table t(a int)") - tk.MustExec(fmt.Sprintf(`set tidb_enable_non_prepared_plan_cache=%v`, nonPrep)) - tk.MustExec(fmt.Sprintf(`set tidb_enable_prepared_plan_cache=%v`, prep)) - - tk.MustExec(`select * from t where a<1`) - tk.MustExec(`select * from t where a<2`) - tk.MustQuery(`select @@last_plan_from_cache`).Check(testkit.Rows(fmt.Sprintf("%v", nonPrep))) - - tk.MustExec(`prepare st from 'select * from t where a 123 - tk.MustQuery("show warnings").Check(testkit.Rows("Warning 1105 skip prepared plan-cache: '123' may be converted to INT")) - - tk.MustExec("prepare stmt from 'select * from t where a=? and a=?'") - tk.MustExec("set @a=1, @b=1") - tk.MustExec("execute stmt using @a, @b") // a=1 and a=1 -> a=1 - tk.MustQuery("show warnings").Check(testkit.Rows("Warning 1105 skip prepared plan-cache: some parameters may be overwritten")) -} - func TestIssue40224(t *testing.T) { store := testkit.CreateMockStore(t) tk := testkit.NewTestKit(t, store) @@ -1388,38 +465,12 @@ func TestIssue40224(t *testing.T) { tk.MustQuery("show warnings").Check(testkit.Rows()) // no warning for INT values tk.MustExec("execute st using @a, @b") tk.MustQuery("select @@last_plan_from_cache").Check(testkit.Rows("1")) // cacheable for INT - tk.MustExec("execute st using @a, @b") - tk.MustQuery(fmt.Sprintf("explain for connection %d", tkProcess.ID)).CheckAt([]int{0}, - [][]interface{}{ - {"IndexReader_6"}, - {"└─IndexRangeScan_5"}, // range scan not full scan - }) -} - -func TestIssue40225(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec("create table t (a int, key(a))") - tk.MustExec("prepare st from 'select * from t where a INT) since plan-cache is totally disabled. - - tk.MustExec("prepare st from 'select * from t where a>?'") - tk.MustExec("set @a=1") - tk.MustExec("execute st using @a") - tk.MustExec("execute st using @a") - tk.MustQuery("select @@last_plan_from_cache").Check(testkit.Rows("1")) - tk.MustExec("create binding for select * from t where a>1 using select /*+ ignore_plan_cache() */ * from t where a>1") - tk.MustExec("execute st using @a") - tk.MustQuery("select @@last_plan_from_cache").Check(testkit.Rows("0")) - tk.MustExec("execute st using @a") - tk.MustQuery("select @@last_plan_from_binding").Check(testkit.Rows("1")) + tk.MustExec("execute st using @a, @b") + tk.MustQuery(fmt.Sprintf("explain for connection %d", tkProcess.ID)).CheckAt([]int{0}, + [][]interface{}{ + {"IndexReader_6"}, + {"└─IndexRangeScan_5"}, // range scan not full scan + }) } func TestIssue40679(t *testing.T) { @@ -1441,117 +492,6 @@ func TestIssue40679(t *testing.T) { tk.MustQuery("show warnings").Check(testkit.Rows("Warning 1105 skip prepared plan-cache: '1.1' may be converted to INT")) } -func TestIssue38335(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec(`CREATE TABLE PK_LP9463 ( - COL1 mediumint NOT NULL DEFAULT '77' COMMENT 'NUMERIC PK', - COL2 varchar(20) COLLATE utf8mb4_bin DEFAULT NULL, - COL4 datetime DEFAULT NULL, - COL3 bigint DEFAULT NULL, - COL5 float DEFAULT NULL, - PRIMARY KEY (COL1))`) - tk.MustExec(` -INSERT INTO PK_LP9463 VALUES (-7415279,'笚綷想摻癫梒偆荈湩窐曋繾鏫蘌憬稁渣½隨苆','1001-11-02 05:11:33',-3745331437675076296,-3.21618e38), -(-7153863,'鯷氤衡椻闍饑堀鱟垩啵緬氂哨笂序鉲秼摀巽茊','6800-06-20 23:39:12',-7871155140266310321,-3.04829e38), -(77,'娥藨潰眤徕菗柢礥蕶浠嶲憅榩椻鍙鑜堋ᛀ暵氎','4473-09-13 01:18:59',4076508026242316746,-1.9525e38), -(16614,'阖旕雐盬皪豧篣哙舄糗悄蟊鯴瞶珧赺潴嶽簤彉','2745-12-29 00:29:06',-4242415439257105874,2.71063e37)`) - tk.MustExec(`prepare stmt from 'SELECT *, rank() OVER (PARTITION BY col2 ORDER BY COL1) FROM PK_LP9463 WHERE col1 != ? AND col1 < ?'`) - tk.MustExec(`set @a=-8414766051197, @b=-8388608`) - tk.MustExec(`execute stmt using @a,@b`) - tk.MustExec(`set @a=16614, @b=16614`) - rows := tk.MustQuery(`execute stmt using @a,@b`).Sort() - tk.MustQuery(`select @@last_plan_from_cache`).Check(testkit.Rows("0")) - tk.MustQuery(`SELECT *, rank() OVER (PARTITION BY col2 ORDER BY COL1) FROM PK_LP9463 WHERE col1 != 16614 and col1 < 16614`).Sort().Check(rows.Rows()) -} - -func TestIssue41032(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec(`CREATE TABLE PK_SIGNED_10087 ( - COL1 mediumint(8) unsigned NOT NULL, - COL2 varchar(20) DEFAULT NULL, - COL4 datetime DEFAULT NULL, - COL3 bigint(20) DEFAULT NULL, - COL5 float DEFAULT NULL, - PRIMARY KEY (COL1) )`) - tk.MustExec(`insert into PK_SIGNED_10087 values(0, "痥腜蟿鮤枓欜喧檕澙姭袐裄钭僇剕焍哓閲疁櫘", "0017-11-14 05:40:55", -4504684261333179273, 7.97449e37)`) - tk.MustExec(`prepare stmt from 'SELECT/*+ HASH_JOIN(t1, t2) */ t2.* FROM PK_SIGNED_10087 t1 JOIN PK_SIGNED_10087 t2 ON t1.col1 = t2.col1 WHERE t2.col1 >= ? AND t1.col1 >= ?;'`) - tk.MustExec(`set @a=0, @b=0`) - tk.MustQuery(`execute stmt using @a,@b`).Check(testkit.Rows("0 痥腜蟿鮤枓欜喧檕澙姭袐裄钭僇剕焍哓閲疁櫘 0017-11-14 05:40:55 -4504684261333179273 79744900000000000000000000000000000000")) - tk.MustExec(`set @a=8950167, @b=16305982`) - tk.MustQuery(`execute stmt using @a,@b`).Check(testkit.Rows()) - tk.MustQuery(`select @@last_plan_from_cache`).Check(testkit.Rows("1")) -} - -func TestSetPlanCacheLimitSwitch(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - - tk.MustQuery("select @@session.tidb_enable_plan_cache_for_param_limit").Check(testkit.Rows("1")) - tk.MustQuery("select @@global.tidb_enable_plan_cache_for_param_limit").Check(testkit.Rows("1")) - - tk.MustExec("set @@session.tidb_enable_plan_cache_for_param_limit = OFF;") - tk.MustQuery("select @@session.tidb_enable_plan_cache_for_param_limit").Check(testkit.Rows("0")) - - tk.MustExec("set @@session.tidb_enable_plan_cache_for_param_limit = 1;") - tk.MustQuery("select @@session.tidb_enable_plan_cache_for_param_limit").Check(testkit.Rows("1")) - - tk.MustExec("set @@global.tidb_enable_plan_cache_for_param_limit = off;") - tk.MustQuery("select @@global.tidb_enable_plan_cache_for_param_limit").Check(testkit.Rows("0")) - - tk.MustExec("set @@global.tidb_enable_plan_cache_for_param_limit = ON;") - tk.MustQuery("select @@global.tidb_enable_plan_cache_for_param_limit").Check(testkit.Rows("1")) - - tk.MustGetErrMsg("set @@global.tidb_enable_plan_cache_for_param_limit = '';", "[variable:1231]Variable 'tidb_enable_plan_cache_for_param_limit' can't be set to the value of ''") - tk.MustGetErrMsg("set @@global.tidb_enable_plan_cache_for_param_limit = 11;", "[variable:1231]Variable 'tidb_enable_plan_cache_for_param_limit' can't be set to the value of '11'") - tk.MustGetErrMsg("set @@global.tidb_enable_plan_cache_for_param_limit = enabled;", "[variable:1231]Variable 'tidb_enable_plan_cache_for_param_limit' can't be set to the value of 'enabled'") - tk.MustGetErrMsg("set @@global.tidb_enable_plan_cache_for_param_limit = disabled;", "[variable:1231]Variable 'tidb_enable_plan_cache_for_param_limit' can't be set to the value of 'disabled'") - tk.MustGetErrMsg("set @@global.tidb_enable_plan_cache_for_param_limit = open;", "[variable:1231]Variable 'tidb_enable_plan_cache_for_param_limit' can't be set to the value of 'open'") -} - -func TestPlanCacheLimitSwitchEffective(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec("drop table if exists t") - tk.MustExec("create table t(a int, key(a))") - - checkIfCached := func(res string) { - tk.MustExec("set @a = 1") - tk.MustExec("execute stmt using @a") - tk.MustExec("execute stmt using @a") - tk.MustQuery("select @@last_plan_from_cache").Check(testkit.Rows(res)) - } - - // before prepare - tk.MustExec("set @@session.tidb_enable_plan_cache_for_param_limit = OFF") - tk.MustExec("prepare stmt from 'select * from t limit ?'") - tk.MustQuery("show warnings").Check(testkit.Rows("Warning 1105 skip prepared plan-cache: query has 'limit ?' is un-cacheable")) - checkIfCached("0") - tk.MustExec("deallocate prepare stmt") - - // after prepare - tk.MustExec("set @@session.tidb_enable_plan_cache_for_param_limit = ON") - tk.MustExec("prepare stmt from 'select * from t limit ?'") - tk.MustExec("set @@session.tidb_enable_plan_cache_for_param_limit = OFF") - checkIfCached("0") - tk.MustExec("execute stmt using @a") - tk.MustQuery("show warnings").Check(testkit.Rows("Warning 1105 skip prepared plan-cache: the switch 'tidb_enable_plan_cache_for_param_limit' is off")) - tk.MustExec("deallocate prepare stmt") - - // after execute - tk.MustExec("set @@session.tidb_enable_plan_cache_for_param_limit = ON") - tk.MustExec("prepare stmt from 'select * from t limit ?'") - checkIfCached("1") - tk.MustExec("set @@session.tidb_enable_plan_cache_for_param_limit = OFF") - checkIfCached("0") - tk.MustExec("deallocate prepare stmt") -} - func TestPlanCacheWithLimit(t *testing.T) { store := testkit.CreateMockStore(t) tk := testkit.NewTestKit(t, store) @@ -1600,87 +540,6 @@ func TestPlanCacheWithLimit(t *testing.T) { tk.MustQuery("show warnings").Check(testkit.Rows("Warning 1105 skip prepared plan-cache: limit count is too large")) } -func TestPlanCacheMemoryTable(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec(`create table t1 (a int)`) - tk.MustExec(`create table t2 (a int, b int)`) - - tk.MustExec(`prepare st from 'select count(*) from information_schema.COLUMNS where table_name=?'`) - tk.MustExec(`set @a='t1'`) - tk.MustQuery(`execute st using @a`).Check(testkit.Rows("1")) // 1 column - tk.MustExec(`set @a='t2'`) - tk.MustQuery(`execute st using @a`).Check(testkit.Rows("2")) // 2 columns - tk.MustQuery(`select @@last_plan_from_cache`).Check(testkit.Rows("0")) // plan accessing memory tables cannot hit the cache -} - -func TestSetPlanCacheSubquerySwitch(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - - tk.MustQuery("select @@session.tidb_enable_plan_cache_for_subquery").Check(testkit.Rows("1")) - tk.MustQuery("select @@global.tidb_enable_plan_cache_for_subquery").Check(testkit.Rows("1")) - - tk.MustExec("set @@session.tidb_enable_plan_cache_for_subquery = OFF;") - tk.MustQuery("select @@session.tidb_enable_plan_cache_for_subquery").Check(testkit.Rows("0")) - - tk.MustExec("set @@session.tidb_enable_plan_cache_for_subquery = 1;") - tk.MustQuery("select @@session.tidb_enable_plan_cache_for_subquery").Check(testkit.Rows("1")) - - tk.MustExec("set @@global.tidb_enable_plan_cache_for_subquery = off;") - tk.MustQuery("select @@global.tidb_enable_plan_cache_for_subquery").Check(testkit.Rows("0")) - - tk.MustExec("set @@global.tidb_enable_plan_cache_for_subquery = ON;") - tk.MustQuery("select @@global.tidb_enable_plan_cache_for_subquery").Check(testkit.Rows("1")) - - tk.MustGetErrMsg("set @@global.tidb_enable_plan_cache_for_subquery = '';", "[variable:1231]Variable 'tidb_enable_plan_cache_for_subquery' can't be set to the value of ''") - tk.MustGetErrMsg("set @@global.tidb_enable_plan_cache_for_subquery = 11;", "[variable:1231]Variable 'tidb_enable_plan_cache_for_subquery' can't be set to the value of '11'") - tk.MustGetErrMsg("set @@global.tidb_enable_plan_cache_for_subquery = enabled;", "[variable:1231]Variable 'tidb_enable_plan_cache_for_subquery' can't be set to the value of 'enabled'") - tk.MustGetErrMsg("set @@global.tidb_enable_plan_cache_for_subquery = disabled;", "[variable:1231]Variable 'tidb_enable_plan_cache_for_subquery' can't be set to the value of 'disabled'") - tk.MustGetErrMsg("set @@global.tidb_enable_plan_cache_for_subquery = open;", "[variable:1231]Variable 'tidb_enable_plan_cache_for_subquery' can't be set to the value of 'open'") -} - -func TestPlanCacheSubQuerySwitchEffective(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec("drop table if exists t") - tk.MustExec("create table t(a int, key(a))") - tk.MustExec("create table s(a int, key(a))") - - checkIfCached := func(res string) { - tk.MustExec("execute stmt") - tk.MustExec("execute stmt") - tk.MustQuery("select @@last_plan_from_cache").Check(testkit.Rows(res)) - } - - // before prepare - tk.MustExec("set @@session.tidb_enable_plan_cache_for_subquery = OFF") - tk.MustExec("prepare stmt from 'select * from t where a in (select a from s)'") - tk.MustQuery("show warnings").Check(testkit.Rows("Warning 1105 skip prepared plan-cache: query has sub-queries is un-cacheable")) - checkIfCached("0") - tk.MustExec("deallocate prepare stmt") - - // after prepare - tk.MustExec("set @@session.tidb_enable_plan_cache_for_subquery = ON") - tk.MustExec("prepare stmt from 'select * from t where a in (select a from s)'") - tk.MustExec("set @@session.tidb_enable_plan_cache_for_subquery = OFF") - checkIfCached("0") - tk.MustExec("execute stmt") - tk.MustQuery("show warnings").Check(testkit.Rows("Warning 1105 skip prepared plan-cache: the switch 'tidb_enable_plan_cache_for_subquery' is off")) - tk.MustExec("deallocate prepare stmt") - - // after execute - tk.MustExec("set @@session.tidb_enable_plan_cache_for_subquery = ON") - tk.MustExec("prepare stmt from 'select * from t where a in (select a from s)'") - checkIfCached("1") - tk.MustExec("set @@session.tidb_enable_plan_cache_for_subquery = OFF") - checkIfCached("0") - tk.MustExec("deallocate prepare stmt") -} - func TestPlanCacheWithSubquery(t *testing.T) { store := testkit.CreateMockStore(t) tk := testkit.NewTestKit(t, store) @@ -1741,26 +600,6 @@ func TestPlanCacheWithSubquery(t *testing.T) { } } -func TestIssue41828(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec(`CREATE TABLE IDT_MULTI15840STROBJSTROBJ ( - COL1 enum('aa', 'zzz') DEFAULT NULL, - COL2 smallint(6) DEFAULT NULL, - COL3 date DEFAULT NULL, - KEY U_M_COL4 (COL1,COL2), - KEY U_M_COL5 (COL3,COL2))`) - - tk.MustExec(`INSERT INTO IDT_MULTI15840STROBJSTROBJ VALUES ('zzz',1047,'6115-06-05'),('zzz',-23221,'4250-09-03'),('zzz',27138,'1568-07-30'),('zzz',-30903,'6753-08-21'),('zzz',-26875,'6117-10-10')`) - tk.MustExec(`prepare stmt from 'select * from IDT_MULTI15840STROBJSTROBJ where col3 <=> ? or col1 in (?, ?, ?) and col2 not between ? and ?'`) - tk.MustExec(`set @a="0051-12-23", @b="none", @c="none", @d="none", @e=-32757, @f=-32757`) - tk.MustQuery(`execute stmt using @a,@b,@c,@d,@e,@f`).Check(testkit.Rows()) - tk.MustQuery(`show warnings`).Check(testkit.Rows(`Warning 1105 skip prepared plan-cache: IndexMerge plan with full-scan is un-cacheable`)) - tk.MustExec(`set @a="9795-01-10", @b="aa", @c="aa", @d="aa", @e=31928, @f=31928`) - tk.MustQuery(`execute stmt using @a,@b,@c,@d,@e,@f`).Check(testkit.Rows()) -} - func convertQueryToPrepExecStmt(q string) (normalQuery, prepStmt string, parameters []string) { // select ... from t where a = #?1# and b = #?2# normalQuery = strings.ReplaceAll(q, "#", "") @@ -2123,70 +962,6 @@ func TestPlanCacheSubquerySPMEffective(t *testing.T) { } } -func TestNonPreparedPlanCacheDMLSwitch(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("set tidb_enable_non_prepared_plan_cache=1") - - tk.MustExec("set tidb_enable_non_prepared_plan_cache_for_dml=0") - tk.MustExec(`insert into t values (1)`) - tk.MustExec(`insert into t values (1)`) - tk.MustQuery(`select @@last_plan_from_cache`).Check(testkit.Rows("0")) - tk.MustExec(`select a from t where a < 2 for update`) - tk.MustExec(`select a from t where a < 2 for update`) - tk.MustQuery(`select @@last_plan_from_cache`).Check(testkit.Rows("0")) - tk.MustExec(`set @x:=1`) - tk.MustExec(`set @x:=1`) - tk.MustQuery(`select @@last_plan_from_cache`).Check(testkit.Rows("0")) - - tk.MustExec("set tidb_enable_non_prepared_plan_cache_for_dml=1") - tk.MustExec(`insert into t values (1)`) - tk.MustExec(`insert into t values (1)`) - tk.MustQuery(`select @@last_plan_from_cache`).Check(testkit.Rows("1")) - tk.MustExec(`select a from t where a < 2 for update`) - tk.MustExec(`select a from t where a < 2 for update`) - tk.MustQuery(`select @@last_plan_from_cache`).Check(testkit.Rows("1")) -} - -func TestNonPreparedPlanCacheUnderscoreCharset(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec(`use test`) - tk.MustExec("create table t (a varchar(10), b int)") - tk.MustExec("set tidb_enable_non_prepared_plan_cache=1") - - tk.MustExec(`select * from t where a = _utf8'a'`) - tk.MustExec(`select * from t where a = _utf8'a'`) - tk.MustQuery(`select @@last_plan_from_cache`).Check(testkit.Rows("0")) - tk.MustExec(`select * from t where a = _latin1'a'`) - tk.MustExec(`select * from t where a = _latin1'a'`) - tk.MustQuery(`select @@last_plan_from_cache`).Check(testkit.Rows("0")) - tk.MustExec(`select * from t where a = N'a'`) // equals to _utf8'a' - tk.MustExec(`select * from t where a = N'a'`) - tk.MustQuery(`select @@last_plan_from_cache`).Check(testkit.Rows("0")) - tk.MustExec(`select * from t where a = 'a'`) - tk.MustExec(`select * from t where a = 'a'`) // can hit if no underscore charset - tk.MustQuery(`select @@last_plan_from_cache`).Check(testkit.Rows("1")) -} - -func TestNonPreparedPlanCacheGroupBy(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec(`use test`) - tk.MustExec("create table t(a int, b int, index(a))") - tk.MustExec("set tidb_enable_non_prepared_plan_cache=1") - - tk.MustExec(`select sum(b) from t group by a+1`) - tk.MustExec(`select sum(b) from t group by a+1`) - tk.MustQuery(`select @@last_plan_from_cache`).Check(testkit.Rows("0")) - tk.MustExec(`select sum(b) from t group by a+2`) - tk.MustQuery(`select @@last_plan_from_cache`).Check(testkit.Rows("0")) - tk.MustExec(`select sum(b) from t group by a+2`) - tk.MustQuery(`select @@last_plan_from_cache`).Check(testkit.Rows("0")) -} - func TestNonPreparedPlanCacheFieldNames(t *testing.T) { store := testkit.CreateMockStore(t) tk := testkit.NewTestKit(t, store) @@ -2222,33 +997,6 @@ func TestNonPreparedPlanCacheFieldNames(t *testing.T) { checkFieldName(`select 1,2 from t where a<20`, `1`, `1`, `2`) } -func TestNonPreparedPlanCacheExplain(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec(`use test`) - tk.MustExec("create table t(a int, index(a))") - tk.MustExec("set tidb_enable_non_prepared_plan_cache=1") - - formats := []string{ - "row", - "brief", - "dot", - "tidb_json", - "verbose", - "cost_trace", - } - - for _, format := range formats { - tk.MustExec(fmt.Sprintf("explain format = '%v' select * from t", format)) - tk.MustQuery("select @@last_plan_from_cache").Check(testkit.Rows("0")) - } - - for _, format := range formats { - tk.MustExec(fmt.Sprintf("explain format = '%v' select * from t limit 1", format)) - tk.MustQuery("show warnings").Check(testkit.Rows()) - } -} - func TestIssue42125(t *testing.T) { store := testkit.CreateMockStore(t) tk := testkit.NewTestKit(t, store) @@ -2413,61 +1161,6 @@ func TestNonPreparedPlanExplainWarning(t *testing.T) { } } -func TestIssue42150(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec(`use test`) - tk.MustExec("drop table if exists t1, t2") - tk.MustExec("CREATE TABLE `t1` (`c_int` int(11) NOT NULL, `c_str` varchar(40) CHARACTER SET utf8 COLLATE utf8_bin DEFAULT NULL, `c_datetime` datetime DEFAULT NULL, `c_timestamp` timestamp NULL DEFAULT NULL, `c_double` double DEFAULT NULL, `c_decimal` decimal(12,6) DEFAULT NULL, `c_enum` enum('blue','green','red','yellow','white','orange','purple') NOT NULL, PRIMARY KEY (`c_int`,`c_enum`) /*T![clustered_index] CLUSTERED */, KEY `c_decimal` (`c_decimal`), UNIQUE KEY `c_datetime` (`c_datetime`), UNIQUE KEY `c_timestamp` (`c_timestamp`)) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin;") - tk.MustExec("CREATE TABLE `t2` (`c_int` int(11) NOT NULL, `c_str` varchar(40) CHARACTER SET utf8 COLLATE utf8_bin DEFAULT NULL, `c_datetime` datetime DEFAULT NULL, `c_timestamp` timestamp NULL DEFAULT NULL, `c_double` double DEFAULT NULL, `c_decimal` decimal(12,6) DEFAULT NULL, `c_enum` enum('blue','green','red','yellow','white','orange','purple') NOT NULL, PRIMARY KEY (`c_int`,`c_enum`) /*T![clustered_index] CLUSTERED */, KEY `c_decimal` (`c_decimal`), UNIQUE KEY `c_datetime` (`c_datetime`), UNIQUE KEY `c_timestamp` (`c_timestamp`)) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin;") - tk.MustExec("create table t (a int, b int, primary key(a), key(b))") - tk.MustExec("set @v0 = 'nice hellman', @v1 = 'flamboyant booth', @v2 = 'quirky brahmagupta'") - tk.MustExec("prepare stmt16 from 'select * from t1 where c_enum in (select c_enum from t2 where t1.c_str in (?, ?, ?))'") - tk.MustExec("execute stmt16 using @v0, @v1, @v2;") - tk.MustExec("execute stmt16 using @v0, @v1, @v2;") - tk.MustQuery("select @@last_plan_from_cache").Check(testkit.Rows("1")) - - tk.MustExec("prepare stmt from 'select c_enum from t1'") - tk.MustExec("execute stmt;") - tk.MustExec("execute stmt;") - tk.MustQuery("select @@last_plan_from_cache").Check(testkit.Rows("1")) - - tk.MustExec("prepare st from 'select a from t use index(b)'") - tk.MustExec("execute st") - tk.MustExec("execute st") - tk.MustQuery("select @@last_plan_from_cache").Check(testkit.Rows("1")) -} - -func TestNonPreparedPlanCacheDML(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(`set tidb_enable_non_prepared_plan_cache_for_dml=1`) - tk.MustExec("create table t (a int default 0, b int default 0)") - - for _, sql := range []string{ - `select a from t for update`, - `select a from t where a<10 for update`, - `insert into t values (1, 1)`, - `insert into t (a, b) values (1, 1)`, - `insert into t (a) values (1)`, - `insert into t (b) values (1)`, - `insert into t select * from t`, - `insert into t select * from t where a>10`, - `update t set a=1`, - `update t set a=1 where a>10`, - `update t set a=1, b=1`, - `update t set a=a+1 where a>10`, - `delete from t`, - `delete from t where a>10`, - } { - tk.MustExec(sql) - tk.MustExec(sql) - tk.MustQuery("select @@last_plan_from_cache").Check(testkit.Rows("1")) - } -} - func TestNonPreparedPlanCachePanic(t *testing.T) { store := testkit.CreateMockStore(t) tk := testkit.NewTestKit(t, store) @@ -2494,151 +1187,6 @@ func TestNonPreparedPlanCachePanic(t *testing.T) { } } -func TestNonPreparedPlanCacheMultiStmt(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(`set tidb_enable_non_prepared_plan_cache_for_dml=1`) - tk.MustExec("create table t (a int)") - - tk.MustExec("update t set a=1 where a<10") - tk.MustExec("update t set a=2 where a<12") - tk.MustQuery("select @@last_plan_from_cache").Check(testkit.Rows("1")) - - // multi-stmt SQL cannot hit the cache - tk.MustExec("update t set a=1 where a<10; update t set a=2 where a<12") - tk.MustExec("update t set a=1 where a<10; update t set a=2 where a<12") - tk.MustQuery("select @@last_plan_from_cache").Check(testkit.Rows("1")) - - tk.MustExec("update t set a=2 where a<12") - tk.MustQuery("select @@last_plan_from_cache").Check(testkit.Rows("1")) -} - -func TestNonPreparedPlanCacheJoin(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("create table t1 (a int, b int, c int)") - tk.MustExec("create table t2 (a int, b int, c int)") - tk.MustExec("create table t3 (a int, b int, c int)") - tk.MustExec("create table t4 (a int, x int)") - - supported := []string{ - "select * from t1, t2 where t1.a=t2.a and t1.b<10", - "select * from t1, t2", - "select * from t1, t2 where t1.a10, N'x', N'y')) from t1`).Check(testkit.Rows("ay")) // no error - tk.MustQuery(`select concat(a, if(b>10, N'x', N'y')) from t1`).Check(testkit.Rows("ay")) - tk.MustQuery("select @@last_plan_from_cache").Check(testkit.Rows("0")) -} - func TestNonPreparedPlanCacheAutoStmtRetry(t *testing.T) { store := testkit.CreateMockStore(t) @@ -2739,59 +1287,6 @@ func TestIssue47133(t *testing.T) { require.Equal(t, cnt, 2) } -func TestIssue45253(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(`CREATE TABLE t1 (c1 INT)`) - tk.MustExec(`INSERT INTO t1 VALUES (1)`) - - tk.MustQuery(`SELECT c1 FROM t1 WHERE TO_BASE64('牵')`).Check(testkit.Rows("1")) - tk.MustQuery(`SELECT c1 FROM t1 WHERE TO_BASE64('牵')`).Check(testkit.Rows("1")) - tk.MustQuery(`select @@last_plan_from_cache`).Check(testkit.Rows("1")) - tk.MustQuery(`SELECT c1 FROM t1 WHERE TO_BASE64('哈')`).Check(testkit.Rows("1")) - tk.MustQuery(`select @@last_plan_from_cache`).Check(testkit.Rows("1")) - tk.MustQuery(`SELECT c1 FROM t1 WHERE TO_BASE64('')`).Check(testkit.Rows()) -} - -func TestIssue45378(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(`CREATE TABLE t1(c1 INT)`) - tk.MustExec(`INSERT INTO t1 VALUES (1)`) - - tk.MustQuery(`SELECT c1 FROM t1 WHERE UNHEX(2038330881)`).Check(testkit.Rows("1")) - tk.MustQuery(`SELECT c1 FROM t1 WHERE UNHEX(2038330881)`).Check(testkit.Rows("1")) - tk.MustQuery(`select @@last_plan_from_cache`).Check(testkit.Rows("1")) -} - -func TestIssue46159(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec(`create table t (a varchar(10), key(a(5)))`) - tk.MustExec(`prepare st from 'select a from t use index(a) where a=?'`) - tk.MustExec(`set @a='a'`) - tk.MustQuery(`execute st using @a`).Check(testkit.Rows()) - tk.MustQuery(`execute st using @a`).Check(testkit.Rows()) - tk.MustQuery(`show warnings`).Check(testkit.Rows("Warning 1105 skip plan-cache: plan rebuild failed, rebuild to get an unsafe range")) -} - -func TestIssue47008(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec(`set @@time_zone='UTC';`) - tk.MustExec(`set @@collation_connection='utf8_general_ci';`) - tk.MustExec(`prepare s from 'select DATE_FORMAT("2020-01-01","%W") = "wednesday"';`) - tk.MustQuery(`execute s;`).Check(testkit.Rows(`1`)) - tk.MustExec(`set @@collation_connection='utf8_bin';`) - tk.MustQuery(`execute s;`).Check(testkit.Rows(`0`)) - tk.MustQuery(`select @@last_plan_from_cache`).Check(testkit.Rows(`0`)) -} - func TestBuiltinFuncFlen(t *testing.T) { // same as TestIssue45378 and TestIssue45253 store := testkit.CreateMockStore(t) diff --git a/tests/integrationtest/r/planner/core/integration_partition.result b/tests/integrationtest/r/planner/core/integration_partition.result index e7cd7cfa89b52..53918f543509c 100644 --- a/tests/integrationtest/r/planner/core/integration_partition.result +++ b/tests/integrationtest/r/planner/core/integration_partition.result @@ -514,9 +514,9 @@ PARTITION P8 VALUES IN (126,30,48,68) insert into PK_LP9326 values(30),(48),(56); SELECT COL1 FROM PK_LP9326 WHERE COL1 NOT IN (621579514938,-17333745845828,2777039147338); COL1 -56 30 48 +56 create database issue_27017; use issue_27017; set tidb_enable_list_partition = 1; diff --git a/tests/integrationtest/r/planner/core/plan_cache.result b/tests/integrationtest/r/planner/core/plan_cache.result new file mode 100644 index 0000000000000..a392e65f91515 --- /dev/null +++ b/tests/integrationtest/r/planner/core/plan_cache.result @@ -0,0 +1,2282 @@ +drop table if exists t; +create table t (id int, value decimal(7,4), c1 int, c2 int); +insert into t values (1,1.9285,54,28), (1,1.9286,54,28); +set session tidb_enable_non_prepared_plan_cache=0; +select * from t where value = 54 / 28; +id value c1 c2 +set session tidb_enable_non_prepared_plan_cache=1; +select * from t where value = 54 / 28; +id value c1 c2 +select * from t where value = 54 / 28; +id value c1 c2 +prepare st from 'select * from t where value = ? / ?'; +set @a=54, @b=28; +execute st using @a, @b; +id value c1 c2 +execute st using @a, @b; +id value c1 c2 +set session tidb_enable_non_prepared_plan_cache=DEFAULT; +set @@tidb_opt_fix_control = "44830:ON"; +drop table if exists t, t1; +create table t (a int, primary key(a)); +create table t1 (a int, b int, primary key(a, b)); +insert into t values (1), (2), (3); +insert into t1 values (1, 1), (2, 2), (3, 3); +set @a=1, @b=2, @c=3; +prepare st from 'select * from t where 1=1 and a in (?, ?, ?)'; +execute st using @a, @b, @c; +a +1 +2 +3 +execute st using @a, @b, @c; +a +1 +2 +3 +select @@last_plan_from_cache; +@@last_plan_from_cache +1 +execute st using @a, @b, @b; +a +1 +2 +select @@last_plan_from_cache; +@@last_plan_from_cache +0 +execute st using @b, @b, @b; +a +2 +select @@last_plan_from_cache; +@@last_plan_from_cache +0 +execute st using @a, @b, @c; +a +1 +2 +3 +execute st using @a, @b, @b; +a +1 +2 +execute st using @a, @b, @b; +a +1 +2 +select @@last_plan_from_cache; +@@last_plan_from_cache +0 +prepare st from 'select * from t1 where 1=1 and (a, b) in ((?, ?), (?, ?), (?, ?))'; +execute st using @a, @a, @b, @b, @c, @c; +a b +1 1 +2 2 +3 3 +execute st using @a, @a, @b, @b, @c, @c; +a b +1 1 +2 2 +3 3 +select @@last_plan_from_cache; +@@last_plan_from_cache +1 +execute st using @a, @a, @b, @b, @b, @b; +a b +1 1 +2 2 +select @@last_plan_from_cache; +@@last_plan_from_cache +0 +execute st using @b, @b, @b, @b, @b, @b; +a b +2 2 +select @@last_plan_from_cache; +@@last_plan_from_cache +0 +execute st using @b, @b, @b, @b, @c, @c; +a b +2 2 +3 3 +select @@last_plan_from_cache; +@@last_plan_from_cache +0 +execute st using @a, @a, @a, @a, @a, @a; +a b +1 1 +execute st using @a, @a, @a, @a, @a, @a; +a b +1 1 +select @@last_plan_from_cache; +@@last_plan_from_cache +0 +execute st using @a, @a, @b, @b, @b, @b; +a b +1 1 +2 2 +execute st using @a, @a, @b, @b, @b, @b; +a b +1 1 +2 2 +select @@last_plan_from_cache; +@@last_plan_from_cache +0 +set @@tidb_opt_fix_control = DEFAULT; +set @@tidb_enable_non_prepared_plan_cache=1; +set @@tidb_opt_fix_control = "44830:ON"; +drop table if exists t1; +create table t1 (a int, b int, primary key(a, b)); +insert into t1 values (1, 1), (2, 2), (3, 3); +set @a=1, @b=2, @c=3; +select * from t1 where 1=1 and (a, b) in ((1, 1), (2, 2), (3, 3)); +a b +1 1 +2 2 +3 3 +select * from t1 where 1=1 and (a, b) in ((1, 1), (2, 2), (3, 3)); +a b +1 1 +2 2 +3 3 +select @@last_plan_from_cache; +@@last_plan_from_cache +1 +select * from t1 where 1=1 and (a, b) in ((1, 1), (2, 2), (2, 2)); +a b +1 1 +2 2 +select @@last_plan_from_cache; +@@last_plan_from_cache +0 +select * from t1 where 1=1 and (a, b) in ((2, 2), (2, 2), (2, 2)); +a b +2 2 +select @@last_plan_from_cache; +@@last_plan_from_cache +0 +select * from t1 where 1=1 and (a, b) in ((1, 1), (1, 1), (1, 1)); +a b +1 1 +select * from t1 where 1=1 and (a, b) in ((1, 1), (1, 1), (1, 1)); +a b +1 1 +select @@last_plan_from_cache; +@@last_plan_from_cache +0 +set @@tidb_enable_non_prepared_plan_cache=DEFAULT; +set @@tidb_opt_fix_control = DEFAULT; +drop table if exists t, t1; +create table t (a int unsigned, key(a)); +prepare st from 'select a from t use index(a) where a= 659971401668884663953087553591534913868320924.5040396 and col2 = 869042976700631943559871054704914143535627349.9659934; +Error 1690 (22003): DECIMAL value is out of range in '(869042976700631943559871054704914143535627349.9659934 * 49015787697063065230692384394107598316198958.1850509)' +drop table if exists t; +create table t(a varchar(8) not null, b varchar(8) not null); +insert into t values('1','1'); +prepare stmt from "select count(1) from t t1, t t2 where t1.a = t2.a and t2.b = '1' and t2.b = ?"; +set @a = '1'; +execute stmt using @a; +count(1) +1 +set @a = '2'; +execute stmt using @a; +count(1) +0 +prepare stmt from "select count(1) from t t1, t t2 where t1.a = t2.a and t1.a > ?"; +set @a = '1'; +execute stmt using @a; +count(1) +0 +set @a = '0'; +execute stmt using @a; +count(1) +1 +drop table if exists t; +create table t(a varchar(8), b varchar(8)); +insert into t values('1','1'); +prepare stmt from "select count(1) from t t1 left join t t2 on t1.a = t2.a where t2.b = ? and t2.b = ?"; +set @p0 = '1', @p1 = '2'; +execute stmt using @p0, @p1; +count(1) +0 +set @p0 = '1', @p1 = '1'; +execute stmt using @p0, @p1; +count(1) +1 +drop table if exists t; +create table t (a int); +set @@tidb_enable_non_prepared_plan_cache=1; +set @@tidb_enable_non_prepared_plan_cache_for_dml=1; +insert into t values (1); +insert into t values (1); +select @@last_plan_from_cache; +@@last_plan_from_cache +1 +update t set a=1; +update t set a=1; +select @@last_plan_from_cache; +@@last_plan_from_cache +1 +delete from t where a=1; +delete from t where a=1; +select @@last_plan_from_cache; +@@last_plan_from_cache +1 +insert /*+ ignore_plan_cache() */ into t values (1); +insert /*+ ignore_plan_cache() */ into t values (1); +select @@last_plan_from_cache; +@@last_plan_from_cache +0 +update /*+ ignore_plan_cache() */ t set a=1; +update /*+ ignore_plan_cache() */ t set a=1; +select @@last_plan_from_cache; +@@last_plan_from_cache +0 +delete /*+ ignore_plan_cache() */ from t where a=1; +delete /*+ ignore_plan_cache() */ from t where a=1; +select @@last_plan_from_cache; +@@last_plan_from_cache +0 +insert into t values (1); +select @@last_plan_from_cache; +@@last_plan_from_cache +1 +update t set a=1; +select @@last_plan_from_cache; +@@last_plan_from_cache +1 +delete from t where a=1; +select @@last_plan_from_cache; +@@last_plan_from_cache +1 +set @@tidb_enable_non_prepared_plan_cache=DEFAULT; +set @@tidb_enable_non_prepared_plan_cache_for_dml=DEFAULT; +drop table if exists t; +create table t(a int, b json); +set tidb_enable_non_prepared_plan_cache=1; +select * from t where a<1; +a b +select * from t where a<2; +a b +select @@last_plan_from_cache; +@@last_plan_from_cache +1 +select * from t where b<1; +a b +select * from t where b<2; +a b +select @@last_plan_from_cache; +@@last_plan_from_cache +0 +select b from t where a<1; +b +select b from t where a<2; +b +select @@last_plan_from_cache; +@@last_plan_from_cache +1 +set tidb_enable_non_prepared_plan_cache=DEFAULT; +drop table if exists t; +create table t(a int, b enum('1', '2', '3')); +set tidb_enable_non_prepared_plan_cache=1; +select * from t where a<1; +a b +select * from t where a<2; +a b +select @@last_plan_from_cache; +@@last_plan_from_cache +1 +select * from t where b='1'; +a b +select * from t where b='2'; +a b +select @@last_plan_from_cache; +@@last_plan_from_cache +0 +select b from t where a<1; +b +select b from t where a<2; +b +select @@last_plan_from_cache; +@@last_plan_from_cache +1 +set tidb_enable_non_prepared_plan_cache=DEFAULT; +drop table if exists t1; +set tidb_enable_non_prepared_plan_cache=1; +create table t1 (s1 char(20) character set latin1); +insert into t1 values (date_format('2004-02-02','%M')); +select * from t1; +s1 +February +set tidb_enable_non_prepared_plan_cache=DEFAULT; +drop table if exists t; +create table t(a int); +set tidb_enable_non_prepared_plan_cache=1; +select * from t where a=1; +a +select * from t where a=2; +a +select @@last_plan_from_cache; +@@last_plan_from_cache +1 +select * from t where a=null; +a +select @@last_plan_from_cache; +@@last_plan_from_cache +0 +select * from t where a=2; +a +select @@last_plan_from_cache; +@@last_plan_from_cache +1 +set tidb_enable_non_prepared_plan_cache=DEFAULT; +drop table if exists t; +create table t(a int); +set tidb_enable_non_prepared_plan_cache=1; +select * from t where a in (1, 2, 3); +a +select * from t where a in (2, 3, 4); +a +select @@last_plan_from_cache; +@@last_plan_from_cache +1 +select * from t where a in (2, 3, 4, 5); +a +select @@last_plan_from_cache; +@@last_plan_from_cache +0 +select * from t where a in (1, 2, 3, 4); +a +select @@last_plan_from_cache; +@@last_plan_from_cache +1 +set tidb_enable_non_prepared_plan_cache=DEFAULT; +set tidb_enable_non_prepared_plan_cache=1; +select data_type from INFORMATION_SCHEMA.columns where table_name = 'v'; +data_type +select data_type from INFORMATION_SCHEMA.columns where table_name = 'v'; +data_type +select @@last_plan_from_cache; +@@last_plan_from_cache +0 +set tidb_enable_non_prepared_plan_cache=DEFAULT; +drop table if exists t; +create table t(a int); +set tidb_enable_non_prepared_plan_cache=1; +select * from t where a in (0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198); +a +select * from t where a in (0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198); +a +select @@last_plan_from_cache; +@@last_plan_from_cache +1 +select * from t where a in (0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199); +a +select * from t where a in (0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199); +a +select @@last_plan_from_cache; +@@last_plan_from_cache +1 +select * from t where a in (0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 200); +a +select * from t where a in (0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 200); +a +select @@last_plan_from_cache; +@@last_plan_from_cache +0 +set tidb_enable_non_prepared_plan_cache=DEFAULT; +drop table if exists t; +create table t(a int); +set tidb_enable_non_prepared_plan_cache=1; +select * from t where a=1; +a +select * from t where a=1; +a +select @@last_plan_from_cache; +@@last_plan_from_cache +1 +alter table t add index idx_a(a); +select * from t where a=1; +a +select @@last_plan_from_cache; +@@last_plan_from_cache +0 +select * from t where a=1; +a +select @@last_plan_from_cache; +@@last_plan_from_cache +1 +set tidb_enable_non_prepared_plan_cache=DEFAULT; +drop table if exists t; +create table t(a int); +set tidb_enable_non_prepared_plan_cache=1; +prepare st from 'select * from t where a=1'; +execute st; +a +execute st; +a +select @@last_plan_from_cache; +@@last_plan_from_cache +1 +select * from t where a=1; +a +select @@last_plan_from_cache; +@@last_plan_from_cache +0 +select * from t where a=1; +a +select @@last_plan_from_cache; +@@last_plan_from_cache +1 +set tidb_enable_non_prepared_plan_cache=DEFAULT; +drop table if exists t; +create table t(a int); +set tidb_enable_non_prepared_plan_cache=1; +select * from t where a=1; +a +select * from t where a=1; +a +select @@last_plan_from_cache; +@@last_plan_from_cache +1 +set tidb_enable_non_prepared_plan_cache=0; +select * from t where a=1; +a +select @@last_plan_from_cache; +@@last_plan_from_cache +0 +set tidb_enable_non_prepared_plan_cache=DEFAULT; +drop table if exists t; +create table t(a int); +set tidb_enable_non_prepared_plan_cache=0; +set tidb_enable_prepared_plan_cache=0; +select * from t where a<1; +a +select * from t where a<2; +a +select @@last_plan_from_cache; +@@last_plan_from_cache +0 +prepare st from 'select * from t where aplanner__core__plan_cache.t.a +│ └─TableReader_21 7992.00 root data:HashAgg_15 +│ └─HashAgg_15 7992.00 cop[tikv] group by:planner__core__plan_cache.t.a, +│ └─Selection_19 9990.00 cop[tikv] not(isnull(planner__core__plan_cache.t.a)) +│ └─TableFullScan_18 10000.00 cop[tikv] table:t keep order:false, stats:pseudo +└─TableReader_14(Probe) 9990.00 root data:Selection_13 + └─Selection_13 9990.00 cop[tikv] not(isnull(planner__core__plan_cache.t.a)) + └─TableFullScan_12 10000.00 cop[tikv] table:t keep order:false, stats:pseudo +set tidb_enable_non_prepared_plan_cache=DEFAULT; +set tidb_enable_non_prepared_plan_cache=1; +explain format='plan_cache' select address from PERFORMANCE_SCHEMA.tikv_profile_cpu; +id estRows task access object operator info +Projection_3 10000.00 root Column#1 +└─MemTableScan_4 10000.00 root table:tikv_profile_cpu +Level Code Message +Warning 1105 skip non-prepared plan-cache: access tables in system schema +use PERFORMANCE_SCHEMA; +explain format='plan_cache' select address from tikv_profile_cpu; +id estRows task access object operator info +Projection_3 10000.00 root Column#1 +└─MemTableScan_4 10000.00 root table:tikv_profile_cpu +Level Code Message +Warning 1105 skip non-prepared plan-cache: access tables in system schema +set tidb_enable_non_prepared_plan_cache=DEFAULT; +use planner__core__plan_cache; +drop table if exists t; +create table t(a int); +set tidb_enable_non_prepared_plan_cache=1; +select * from t where a=1; +a +select * from t where a=1; +a +select @@last_plan_from_cache; +@@last_plan_from_cache +1 +set @@sql_mode=''; +select * from t where a=1; +a +select @@last_plan_from_cache; +@@last_plan_from_cache +0 +select * from t where a=1; +a +select @@last_plan_from_cache; +@@last_plan_from_cache +1 +set @@sql_mode=DEFAULT; +set tidb_enable_non_prepared_plan_cache=DEFAULT; +drop table if exists t; +create table t(a int, b int, c varchar(2048)); +prepare st from 'select * from t, t t1 where t1.c=space(2048) and t.c=space(2048) and t.a=t1.b union all select * from t, t t1 where t1.c=space(2048) and t.c=space(2048) and t.a=t1.b union all select * from t, t t1 where t1.c=space(2048) and t.c=space(2048) and t.a=t1.b union all select * from t, t t1 where t1.c=space(2048) and t.c=space(2048) and t.a=t1.b union all select * from t, t t1 where t1.c=space(2048) and t.c=space(2048) and t.a=t1.b union all select * from t, t t1 where t1.c=space(2048) and t.c=space(2048) and t.a=t1.b union all select * from t, t t1 where t1.c=space(2048) and t.c=space(2048) and t.a=t1.b union all select * from t, t t1 where t1.c=space(2048) and t.c=space(2048) and t.a=t1.b union all select * from t, t t1 where t1.c=space(2048) and t.c=space(2048) and t.a=t1.b union all select * from t, t t1 where t1.c=space(2048) and t.c=space(2048) and t.a=t1.b union all select * from t, t t1 where t1.c=space(2048) and t.c=space(2048) and t.a=t1.b union all select * from t, t t1 where t1.c=space(2048) and t.c=space(2048) and t.a=t1.b union all select * from t, t t1 where t1.c=space(2048) and t.c=space(2048) and t.a=t1.b union all select * from t, t t1 where t1.c=space(2048) and t.c=space(2048) and t.a=t1.b union all select * from t, t t1 where t1.c=space(2048) and t.c=space(2048) and t.a=t1.b'; +execute st; +a b c a b c +execute st; +a b c a b c +select @@last_plan_from_cache; +@@last_plan_from_cache +1 +prepare st from 'select * from t, t t1 where t1.c=space(2048) and t.c=space(2048) and t.a=t1.b union all select * from t, t t1 where t1.c=space(2048) and t.c=space(2048) and t.a=t1.b union all select * from t, t t1 where t1.c=space(2048) and t.c=space(2048) and t.a=t1.b union all select * from t, t t1 where t1.c=space(2048) and t.c=space(2048) and t.a=t1.b union all select * from t, t t1 where t1.c=space(2048) and t.c=space(2048) and t.a=t1.b union all select * from t, t t1 where t1.c=space(2048) and t.c=space(2048) and t.a=t1.b union all select * from t, t t1 where t1.c=space(2048) and t.c=space(2048) and t.a=t1.b union all select * from t, t t1 where t1.c=space(2048) and t.c=space(2048) and t.a=t1.b union all select * from t, t t1 where t1.c=space(2048) and t.c=space(2048) and t.a=t1.b union all select * from t, t t1 where t1.c=space(2048) and t.c=space(2048) and t.a=t1.b union all select * from t, t t1 where t1.c=space(2048) and t.c=space(2048) and t.a=t1.b union all select * from t, t t1 where t1.c=space(2048) and t.c=space(2048) and t.a=t1.b union all select * from t, t t1 where t1.c=space(2048) and t.c=space(2048) and t.a=t1.b union all select * from t, t t1 where t1.c=space(2048) and t.c=space(2048) and t.a=t1.b union all select * from t, t t1 where t1.c=space(2048) and t.c=space(2048) and t.a=t1.b union all select * from t, t t1 where t1.c=space(2048) and t.c=space(2048) and t.a=t1.b union all select * from t, t t1 where t1.c=space(2048) and t.c=space(2048) and t.a=t1.b union all select * from t, t t1 where t1.c=space(2048) and t.c=space(2048) and t.a=t1.b union all select * from t, t t1 where t1.c=space(2048) and t.c=space(2048) and t.a=t1.b union all select * from t, t t1 where t1.c=space(2048) and t.c=space(2048) and t.a=t1.b union all select * from t, t t1 where t1.c=space(2048) and t.c=space(2048) and t.a=t1.b union all select * from t, t t1 where t1.c=space(2048) and t.c=space(2048) and t.a=t1.b union all select * from t, t t1 where t1.c=space(2048) and t.c=space(2048) and t.a=t1.b union all select * from t, t t1 where t1.c=space(2048) and t.c=space(2048) and t.a=t1.b union all select * from t, t t1 where t1.c=space(2048) and t.c=space(2048) and t.a=t1.b union all select * from t, t t1 where t1.c=space(2048) and t.c=space(2048) and t.a=t1.b union all select * from t, t t1 where t1.c=space(2048) and t.c=space(2048) and t.a=t1.b union all select * from t, t t1 where t1.c=space(2048) and t.c=space(2048) and t.a=t1.b union all select * from t, t t1 where t1.c=space(2048) and t.c=space(2048) and t.a=t1.b union all select * from t, t t1 where t1.c=space(2048) and t.c=space(2048) and t.a=t1.b'; +execute st; +a b c a b c +execute st; +a b c a b c +select @@last_plan_from_cache; +@@last_plan_from_cache +0 +set tidb_plan_cache_max_plan_size=1073741824; +execute st; +a b c a b c +execute st; +a b c a b c +select @@last_plan_from_cache; +@@last_plan_from_cache +1 +drop table if exists t; +create table t(a int, b int); +prepare st_199 from 'select * from t where a in (0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,127,128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143,144,145,146,147,148,149,150,151,152,153,154,155,156,157,158,159,160,161,162,163,164,165,166,167,168,169,170,171,172,173,174,175,176,177,178,179,180,181,182,183,184,185,186,187,188,189,190,191,192,193,194,195,196,197,198)'; +execute st_199; +a b +execute st_199; +a b +select @@last_plan_from_cache; +@@last_plan_from_cache +1 +prepare st_201 from 'select * from t where a in (0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,127,128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143,144,145,146,147,148,149,150,151,152,153,154,155,156,157,158,159,160,161,162,163,164,165,166,167,168,169,170,171,172,173,174,175,176,177,178,179,180,181,182,183,184,185,186,187,188,189,190,191,192,193,194,195,196,197,198,199,200)'; +execute st_201; +a b +execute st_201; +a b +select @@last_plan_from_cache; +@@last_plan_from_cache +0 +prepare st_99_100 from 'select * from t where a in (0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98) and b in (0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99)'; +execute st_99_100; +a b +execute st_99_100; +a b +select @@last_plan_from_cache; +@@last_plan_from_cache +1 +prepare st_100_101 from 'select * from t where a in (0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99) and b in (0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100)'; +execute st_100_101; +a b +execute st_100_101; +a b +select @@last_plan_from_cache; +@@last_plan_from_cache +0 +drop table if exists t; +create table t(a int); +insert into t values (2); +prepare st from 'select * from t where a=?'; +set @a=1; +execute st using @a; +a +execute st using @a; +a +select @@last_plan_from_cache; +@@last_plan_from_cache +1 +analyze table t; +set tidb_plan_cache_invalidation_on_fresh_stats = 0; +execute st using @a; +a +select @@last_plan_from_cache; +@@last_plan_from_cache +1 +set tidb_plan_cache_invalidation_on_fresh_stats = 1; +execute st using @a; +a +select @@last_plan_from_cache; +@@last_plan_from_cache +0 +execute st using @a; +a +select @@last_plan_from_cache; +@@last_plan_from_cache +1 +set tidb_plan_cache_invalidation_on_fresh_stats = DEFAULT; +drop table if exists t; +create table t(a int); +insert into t values (2); +set tidb_enable_non_prepared_plan_cache=1; +select * from t where a=1; +a +select * from t where a=1; +a +select @@last_plan_from_cache; +@@last_plan_from_cache +1 +analyze table t; +select * from t where a=1; +a +select @@last_plan_from_cache; +@@last_plan_from_cache +0 +select * from t where a=1; +a +select @@last_plan_from_cache; +@@last_plan_from_cache +1 +set tidb_enable_non_prepared_plan_cache=DEFAULT; +drop table if exists t; +create table t(a int, index(a)); +set tidb_enable_non_prepared_plan_cache=1; +select /*+ use_index(t, a) */ * from t where a=1; +a +select /*+ use_index(t, a) */ * from t where a=1; +a +select @@last_plan_from_cache; +@@last_plan_from_cache +0 +select * from t where a=1; +a +select * from t where a=1; +a +select @@last_plan_from_cache; +@@last_plan_from_cache +1 +set tidb_enable_non_prepared_plan_cache=DEFAULT; +drop table if exists tx; +create table tx(a double, b int); +set tidb_enable_non_prepared_plan_cache=1; +insert into tx values (3.0, 3); +select json_object('k', a) = json_object('k', b) from tx; +json_object('k', a) = json_object('k', b) +1 +select json_object('k', a) = json_object('k', b) from tx; +json_object('k', a) = json_object('k', b) +1 +select @@last_plan_from_cache; +@@last_plan_from_cache +0 +set tidb_enable_non_prepared_plan_cache=DEFAULT; +drop table if exists t; +create table t(a int, index(a)); +set tidb_enable_non_prepared_plan_cache=1; +create binding for select * from t where a=1 using select /*+ use_index(t, a) */ * from t where a=1; +select * from t where a=1; +a +select * from t where a=1; +a +select @@last_plan_from_cache; +@@last_plan_from_cache +0 +drop binding for select * from t where a=1; +select * from t where a=1; +a +select * from t where a=1; +a +select @@last_plan_from_cache; +@@last_plan_from_cache +1 +set tidb_enable_non_prepared_plan_cache=DEFAULT; +drop table if exists t; +create table t (a int primary key, b int, unique key(b)); +set tidb_enable_non_prepared_plan_cache=1; +explain format='brief' select a from t where a in (1, 2); +id estRows task access object operator info +Batch_Point_Get 2.00 root table:t handle:[1 2], keep order:false, desc:false +select a from t where a in (1, 2); +a +select a from t where a in (1, 2); +a +select @@last_plan_from_cache; +@@last_plan_from_cache +0 +explain format='brief' select b from t where b = 1; +id estRows task access object operator info +Point_Get 1.00 root table:t, index:b(b) +select b from t where b = 1; +b +select b from t where b = 1; +b +select @@last_plan_from_cache; +@@last_plan_from_cache +0 +set tidb_enable_non_prepared_plan_cache=DEFAULT; +drop table if exists t; +create table t (a int); +set tidb_enable_non_prepared_plan_cache=1; +select * from t union select * from t; +a +select * from t union select * from t; +a +select @@last_plan_from_cache; +@@last_plan_from_cache +0 +select * from t union distinct select * from t; +a +select * from t union distinct select * from t; +a +select @@last_plan_from_cache; +@@last_plan_from_cache +0 +select * from t union all select * from t; +a +select * from t union all select * from t; +a +select @@last_plan_from_cache; +@@last_plan_from_cache +0 +select * from t except select * from t; +a +select * from t except select * from t; +a +select @@last_plan_from_cache; +@@last_plan_from_cache +0 +select * from t intersect select * from t; +a +select * from t intersect select * from t; +a +select @@last_plan_from_cache; +@@last_plan_from_cache +0 +set tidb_enable_non_prepared_plan_cache=DEFAULT; +drop table if exists t; +create table t (a int); +create definer='root'@'localhost' view t_v as select * from t; +create table t_p (a int) partition by hash(a) partitions 4; +create temporary table t_t (a int); +set tidb_enable_non_prepared_plan_cache=1; +select * from t_v; +a +select * from t_v; +a +select @@last_plan_from_cache; +@@last_plan_from_cache +0 +select * from t_p; +a +select * from t_p; +a +select @@last_plan_from_cache; +@@last_plan_from_cache +0 +select * from t_t; +a +select * from t_t; +a +select @@last_plan_from_cache; +@@last_plan_from_cache +0 +with t_cte as (select * from t) select * from t_cte; +a +with t_cte as (select * from t) select * from t_cte; +a +select @@last_plan_from_cache; +@@last_plan_from_cache +0 +set tidb_enable_non_prepared_plan_cache=DEFAULT; +drop table if exists t; +create table t (a int, key(a)); +set tidb_enable_non_prepared_plan_cache=1; +select * from t where a=1; +a +select * from t where a=1; +a +select @@last_plan_from_cache; +@@last_plan_from_cache +1 +select * from t where a=1.1; +a +select @@last_plan_from_cache; +@@last_plan_from_cache +0 +explain format = 'plan_cache' select * from t where a=1.1; +id estRows task access object operator info +IndexReader_10 8000.00 root index:Selection_9 +└─Selection_9 8000.00 cop[tikv] eq(cast(planner__core__plan_cache.t.a, decimal(10,0) BINARY), 1.1) + └─IndexFullScan_8 10000.00 cop[tikv] table:t, index:a(a) keep order:false, stats:pseudo +Level Code Message +Warning 1105 skip non-prepared plan-cache: '1.1' may be converted to INT +select * from t where a='1'; +a +select @@last_plan_from_cache; +@@last_plan_from_cache +0 +explain format = 'plan_cache' select * from t where a='1'; +id estRows task access object operator info +IndexReader_6 10.00 root index:IndexRangeScan_5 +└─IndexRangeScan_5 10.00 cop[tikv] table:t, index:a(a) range:[1,1], keep order:false, stats:pseudo +Level Code Message +Warning 1105 skip non-prepared plan-cache: '1' may be converted to INT +set tidb_enable_non_prepared_plan_cache=DEFAULT; +drop table if exists t6; +create table t6 (a date, b date, key(a)); +insert into t6 values ('2023-01-21', '2023-01-05'); +set tidb_enable_non_prepared_plan_cache=1; +select * from t6 where a in (2015, '8'); +a b +select * from t6 where a in (2009, '2023-01-21'); +a b +2023-01-21 2023-01-05 +select @@last_plan_from_cache; +@@last_plan_from_cache +1 +set tidb_enable_non_prepared_plan_cache=DEFAULT; +drop table if exists t; +create table t(a int, index(a)); +set tidb_enable_non_prepared_plan_cache=1; +select * from t where a=1; +a +select * from t where a=1; +a +select @@last_plan_from_cache; +@@last_plan_from_cache +1 +set @@session.sql_select_limit=1; +select * from t where a=1; +a +select @@last_plan_from_cache; +@@last_plan_from_cache +0 +set tidb_enable_non_prepared_plan_cache=DEFAULT; +set @@session.sql_select_limit=DEFAULT; +drop table if exists t; +create table t (a year); +insert into t values (2000); +prepare st from 'select * from t where a?'; +set @a=1; +execute st using @a; +a +execute st using @a; +a +select @@last_plan_from_cache; +@@last_plan_from_cache +1 +create binding for select * from t where a>1 using select /*+ ignore_plan_cache() */ * from t where a>1; +execute st using @a; +a +select @@last_plan_from_cache; +@@last_plan_from_cache +0 +execute st using @a; +a +select @@last_plan_from_binding; +@@last_plan_from_binding +1 +CREATE TABLE PK_LP9463 ( +COL1 mediumint NOT NULL DEFAULT '77' COMMENT 'NUMERIC PK', +COL2 varchar(20) COLLATE utf8mb4_bin DEFAULT NULL, +COL4 datetime DEFAULT NULL, +COL3 bigint DEFAULT NULL, +COL5 float DEFAULT NULL, +PRIMARY KEY (COL1)); +INSERT INTO PK_LP9463 VALUES (-7415279,'笚綷想摻癫梒偆荈湩窐曋繾鏫蘌憬稁渣½隨苆','1001-11-02 05:11:33',-3745331437675076296,-3.21618e38), +(-7153863,'鯷氤衡椻闍饑堀鱟垩啵緬氂哨笂序鉲秼摀巽茊','6800-06-20 23:39:12',-7871155140266310321,-3.04829e38), +(77,'娥藨潰眤徕菗柢礥蕶浠嶲憅榩椻鍙鑜堋ᛀ暵氎','4473-09-13 01:18:59',4076508026242316746,-1.9525e38), +(16614,'阖旕雐盬皪豧篣哙舄糗悄蟊鯴瞶珧赺潴嶽簤彉','2745-12-29 00:29:06',-4242415439257105874,2.71063e37); +prepare stmt from 'SELECT *, rank() OVER (PARTITION BY col2 ORDER BY COL1) FROM PK_LP9463 WHERE col1 != ? AND col1 < ?'; +set @a=-8414766051197, @b=-8388608; +execute stmt using @a,@b; +COL1 COL2 COL4 COL3 COL5 rank() OVER (PARTITION BY col2 ORDER BY COL1) +set @a=16614, @b=16614; +execute stmt using @a,@b; +COL1 COL2 COL4 COL3 COL5 rank() OVER (PARTITION BY col2 ORDER BY COL1) +-7153863 鯷氤衡椻闍饑堀鱟垩啵緬氂哨笂序鉲秼摀巽茊 6800-06-20 23:39:12 -7871155140266310321 -3.04829e38 1 +-7415279 笚綷想摻癫梒偆荈湩窐曋繾鏫蘌憬稁渣½隨苆 1001-11-02 05:11:33 -3745331437675076296 -3.21618e38 1 +77 娥藨潰眤徕菗柢礥蕶浠嶲憅榩椻鍙鑜堋ᛀ暵氎 4473-09-13 01:18:59 4076508026242316746 -1.9525e38 1 +select @@last_plan_from_cache; +@@last_plan_from_cache +0 +SELECT *, rank() OVER (PARTITION BY col2 ORDER BY COL1) FROM PK_LP9463 WHERE col1 != 16614 and col1 < 16614; +COL1 COL2 COL4 COL3 COL5 rank() OVER (PARTITION BY col2 ORDER BY COL1) +-7153863 鯷氤衡椻闍饑堀鱟垩啵緬氂哨笂序鉲秼摀巽茊 6800-06-20 23:39:12 -7871155140266310321 -3.04829e38 1 +-7415279 笚綷想摻癫梒偆荈湩窐曋繾鏫蘌憬稁渣½隨苆 1001-11-02 05:11:33 -3745331437675076296 -3.21618e38 1 +77 娥藨潰眤徕菗柢礥蕶浠嶲憅榩椻鍙鑜堋ᛀ暵氎 4473-09-13 01:18:59 4076508026242316746 -1.9525e38 1 +CREATE TABLE PK_SIGNED_10087 ( +COL1 mediumint(8) unsigned NOT NULL, +COL2 varchar(20) DEFAULT NULL, +COL4 datetime DEFAULT NULL, +COL3 bigint(20) DEFAULT NULL, +COL5 float DEFAULT NULL, +PRIMARY KEY (COL1) ); +insert into PK_SIGNED_10087 values(0, "痥腜蟿鮤枓欜喧檕澙姭袐裄钭僇剕焍哓閲疁櫘", "0017-11-14 05:40:55", -4504684261333179273, 7.97449e37); +prepare stmt from 'SELECT/*+ HASH_JOIN(t1, t2) */ t2.* FROM PK_SIGNED_10087 t1 JOIN PK_SIGNED_10087 t2 ON t1.col1 = t2.col1 WHERE t2.col1 >= ? AND t1.col1 >= ?;'; +set @a=0, @b=0; +execute stmt using @a,@b; +COL1 COL2 COL4 COL3 COL5 +0 痥腜蟿鮤枓欜喧檕澙姭袐裄钭僇剕焍哓閲疁櫘 0017-11-14 05:40:55 -4504684261333179273 7.97449e37 +set @a=8950167, @b=16305982; +execute stmt using @a,@b; +COL1 COL2 COL4 COL3 COL5 +select @@last_plan_from_cache; +@@last_plan_from_cache +1 +select @@session.tidb_enable_plan_cache_for_param_limit; +@@session.tidb_enable_plan_cache_for_param_limit +1 +select @@global.tidb_enable_plan_cache_for_param_limit; +@@global.tidb_enable_plan_cache_for_param_limit +1 +set @@session.tidb_enable_plan_cache_for_param_limit = OFF; +select @@session.tidb_enable_plan_cache_for_param_limit; +@@session.tidb_enable_plan_cache_for_param_limit +0 +set @@session.tidb_enable_plan_cache_for_param_limit = 1; +select @@session.tidb_enable_plan_cache_for_param_limit; +@@session.tidb_enable_plan_cache_for_param_limit +1 +set @@global.tidb_enable_plan_cache_for_param_limit = off; +select @@global.tidb_enable_plan_cache_for_param_limit; +@@global.tidb_enable_plan_cache_for_param_limit +0 +set @@global.tidb_enable_plan_cache_for_param_limit = ON; +select @@global.tidb_enable_plan_cache_for_param_limit; +@@global.tidb_enable_plan_cache_for_param_limit +1 +set @@global.tidb_enable_plan_cache_for_param_limit = ''; +Error 1231 (42000): Variable 'tidb_enable_plan_cache_for_param_limit' can't be set to the value of '' +set @@global.tidb_enable_plan_cache_for_param_limit = 11; +Error 1231 (42000): Variable 'tidb_enable_plan_cache_for_param_limit' can't be set to the value of '11' +set @@global.tidb_enable_plan_cache_for_param_limit = enabled; +Error 1231 (42000): Variable 'tidb_enable_plan_cache_for_param_limit' can't be set to the value of 'enabled' +set @@global.tidb_enable_plan_cache_for_param_limit = disabled; +Error 1231 (42000): Variable 'tidb_enable_plan_cache_for_param_limit' can't be set to the value of 'disabled' +set @@global.tidb_enable_plan_cache_for_param_limit = open; +Error 1231 (42000): Variable 'tidb_enable_plan_cache_for_param_limit' can't be set to the value of 'open' +set @@global.tidb_enable_plan_cache_for_param_limit = DEFAULT; +drop table if exists t; +create table t(a int, key(a)); +set @@session.tidb_enable_plan_cache_for_param_limit = OFF; +prepare stmt from 'select * from t limit ?'; +show warnings; +Level Code Message +Warning 1105 skip prepared plan-cache: query has 'limit ?' is un-cacheable +set @a = 1; +execute stmt using @a; +a +execute stmt using @a; +a +select @@last_plan_from_cache; +@@last_plan_from_cache +0 +deallocate prepare stmt; +set @@session.tidb_enable_plan_cache_for_param_limit = ON; +prepare stmt from 'select * from t limit ?'; +set @@session.tidb_enable_plan_cache_for_param_limit = OFF; +set @a = 1; +execute stmt using @a; +a +execute stmt using @a; +a +select @@last_plan_from_cache; +@@last_plan_from_cache +0 +execute stmt using @a; +a +show warnings; +Level Code Message +Warning 1105 skip prepared plan-cache: the switch 'tidb_enable_plan_cache_for_param_limit' is off +deallocate prepare stmt; +set @@session.tidb_enable_plan_cache_for_param_limit = ON; +prepare stmt from 'select * from t limit ?'; +set @a = 1; +execute stmt using @a; +a +execute stmt using @a; +a +select @@last_plan_from_cache; +@@last_plan_from_cache +1 +set @@session.tidb_enable_plan_cache_for_param_limit = OFF; +set @a = 1; +execute stmt using @a; +a +execute stmt using @a; +a +select @@last_plan_from_cache; +@@last_plan_from_cache +0 +deallocate prepare stmt; +drop table if exists t1, t2; +create table t1 (a int); +create table t2 (a int, b int); +prepare st from 'select count(*) from information_schema.COLUMNS where table_name=? and TABLE_SCHEMA = \'planner__core__plan_cache\''; +set @a='t1'; +execute st using @a; +count(*) +1 +set @a='t2'; +execute st using @a; +count(*) +2 +select @@last_plan_from_cache; +@@last_plan_from_cache +0 +select @@session.tidb_enable_plan_cache_for_subquery; +@@session.tidb_enable_plan_cache_for_subquery +1 +select @@global.tidb_enable_plan_cache_for_subquery; +@@global.tidb_enable_plan_cache_for_subquery +1 +set @@session.tidb_enable_plan_cache_for_subquery = OFF; +select @@session.tidb_enable_plan_cache_for_subquery; +@@session.tidb_enable_plan_cache_for_subquery +0 +set @@session.tidb_enable_plan_cache_for_subquery = 1; +select @@session.tidb_enable_plan_cache_for_subquery; +@@session.tidb_enable_plan_cache_for_subquery +1 +set @@global.tidb_enable_plan_cache_for_subquery = off; +select @@global.tidb_enable_plan_cache_for_subquery; +@@global.tidb_enable_plan_cache_for_subquery +0 +set @@global.tidb_enable_plan_cache_for_subquery = ON; +select @@global.tidb_enable_plan_cache_for_subquery; +@@global.tidb_enable_plan_cache_for_subquery +1 +set @@global.tidb_enable_plan_cache_for_subquery = ''; +Error 1231 (42000): Variable 'tidb_enable_plan_cache_for_subquery' can't be set to the value of '' +set @@global.tidb_enable_plan_cache_for_subquery = 11; +Error 1231 (42000): Variable 'tidb_enable_plan_cache_for_subquery' can't be set to the value of '11' +set @@global.tidb_enable_plan_cache_for_subquery = enabled; +Error 1231 (42000): Variable 'tidb_enable_plan_cache_for_subquery' can't be set to the value of 'enabled' +set @@global.tidb_enable_plan_cache_for_subquery = disabled; +Error 1231 (42000): Variable 'tidb_enable_plan_cache_for_subquery' can't be set to the value of 'disabled' +set @@global.tidb_enable_plan_cache_for_subquery = open; +Error 1231 (42000): Variable 'tidb_enable_plan_cache_for_subquery' can't be set to the value of 'open' +set @@global.tidb_enable_plan_cache_for_subquery = DEFAULT; +drop table if exists t, s; +create table t(a int, key(a)); +create table s(a int, key(a)); +set @@session.tidb_enable_plan_cache_for_subquery = OFF; +prepare stmt from 'select * from t where a in (select a from s)'; +Level Code Message +Warning 1105 skip prepared plan-cache: query has sub-queries is un-cacheable +execute stmt; +a +execute stmt; +a +select @@last_plan_from_cache; +@@last_plan_from_cache +0 +deallocate prepare stmt; +set @@session.tidb_enable_plan_cache_for_subquery = ON; +prepare stmt from 'select * from t where a in (select a from s)'; +set @@session.tidb_enable_plan_cache_for_subquery = OFF; +execute stmt; +a +execute stmt; +a +select @@last_plan_from_cache; +@@last_plan_from_cache +0 +execute stmt; +a +Level Code Message +Warning 1105 skip prepared plan-cache: the switch 'tidb_enable_plan_cache_for_subquery' is off +deallocate prepare stmt; +set @@session.tidb_enable_plan_cache_for_subquery = ON; +prepare stmt from 'select * from t where a in (select a from s)'; +execute stmt; +a +execute stmt; +a +select @@last_plan_from_cache; +@@last_plan_from_cache +1 +set @@session.tidb_enable_plan_cache_for_subquery = OFF; +execute stmt; +a +execute stmt; +a +select @@last_plan_from_cache; +@@last_plan_from_cache +0 +deallocate prepare stmt; +set @@session.tidb_enable_plan_cache_for_subquery = DEFAULT; +CREATE TABLE IDT_MULTI15840STROBJSTROBJ ( +COL1 enum('aa', 'zzz') DEFAULT NULL, +COL2 smallint(6) DEFAULT NULL, +COL3 date DEFAULT NULL, +KEY U_M_COL4 (COL1,COL2), +KEY U_M_COL5 (COL3,COL2)); +INSERT INTO IDT_MULTI15840STROBJSTROBJ VALUES ('zzz',1047,'6115-06-05'),('zzz',-23221,'4250-09-03'),('zzz',27138,'1568-07-30'),('zzz',-30903,'6753-08-21'),('zzz',-26875,'6117-10-10'); +prepare stmt from 'select * from IDT_MULTI15840STROBJSTROBJ where col3 <=> ? or col1 in (?, ?, ?) and col2 not between ? and ?'; +set @a="0051-12-23", @b="none", @c="none", @d="none", @e=-32757, @f=-32757; +execute stmt using @a,@b,@c,@d,@e,@f; +COL1 COL2 COL3 +show warnings; +Level Code Message +Warning 1105 skip prepared plan-cache: IndexMerge plan with full-scan is un-cacheable +set @a="9795-01-10", @b="aa", @c="aa", @d="aa", @e=31928, @f=31928; +execute stmt using @a,@b,@c,@d,@e,@f; +COL1 COL2 COL3 +drop table if exists t; +create table t (a int); +set tidb_enable_non_prepared_plan_cache=1; +set tidb_enable_non_prepared_plan_cache_for_dml=0; +insert into t values (1); +insert into t values (1); +select @@last_plan_from_cache; +@@last_plan_from_cache +0 +select a from t where a < 2 for update; +a +1 +1 +select a from t where a < 2 for update; +a +1 +1 +select @@last_plan_from_cache; +@@last_plan_from_cache +0 +set @x:=1; +set @x:=1; +select @@last_plan_from_cache; +@@last_plan_from_cache +0 +set tidb_enable_non_prepared_plan_cache_for_dml=1; +insert into t values (1); +insert into t values (1); +select @@last_plan_from_cache; +@@last_plan_from_cache +1 +select a from t where a < 2 for update; +a +1 +1 +1 +1 +select a from t where a < 2 for update; +a +1 +1 +1 +1 +select @@last_plan_from_cache; +@@last_plan_from_cache +1 +set tidb_enable_non_prepared_plan_cache=DEFAULT; +set tidb_enable_non_prepared_plan_cache_for_dml=DEFAULT; +drop table if exists t; +create table t (a varchar(10), b int); +set tidb_enable_non_prepared_plan_cache=1; +select * from t where a = _utf8'a'; +a b +select * from t where a = _utf8'a'; +a b +select @@last_plan_from_cache; +@@last_plan_from_cache +0 +select * from t where a = _latin1'a'; +a b +select * from t where a = _latin1'a'; +a b +select @@last_plan_from_cache; +@@last_plan_from_cache +0 +select * from t where a = N'a'; +a b +select * from t where a = N'a'; +a b +select @@last_plan_from_cache; +@@last_plan_from_cache +0 +select * from t where a = 'a'; +a b +select * from t where a = 'a'; +a b +select @@last_plan_from_cache; +@@last_plan_from_cache +1 +set tidb_enable_non_prepared_plan_cache=DEFAULT; +drop table if exists t; +create table t(a int, b int, index(a)); +set tidb_enable_non_prepared_plan_cache=1; +select sum(b) from t group by a+1; +sum(b) +select sum(b) from t group by a+1; +sum(b) +select @@last_plan_from_cache; +@@last_plan_from_cache +0 +select sum(b) from t group by a+2; +sum(b) +select @@last_plan_from_cache; +@@last_plan_from_cache +0 +select sum(b) from t group by a+2; +sum(b) +select @@last_plan_from_cache; +@@last_plan_from_cache +0 +set tidb_enable_non_prepared_plan_cache=DEFAULT; +drop table if exists t; +create table t(a int, index(a)); +set tidb_enable_non_prepared_plan_cache=1; +explain format = 'row' select * from t; +id estRows task access object operator info +IndexReader_7 10000.00 root index:IndexFullScan_6 +└─IndexFullScan_6 10000.00 cop[tikv] table:t, index:a(a) keep order:false, stats:pseudo +select @@last_plan_from_cache; +@@last_plan_from_cache +0 +explain format = 'brief' select * from t; +id estRows task access object operator info +IndexReader 10000.00 root index:IndexFullScan +└─IndexFullScan 10000.00 cop[tikv] table:t, index:a(a) keep order:false, stats:pseudo +select @@last_plan_from_cache; +@@last_plan_from_cache +0 +explain format = 'dot' select * from t; +dot contents + +digraph IndexReader_7 { +subgraph cluster7{ +node [style=filled, color=lightgrey] +color=black +label = "root" +"IndexReader_7" +} +subgraph cluster6{ +node [style=filled, color=lightgrey] +color=black +label = "cop" +"IndexFullScan_6" +} +"IndexReader_7" -> "IndexFullScan_6" +} + +select @@last_plan_from_cache; +@@last_plan_from_cache +0 +explain format = 'tidb_json' select * from t; +TiDB_JSON +[ + { + "id": "IndexReader_7", + "estRows": "10000.00", + "taskType": "root", + "operatorInfo": "index:IndexFullScan_6", + "subOperators": [ + { + "id": "IndexFullScan_6", + "estRows": "10000.00", + "taskType": "cop[tikv]", + "accessObject": "table:t, index:a(a)", + "operatorInfo": "keep order:false, stats:pseudo" + } + ] + } +] + +select @@last_plan_from_cache; +@@last_plan_from_cache +0 +explain format = 'verbose' select * from t; +id estRows estCost task access object operator info +IndexReader_7 10000.00 150773.33 root index:IndexFullScan_6 +└─IndexFullScan_6 10000.00 1628000.00 cop[tikv] table:t, index:a(a) keep order:false, stats:pseudo +select @@last_plan_from_cache; +@@last_plan_from_cache +0 +explain format = 'cost_trace' select * from t; +id estRows estCost costFormula task access object operator info +IndexReader_7 10000.00 150773.33 ((scan(10000*logrowsize(16)*tikv_scan_factor(40.7))) + (net(10000*rowsize(16)*tidb_kv_net_factor(3.96))))/15.00 root index:IndexFullScan_6 +└─IndexFullScan_6 10000.00 1628000.00 scan(10000*logrowsize(16)*tikv_scan_factor(40.7)) cop[tikv] table:t, index:a(a) keep order:false, stats:pseudo +select @@last_plan_from_cache; +@@last_plan_from_cache +0 +explain format = 'row' select * from t limit 1; +id estRows task access object operator info +Limit_7 1.00 root offset:0, count:1 +└─IndexReader_12 1.00 root index:Limit_11 + └─Limit_11 1.00 cop[tikv] offset:0, count:1 + └─IndexFullScan_10 1.00 cop[tikv] table:t, index:a(a) keep order:false, stats:pseudo +explain format = 'brief' select * from t limit 1; +id estRows task access object operator info +Limit 1.00 root offset:0, count:1 +└─IndexReader 1.00 root index:Limit + └─Limit 1.00 cop[tikv] offset:0, count:1 + └─IndexFullScan 1.00 cop[tikv] table:t, index:a(a) keep order:false, stats:pseudo +explain format = 'dot' select * from t limit 1; +dot contents + +digraph Limit_7 { +subgraph cluster7{ +node [style=filled, color=lightgrey] +color=black +label = "root" +"Limit_7" -> "IndexReader_12" +} +subgraph cluster11{ +node [style=filled, color=lightgrey] +color=black +label = "cop" +"Limit_11" -> "IndexFullScan_10" +} +"IndexReader_12" -> "Limit_11" +} + +explain format = 'tidb_json' select * from t limit 1; +TiDB_JSON +[ + { + "id": "Limit_7", + "estRows": "1.00", + "taskType": "root", + "operatorInfo": "offset:0, count:1", + "subOperators": [ + { + "id": "IndexReader_12", + "estRows": "1.00", + "taskType": "root", + "operatorInfo": "index:Limit_11", + "subOperators": [ + { + "id": "Limit_11", + "estRows": "1.00", + "taskType": "cop[tikv]", + "operatorInfo": "offset:0, count:1", + "subOperators": [ + { + "id": "IndexFullScan_10", + "estRows": "1.00", + "taskType": "cop[tikv]", + "accessObject": "table:t, index:a(a)", + "operatorInfo": "keep order:false, stats:pseudo" + } + ] + } + ] + } + ] + } +] + +explain format = 'verbose' select * from t limit 1; +id estRows estCost task access object operator info +Limit_7 1.00 12.97 root offset:0, count:1 +└─IndexReader_12 1.00 12.97 root index:Limit_11 + └─Limit_11 1.00 162.80 cop[tikv] offset:0, count:1 + └─IndexFullScan_10 1.00 162.80 cop[tikv] table:t, index:a(a) keep order:false, stats:pseudo +explain format = 'cost_trace' select * from t limit 1; +id estRows estCost costFormula task access object operator info +Limit_7 1.00 12.97 ((((scan(1*logrowsize(16)*tikv_scan_factor(40.7)))) + (net(1*rowsize(8)*tidb_kv_net_factor(3.96))))/15.00) root offset:0, count:1 +└─IndexReader_12 1.00 12.97 (((scan(1*logrowsize(16)*tikv_scan_factor(40.7)))) + (net(1*rowsize(8)*tidb_kv_net_factor(3.96))))/15.00 root index:Limit_11 + └─Limit_11 1.00 162.80 (scan(1*logrowsize(16)*tikv_scan_factor(40.7))) cop[tikv] offset:0, count:1 + └─IndexFullScan_10 1.00 162.80 scan(1*logrowsize(16)*tikv_scan_factor(40.7)) cop[tikv] table:t, index:a(a) keep order:false, stats:pseudo +set tidb_enable_non_prepared_plan_cache=DEFAULT; +drop table if exists t, t1, t2; +CREATE TABLE `t1` (`c_int` int(11) NOT NULL, `c_str` varchar(40) CHARACTER SET utf8 COLLATE utf8_bin DEFAULT NULL, `c_datetime` datetime DEFAULT NULL, `c_timestamp` timestamp NULL DEFAULT NULL, `c_double` double DEFAULT NULL, `c_decimal` decimal(12,6) DEFAULT NULL, `c_enum` enum('blue','green','red','yellow','white','orange','purple') NOT NULL, PRIMARY KEY (`c_int`,`c_enum`) /*T![clustered_index] CLUSTERED */, KEY `c_decimal` (`c_decimal`), UNIQUE KEY `c_datetime` (`c_datetime`), UNIQUE KEY `c_timestamp` (`c_timestamp`)) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin; +CREATE TABLE `t2` (`c_int` int(11) NOT NULL, `c_str` varchar(40) CHARACTER SET utf8 COLLATE utf8_bin DEFAULT NULL, `c_datetime` datetime DEFAULT NULL, `c_timestamp` timestamp NULL DEFAULT NULL, `c_double` double DEFAULT NULL, `c_decimal` decimal(12,6) DEFAULT NULL, `c_enum` enum('blue','green','red','yellow','white','orange','purple') NOT NULL, PRIMARY KEY (`c_int`,`c_enum`) /*T![clustered_index] CLUSTERED */, KEY `c_decimal` (`c_decimal`), UNIQUE KEY `c_datetime` (`c_datetime`), UNIQUE KEY `c_timestamp` (`c_timestamp`)) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin; +create table t (a int, b int, primary key(a), key(b)); +set @v0 = 'nice hellman', @v1 = 'flamboyant booth', @v2 = 'quirky brahmagupta'; +prepare stmt16 from 'select * from t1 where c_enum in (select c_enum from t2 where t1.c_str in (?, ?, ?))'; +execute stmt16 using @v0, @v1, @v2; +c_int c_str c_datetime c_timestamp c_double c_decimal c_enum +execute stmt16 using @v0, @v1, @v2; +c_int c_str c_datetime c_timestamp c_double c_decimal c_enum +select @@last_plan_from_cache; +@@last_plan_from_cache +1 +prepare stmt from 'select c_enum from t1'; +execute stmt; +c_enum +execute stmt; +c_enum +select @@last_plan_from_cache; +@@last_plan_from_cache +1 +prepare st from 'select a from t use index(b)'; +execute st; +a +execute st; +a +select @@last_plan_from_cache; +@@last_plan_from_cache +1 +set tidb_enable_non_prepared_plan_cache=1; +set tidb_enable_non_prepared_plan_cache_for_dml=1; +drop table if exists t; +create table t (a int default 0, b int default 0); +select a from t for update; +a +select a from t for update; +a +select @@last_plan_from_cache; +@@last_plan_from_cache +1 +select a from t where a<10 for update; +a +select a from t where a<10 for update; +a +select @@last_plan_from_cache; +@@last_plan_from_cache +1 +insert into t values (1, 1); +insert into t values (1, 1); +select @@last_plan_from_cache; +@@last_plan_from_cache +1 +insert into t (a, b) values (1, 1); +insert into t (a, b) values (1, 1); +select @@last_plan_from_cache; +@@last_plan_from_cache +1 +insert into t (a) values (1); +insert into t (a) values (1); +select @@last_plan_from_cache; +@@last_plan_from_cache +1 +insert into t (b) values (1); +insert into t (b) values (1); +select @@last_plan_from_cache; +@@last_plan_from_cache +1 +insert into t select * from t; +insert into t select * from t; +select @@last_plan_from_cache; +@@last_plan_from_cache +1 +insert into t select * from t where a>10; +insert into t select * from t where a>10; +select @@last_plan_from_cache; +@@last_plan_from_cache +1 +update t set a=1; +update t set a=1; +select @@last_plan_from_cache; +@@last_plan_from_cache +1 +update t set a=1 where a>10; +update t set a=1 where a>10; +select @@last_plan_from_cache; +@@last_plan_from_cache +1 +update t set a=1, b=1; +update t set a=1, b=1; +select @@last_plan_from_cache; +@@last_plan_from_cache +1 +update t set a=a+1 where a>10; +update t set a=a+1 where a>10; +select @@last_plan_from_cache; +@@last_plan_from_cache +1 +delete from t; +delete from t; +select @@last_plan_from_cache; +@@last_plan_from_cache +1 +delete from t where a>10; +delete from t where a>10; +select @@last_plan_from_cache; +@@last_plan_from_cache +1 +set tidb_enable_non_prepared_plan_cache=DEFAULT; +set tidb_enable_non_prepared_plan_cache_for_dml=DEFAULT; +set tidb_enable_non_prepared_plan_cache=1; +set tidb_enable_non_prepared_plan_cache_for_dml=1; +drop table if exists t; +create table t (a int); +update t set a=1 where a<10; +update t set a=2 where a<12; +select @@last_plan_from_cache; +@@last_plan_from_cache +1 +update t set a=1 where a<10; + update t set a=2 where a<12; +update t set a=1 where a<10; + update t set a=2 where a<12; +select @@last_plan_from_cache; +@@last_plan_from_cache +1 +update t set a=2 where a<12; +select @@last_plan_from_cache; +@@last_plan_from_cache +1 +set tidb_enable_non_prepared_plan_cache=DEFAULT; +set tidb_enable_non_prepared_plan_cache_for_dml=DEFAULT; +set tidb_enable_non_prepared_plan_cache=1; +drop table if exists t1, t2, t3, t4; +create table t1 (a int, b int, c int); +create table t2 (a int, b int, c int); +create table t3 (a int, b int, c int); +create table t4 (a int, x int); +select * from t1, t2 where t1.a=t2.a and t1.b<10; +a b c a b c +select * from t1, t2 where t1.a=t2.a and t1.b<10; +a b c a b c +select @@last_plan_from_cache; +@@last_plan_from_cache +1 +select * from t1, t2; +a b c a b c +select * from t1, t2; +a b c a b c +select @@last_plan_from_cache; +@@last_plan_from_cache +1 +select * from t1, t2 where t1.a10, N'x', N'y')) from t1; +concat(a, if(b>10, N'x', N'y')) +ay +select concat(a, if(b>10, N'x', N'y')) from t1; +concat(a, if(b>10, N'x', N'y')) +ay +select @@last_plan_from_cache; +@@last_plan_from_cache +0 +set tidb_enable_non_prepared_plan_cache=DEFAULT; +set tidb_enable_non_prepared_plan_cache=1; +drop table if exists t1; +CREATE TABLE t1 (c1 INT); +INSERT INTO t1 VALUES (1); +SELECT c1 FROM t1 WHERE TO_BASE64('牵'); +c1 +1 +SELECT c1 FROM t1 WHERE TO_BASE64('牵'); +c1 +1 +select @@last_plan_from_cache; +@@last_plan_from_cache +1 +SELECT c1 FROM t1 WHERE TO_BASE64('哈'); +c1 +1 +select @@last_plan_from_cache; +@@last_plan_from_cache +1 +SELECT c1 FROM t1 WHERE TO_BASE64(''); +c1 +set tidb_enable_non_prepared_plan_cache=DEFAULT; +set tidb_enable_non_prepared_plan_cache=1; +drop table if exists t1; +CREATE TABLE t1(c1 INT); +INSERT INTO t1 VALUES (1); +SELECT c1 FROM t1 WHERE UNHEX(2038330881); +c1 +1 +SELECT c1 FROM t1 WHERE UNHEX(2038330881); +c1 +1 +select @@last_plan_from_cache; +@@last_plan_from_cache +1 +set tidb_enable_non_prepared_plan_cache=DEFAULT; +drop table if exists t; +create table t (a varchar(10), key(a(5))); +prepare st from 'select a from t use index(a) where a=?'; +set @a='a'; +execute st using @a; +a +execute st using @a; +a +Level Code Message +Warning 1105 skip plan-cache: plan rebuild failed, rebuild to get an unsafe range +set @@time_zone='UTC'; +set @@collation_connection='utf8_general_ci'; +prepare s from 'select DATE_FORMAT("2020-01-01","%W") = "wednesday"'; +execute s; +DATE_FORMAT("2020-01-01","%W") = "wednesday" +1 +set @@collation_connection='utf8_bin'; +execute s; +DATE_FORMAT("2020-01-01","%W") = "wednesday" +0 +select @@last_plan_from_cache; +@@last_plan_from_cache +0 +set @@time_zone=DEFAULT; +set @@collation_connection=DEFAULT; +set tidb_enable_non_prepared_plan_cache=1; +drop table if exists t; +create table t (a int, b varchar(32), c datetime, key(a)); +select * from t where mod(a, 5) < 2; +a b c +select * from t where mod(a, 5) < 2; +a b c +select @@last_plan_from_cache; +@@last_plan_from_cache +1 +select * from t where c < now(); +a b c +select * from t where c < now(); +a b c +select @@last_plan_from_cache; +@@last_plan_from_cache +1 +select date_format(c, '%Y-%m-%d') from t where a < 10; +date_format(c, '%Y-%m-%d') +select date_format(c, '%Y-%m-%d') from t where a < 10; +date_format(c, '%Y-%m-%d') +select @@last_plan_from_cache; +@@last_plan_from_cache +1 +select str_to_date(b, '%Y-%m-%d') from t where a < 10; +str_to_date(b, '%Y-%m-%d') +select str_to_date(b, '%Y-%m-%d') from t where a < 10; +str_to_date(b, '%Y-%m-%d') +select @@last_plan_from_cache; +@@last_plan_from_cache +1 +select * from t where a-2 < 20; +a b c +select * from t where a-2 < 20; +a b c +select @@last_plan_from_cache; +@@last_plan_from_cache +1 +select * from t where a+b > 100; +a b c +select * from t where a+b > 100; +a b c +select @@last_plan_from_cache; +@@last_plan_from_cache +1 +select * from t where -a > 10; +a b c +select * from t where -a > 10; +a b c +select @@last_plan_from_cache; +@@last_plan_from_cache +0 +select * from t where a < 1 and b like '%abc%'; +a b c +select * from t where a < 1 and b like '%abc%'; +a b c +select @@last_plan_from_cache; +@@last_plan_from_cache +0 +select database() from t; +database() +select database() from t; +database() +select @@last_plan_from_cache; +@@last_plan_from_cache +0 +set tidb_enable_non_prepared_plan_cache=DEFAULT; diff --git a/tests/integrationtest/t/planner/core/integration_partition.test b/tests/integrationtest/t/planner/core/integration_partition.test index 40d0afa5d403a..bb50b9e206c5b 100644 --- a/tests/integrationtest/t/planner/core/integration_partition.test +++ b/tests/integrationtest/t/planner/core/integration_partition.test @@ -398,6 +398,7 @@ PARTITION BY LIST COLUMNS(col1) ( PARTITION P8 VALUES IN (126,30,48,68) ); insert into PK_LP9326 values(30),(48),(56); +--sorted_result SELECT COL1 FROM PK_LP9326 WHERE COL1 NOT IN (621579514938,-17333745845828,2777039147338); diff --git a/tests/integrationtest/t/planner/core/plan_cache.test b/tests/integrationtest/t/planner/core/plan_cache.test new file mode 100644 index 0000000000000..da527157506f2 --- /dev/null +++ b/tests/integrationtest/t/planner/core/plan_cache.test @@ -0,0 +1,1431 @@ +# TestIssue43311 +drop table if exists t; +create table t (id int, value decimal(7,4), c1 int, c2 int); +insert into t values (1,1.9285,54,28), (1,1.9286,54,28); +set session tidb_enable_non_prepared_plan_cache=0; +select * from t where value = 54 / 28; +set session tidb_enable_non_prepared_plan_cache=1; +select * from t where value = 54 / 28; +select * from t where value = 54 / 28; +prepare st from 'select * from t where value = ? / ?'; +set @a=54, @b=28; +execute st using @a, @b; +execute st using @a, @b; +set session tidb_enable_non_prepared_plan_cache=DEFAULT; + + +# TestIssue44830 +set @@tidb_opt_fix_control = "44830:ON"; +drop table if exists t, t1; +create table t (a int, primary key(a)); +create table t1 (a int, b int, primary key(a, b)); +insert into t values (1), (2), (3); +insert into t1 values (1, 1), (2, 2), (3, 3); +set @a=1, @b=2, @c=3; +prepare st from 'select * from t where 1=1 and a in (?, ?, ?)'; +--sorted_result +execute st using @a, @b, @c; +--sorted_result +execute st using @a, @b, @c; +select @@last_plan_from_cache; +--sorted_result +execute st using @a, @b, @b; +select @@last_plan_from_cache; +--sorted_result +execute st using @b, @b, @b; +select @@last_plan_from_cache; +--sorted_result +execute st using @a, @b, @c; +--sorted_result +execute st using @a, @b, @b; +--sorted_result +execute st using @a, @b, @b; +select @@last_plan_from_cache; +prepare st from 'select * from t1 where 1=1 and (a, b) in ((?, ?), (?, ?), (?, ?))'; +--sorted_result +execute st using @a, @a, @b, @b, @c, @c; +--sorted_result +execute st using @a, @a, @b, @b, @c, @c; +select @@last_plan_from_cache; +--sorted_result +execute st using @a, @a, @b, @b, @b, @b; +select @@last_plan_from_cache; +--sorted_result +execute st using @b, @b, @b, @b, @b, @b; +select @@last_plan_from_cache; +--sorted_result +execute st using @b, @b, @b, @b, @c, @c; +select @@last_plan_from_cache; +--sorted_result +execute st using @a, @a, @a, @a, @a, @a; +--sorted_result +execute st using @a, @a, @a, @a, @a, @a; +select @@last_plan_from_cache; +--sorted_result +execute st using @a, @a, @b, @b, @b, @b; +execute st using @a, @a, @b, @b, @b, @b; +select @@last_plan_from_cache; +set @@tidb_opt_fix_control = DEFAULT; + + +# TestIssue44830NonPrep +set @@tidb_enable_non_prepared_plan_cache=1; +set @@tidb_opt_fix_control = "44830:ON"; +drop table if exists t1; +create table t1 (a int, b int, primary key(a, b)); +insert into t1 values (1, 1), (2, 2), (3, 3); +set @a=1, @b=2, @c=3; +--sorted_result +select * from t1 where 1=1 and (a, b) in ((1, 1), (2, 2), (3, 3)); +--sorted_result +select * from t1 where 1=1 and (a, b) in ((1, 1), (2, 2), (3, 3)); +select @@last_plan_from_cache; +--sorted_result +select * from t1 where 1=1 and (a, b) in ((1, 1), (2, 2), (2, 2)); +select @@last_plan_from_cache; +--sorted_result +select * from t1 where 1=1 and (a, b) in ((2, 2), (2, 2), (2, 2)); +select @@last_plan_from_cache; +--sorted_result +select * from t1 where 1=1 and (a, b) in ((1, 1), (1, 1), (1, 1)); +--sorted_result +select * from t1 where 1=1 and (a, b) in ((1, 1), (1, 1), (1, 1)); +select @@last_plan_from_cache; +set @@tidb_enable_non_prepared_plan_cache=DEFAULT; +set @@tidb_opt_fix_control = DEFAULT; + + +# TestPlanCacheUnsafeRange +drop table if exists t, t1; +create table t (a int unsigned, key(a)); +prepare st from 'select a from t use index(a) where a= 659971401668884663953087553591534913868320924.5040396 and col2 = 869042976700631943559871054704914143535627349.9659934; + + +# TestIssue14875 +drop table if exists t; +create table t(a varchar(8) not null, b varchar(8) not null); +insert into t values('1','1'); +prepare stmt from "select count(1) from t t1, t t2 where t1.a = t2.a and t2.b = '1' and t2.b = ?"; +set @a = '1'; +execute stmt using @a; +set @a = '2'; +execute stmt using @a; +prepare stmt from "select count(1) from t t1, t t2 where t1.a = t2.a and t1.a > ?"; +set @a = '1'; +execute stmt using @a; +set @a = '0'; +execute stmt using @a; + + +# TestIssue14871 +drop table if exists t; +create table t(a varchar(8), b varchar(8)); +insert into t values('1','1'); +prepare stmt from "select count(1) from t t1 left join t t2 on t1.a = t2.a where t2.b = ? and t2.b = ?"; +set @p0 = '1', @p1 = '2'; +execute stmt using @p0, @p1; +set @p0 = '1', @p1 = '1'; +execute stmt using @p0, @p1; + + +# TestNonPreparedPlanCacheDMLHints +drop table if exists t; +create table t (a int); +set @@tidb_enable_non_prepared_plan_cache=1; +set @@tidb_enable_non_prepared_plan_cache_for_dml=1; +insert into t values (1); +insert into t values (1); +select @@last_plan_from_cache; +update t set a=1; +update t set a=1; +select @@last_plan_from_cache; +delete from t where a=1; +delete from t where a=1; +select @@last_plan_from_cache; +insert /*+ ignore_plan_cache() */ into t values (1); +insert /*+ ignore_plan_cache() */ into t values (1); +select @@last_plan_from_cache; +update /*+ ignore_plan_cache() */ t set a=1; +update /*+ ignore_plan_cache() */ t set a=1; +select @@last_plan_from_cache; +delete /*+ ignore_plan_cache() */ from t where a=1; +delete /*+ ignore_plan_cache() */ from t where a=1; +select @@last_plan_from_cache; +insert into t values (1); +select @@last_plan_from_cache; +update t set a=1; +select @@last_plan_from_cache; +delete from t where a=1; +select @@last_plan_from_cache; +set @@tidb_enable_non_prepared_plan_cache=DEFAULT; +set @@tidb_enable_non_prepared_plan_cache_for_dml=DEFAULT; + + +# TestNonPreparedPlanCacheJSONFilter +drop table if exists t; +create table t(a int, b json); +set tidb_enable_non_prepared_plan_cache=1; +select * from t where a<1; +select * from t where a<2; +select @@last_plan_from_cache; +select * from t where b<1; +select * from t where b<2; +select @@last_plan_from_cache; +select b from t where a<1; +select b from t where a<2; +select @@last_plan_from_cache; +set tidb_enable_non_prepared_plan_cache=DEFAULT; + + +# TestNonPreparedPlanCacheEnumFilter +drop table if exists t; +create table t(a int, b enum('1', '2', '3')); +set tidb_enable_non_prepared_plan_cache=1; +select * from t where a<1; +select * from t where a<2; +select @@last_plan_from_cache; +select * from t where b='1'; +select * from t where b='2'; +select @@last_plan_from_cache; +select b from t where a<1; +select b from t where a<2; +select @@last_plan_from_cache; +set tidb_enable_non_prepared_plan_cache=DEFAULT; + + +# TestNonPreparedPlanCacheDateFormat +drop table if exists t1; +set tidb_enable_non_prepared_plan_cache=1; +create table t1 (s1 char(20) character set latin1); +insert into t1 values (date_format('2004-02-02','%M')); +select * from t1; +set tidb_enable_non_prepared_plan_cache=DEFAULT; + + +# TestNonPreparedPlanCacheNullValue +drop table if exists t; +create table t(a int); +set tidb_enable_non_prepared_plan_cache=1; +select * from t where a=1; +select * from t where a=2; +select @@last_plan_from_cache; +select * from t where a=null; +select @@last_plan_from_cache; +select * from t where a=2; +select @@last_plan_from_cache; +set tidb_enable_non_prepared_plan_cache=DEFAULT; + + +# TestNonPreparedPlanCacheInListChange +drop table if exists t; +create table t(a int); +set tidb_enable_non_prepared_plan_cache=1; +select * from t where a in (1, 2, 3); +select * from t where a in (2, 3, 4); +select @@last_plan_from_cache; +select * from t where a in (2, 3, 4, 5); +select @@last_plan_from_cache; +select * from t where a in (1, 2, 3, 4); +select @@last_plan_from_cache; +set tidb_enable_non_prepared_plan_cache=DEFAULT; + + +# TestNonPreparedPlanCacheMemoryTable +set tidb_enable_non_prepared_plan_cache=1; +select data_type from INFORMATION_SCHEMA.columns where table_name = 'v'; +select data_type from INFORMATION_SCHEMA.columns where table_name = 'v'; +select @@last_plan_from_cache; +set tidb_enable_non_prepared_plan_cache=DEFAULT; + + +# TestNonPreparedPlanCacheTooManyConsts +drop table if exists t; +create table t(a int); +set tidb_enable_non_prepared_plan_cache=1; +select * from t where a in (0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198); +select * from t where a in (0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198); +select @@last_plan_from_cache; +select * from t where a in (0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199); +select * from t where a in (0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199); +select @@last_plan_from_cache; +select * from t where a in (0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 200); +select * from t where a in (0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 200); +select @@last_plan_from_cache; +set tidb_enable_non_prepared_plan_cache=DEFAULT; + + +# TestNonPreparedPlanCacheSchemaChange +drop table if exists t; +create table t(a int); +set tidb_enable_non_prepared_plan_cache=1; +select * from t where a=1; +select * from t where a=1; +select @@last_plan_from_cache; +alter table t add index idx_a(a); +select * from t where a=1; +select @@last_plan_from_cache; +select * from t where a=1; +select @@last_plan_from_cache; +set tidb_enable_non_prepared_plan_cache=DEFAULT; + + +# TestNonPreparedCacheWithPreparedCache +drop table if exists t; +create table t(a int); +set tidb_enable_non_prepared_plan_cache=1; +prepare st from 'select * from t where a=1'; +execute st; +execute st; +select @@last_plan_from_cache; +select * from t where a=1; +select @@last_plan_from_cache; +select * from t where a=1; +select @@last_plan_from_cache; +set tidb_enable_non_prepared_plan_cache=DEFAULT; + + +# TestNonPreparedPlanCacheSwitch +drop table if exists t; +create table t(a int); +set tidb_enable_non_prepared_plan_cache=1; +select * from t where a=1; +select * from t where a=1; +select @@last_plan_from_cache; +set tidb_enable_non_prepared_plan_cache=0; +select * from t where a=1; +select @@last_plan_from_cache; +set tidb_enable_non_prepared_plan_cache=DEFAULT; + + +# TestNonPreparedPlanCacheSwitch2 +drop table if exists t; +create table t(a int); +set tidb_enable_non_prepared_plan_cache=0; +set tidb_enable_prepared_plan_cache=0; +select * from t where a<1; +select * from t where a<2; +select @@last_plan_from_cache; +prepare st from 'select * from t where a?'; +set @a=1; +execute st using @a; +execute st using @a; +select @@last_plan_from_cache; +create binding for select * from t where a>1 using select /*+ ignore_plan_cache() */ * from t where a>1; +execute st using @a; +select @@last_plan_from_cache; +execute st using @a; +select @@last_plan_from_binding; + + +# TestIssue38335 +CREATE TABLE PK_LP9463 ( + COL1 mediumint NOT NULL DEFAULT '77' COMMENT 'NUMERIC PK', + COL2 varchar(20) COLLATE utf8mb4_bin DEFAULT NULL, + COL4 datetime DEFAULT NULL, + COL3 bigint DEFAULT NULL, + COL5 float DEFAULT NULL, + PRIMARY KEY (COL1)); + +INSERT INTO PK_LP9463 VALUES (-7415279,'笚綷想摻癫梒偆荈湩窐曋繾鏫蘌憬稁渣½隨苆','1001-11-02 05:11:33',-3745331437675076296,-3.21618e38), +(-7153863,'鯷氤衡椻闍饑堀鱟垩啵緬氂哨笂序鉲秼摀巽茊','6800-06-20 23:39:12',-7871155140266310321,-3.04829e38), +(77,'娥藨潰眤徕菗柢礥蕶浠嶲憅榩椻鍙鑜堋ᛀ暵氎','4473-09-13 01:18:59',4076508026242316746,-1.9525e38), +(16614,'阖旕雐盬皪豧篣哙舄糗悄蟊鯴瞶珧赺潴嶽簤彉','2745-12-29 00:29:06',-4242415439257105874,2.71063e37); +prepare stmt from 'SELECT *, rank() OVER (PARTITION BY col2 ORDER BY COL1) FROM PK_LP9463 WHERE col1 != ? AND col1 < ?'; +set @a=-8414766051197, @b=-8388608; +--sorted_result +execute stmt using @a,@b; +set @a=16614, @b=16614; +--sorted_result +execute stmt using @a,@b; +select @@last_plan_from_cache; +--sorted_result +SELECT *, rank() OVER (PARTITION BY col2 ORDER BY COL1) FROM PK_LP9463 WHERE col1 != 16614 and col1 < 16614; + + +# TestIssue41032 +CREATE TABLE PK_SIGNED_10087 ( + COL1 mediumint(8) unsigned NOT NULL, + COL2 varchar(20) DEFAULT NULL, + COL4 datetime DEFAULT NULL, + COL3 bigint(20) DEFAULT NULL, + COL5 float DEFAULT NULL, + PRIMARY KEY (COL1) ); +insert into PK_SIGNED_10087 values(0, "痥腜蟿鮤枓欜喧檕澙姭袐裄钭僇剕焍哓閲疁櫘", "0017-11-14 05:40:55", -4504684261333179273, 7.97449e37); +prepare stmt from 'SELECT/*+ HASH_JOIN(t1, t2) */ t2.* FROM PK_SIGNED_10087 t1 JOIN PK_SIGNED_10087 t2 ON t1.col1 = t2.col1 WHERE t2.col1 >= ? AND t1.col1 >= ?;'; +set @a=0, @b=0; +--sorted_result +execute stmt using @a,@b; +set @a=8950167, @b=16305982; +execute stmt using @a,@b; +select @@last_plan_from_cache; + + +# TestSetPlanCacheLimitSwitch +select @@session.tidb_enable_plan_cache_for_param_limit; +select @@global.tidb_enable_plan_cache_for_param_limit; +set @@session.tidb_enable_plan_cache_for_param_limit = OFF; +select @@session.tidb_enable_plan_cache_for_param_limit; +set @@session.tidb_enable_plan_cache_for_param_limit = 1; +select @@session.tidb_enable_plan_cache_for_param_limit; +set @@global.tidb_enable_plan_cache_for_param_limit = off; +select @@global.tidb_enable_plan_cache_for_param_limit; +set @@global.tidb_enable_plan_cache_for_param_limit = ON; +select @@global.tidb_enable_plan_cache_for_param_limit; +-- error 1231 +set @@global.tidb_enable_plan_cache_for_param_limit = ''; +-- error 1231 +set @@global.tidb_enable_plan_cache_for_param_limit = 11; +-- error 1231 +set @@global.tidb_enable_plan_cache_for_param_limit = enabled; +-- error 1231 +set @@global.tidb_enable_plan_cache_for_param_limit = disabled; +-- error 1231 +set @@global.tidb_enable_plan_cache_for_param_limit = open; +set @@global.tidb_enable_plan_cache_for_param_limit = DEFAULT; + + +# TestPlanCacheLimitSwitchEffective +drop table if exists t; +create table t(a int, key(a)); +set @@session.tidb_enable_plan_cache_for_param_limit = OFF; +prepare stmt from 'select * from t limit ?'; +show warnings; +set @a = 1; +execute stmt using @a; +execute stmt using @a; +select @@last_plan_from_cache; +deallocate prepare stmt; +set @@session.tidb_enable_plan_cache_for_param_limit = ON; +prepare stmt from 'select * from t limit ?'; +set @@session.tidb_enable_plan_cache_for_param_limit = OFF; +set @a = 1; +execute stmt using @a; +execute stmt using @a; +select @@last_plan_from_cache; +execute stmt using @a; +show warnings; +deallocate prepare stmt; +set @@session.tidb_enable_plan_cache_for_param_limit = ON; +prepare stmt from 'select * from t limit ?'; +set @a = 1; +execute stmt using @a; +execute stmt using @a; +select @@last_plan_from_cache; +set @@session.tidb_enable_plan_cache_for_param_limit = OFF; +set @a = 1; +execute stmt using @a; +execute stmt using @a; +select @@last_plan_from_cache; +deallocate prepare stmt; + + +# TestPlanCacheMemoryTable +drop table if exists t1, t2; +create table t1 (a int); +create table t2 (a int, b int); +prepare st from 'select count(*) from information_schema.COLUMNS where table_name=? and TABLE_SCHEMA = \'planner__core__plan_cache\''; +set @a='t1'; +execute st using @a; +set @a='t2'; +execute st using @a; +select @@last_plan_from_cache; + + +# TestSetPlanCacheSubquerySwitch +select @@session.tidb_enable_plan_cache_for_subquery; +select @@global.tidb_enable_plan_cache_for_subquery; +set @@session.tidb_enable_plan_cache_for_subquery = OFF; +select @@session.tidb_enable_plan_cache_for_subquery; +set @@session.tidb_enable_plan_cache_for_subquery = 1; +select @@session.tidb_enable_plan_cache_for_subquery; +set @@global.tidb_enable_plan_cache_for_subquery = off; +select @@global.tidb_enable_plan_cache_for_subquery; +set @@global.tidb_enable_plan_cache_for_subquery = ON; +select @@global.tidb_enable_plan_cache_for_subquery; +-- error 1231 +set @@global.tidb_enable_plan_cache_for_subquery = ''; +-- error 1231 +set @@global.tidb_enable_plan_cache_for_subquery = 11; +-- error 1231 +set @@global.tidb_enable_plan_cache_for_subquery = enabled; +-- error 1231 +set @@global.tidb_enable_plan_cache_for_subquery = disabled; +-- error 1231 +set @@global.tidb_enable_plan_cache_for_subquery = open; +set @@global.tidb_enable_plan_cache_for_subquery = DEFAULT; + + +# TestPlanCacheSubQuerySwitchEffective +drop table if exists t, s; +create table t(a int, key(a)); +create table s(a int, key(a)); +set @@session.tidb_enable_plan_cache_for_subquery = OFF; +--enable_warnings +prepare stmt from 'select * from t where a in (select a from s)'; +--disable_warnings +execute stmt; +execute stmt; +select @@last_plan_from_cache; +deallocate prepare stmt; +set @@session.tidb_enable_plan_cache_for_subquery = ON; +prepare stmt from 'select * from t where a in (select a from s)'; +set @@session.tidb_enable_plan_cache_for_subquery = OFF; +execute stmt; +execute stmt; +select @@last_plan_from_cache; +--enable_warnings +execute stmt; +--disable_warnings +deallocate prepare stmt; +set @@session.tidb_enable_plan_cache_for_subquery = ON; +prepare stmt from 'select * from t where a in (select a from s)'; +execute stmt; +execute stmt; +select @@last_plan_from_cache; +set @@session.tidb_enable_plan_cache_for_subquery = OFF; +execute stmt; +execute stmt; +select @@last_plan_from_cache; +deallocate prepare stmt; +set @@session.tidb_enable_plan_cache_for_subquery = DEFAULT; + + +# TestIssue41828 +CREATE TABLE IDT_MULTI15840STROBJSTROBJ ( + COL1 enum('aa', 'zzz') DEFAULT NULL, + COL2 smallint(6) DEFAULT NULL, + COL3 date DEFAULT NULL, + KEY U_M_COL4 (COL1,COL2), + KEY U_M_COL5 (COL3,COL2)); +INSERT INTO IDT_MULTI15840STROBJSTROBJ VALUES ('zzz',1047,'6115-06-05'),('zzz',-23221,'4250-09-03'),('zzz',27138,'1568-07-30'),('zzz',-30903,'6753-08-21'),('zzz',-26875,'6117-10-10'); +prepare stmt from 'select * from IDT_MULTI15840STROBJSTROBJ where col3 <=> ? or col1 in (?, ?, ?) and col2 not between ? and ?'; +set @a="0051-12-23", @b="none", @c="none", @d="none", @e=-32757, @f=-32757; +execute stmt using @a,@b,@c,@d,@e,@f; +show warnings; +set @a="9795-01-10", @b="aa", @c="aa", @d="aa", @e=31928, @f=31928; +execute stmt using @a,@b,@c,@d,@e,@f; + + +# TestNonPreparedPlanCacheDMLSwitch +drop table if exists t; +create table t (a int); +set tidb_enable_non_prepared_plan_cache=1; +set tidb_enable_non_prepared_plan_cache_for_dml=0; +insert into t values (1); +insert into t values (1); +select @@last_plan_from_cache; +select a from t where a < 2 for update; +select a from t where a < 2 for update; +select @@last_plan_from_cache; +set @x:=1; +set @x:=1; +select @@last_plan_from_cache; +set tidb_enable_non_prepared_plan_cache_for_dml=1; +insert into t values (1); +insert into t values (1); +select @@last_plan_from_cache; +select a from t where a < 2 for update; +select a from t where a < 2 for update; +select @@last_plan_from_cache; +set tidb_enable_non_prepared_plan_cache=DEFAULT; +set tidb_enable_non_prepared_plan_cache_for_dml=DEFAULT; + + +# TestNonPreparedPlanCacheUnderscoreCharset +drop table if exists t; +create table t (a varchar(10), b int); +set tidb_enable_non_prepared_plan_cache=1; +select * from t where a = _utf8'a'; +select * from t where a = _utf8'a'; +select @@last_plan_from_cache; +select * from t where a = _latin1'a'; +select * from t where a = _latin1'a'; +select @@last_plan_from_cache; +select * from t where a = N'a'; +select * from t where a = N'a'; +select @@last_plan_from_cache; +select * from t where a = 'a'; +select * from t where a = 'a'; +select @@last_plan_from_cache; +set tidb_enable_non_prepared_plan_cache=DEFAULT; + + +# TestNonPreparedPlanCacheGroupBy +drop table if exists t; +create table t(a int, b int, index(a)); +set tidb_enable_non_prepared_plan_cache=1; +select sum(b) from t group by a+1; +select sum(b) from t group by a+1; +select @@last_plan_from_cache; +select sum(b) from t group by a+2; +select @@last_plan_from_cache; +select sum(b) from t group by a+2; +select @@last_plan_from_cache; +set tidb_enable_non_prepared_plan_cache=DEFAULT; + + +# TestNonPreparedPlanCacheExplain +drop table if exists t; +create table t(a int, index(a)); +set tidb_enable_non_prepared_plan_cache=1; +explain format = 'row' select * from t; +select @@last_plan_from_cache; +explain format = 'brief' select * from t; +select @@last_plan_from_cache; +explain format = 'dot' select * from t; +select @@last_plan_from_cache; +explain format = 'tidb_json' select * from t; +select @@last_plan_from_cache; +explain format = 'verbose' select * from t; +select @@last_plan_from_cache; +explain format = 'cost_trace' select * from t; +select @@last_plan_from_cache; +--enable_warnings +explain format = 'row' select * from t limit 1; +explain format = 'brief' select * from t limit 1; +explain format = 'dot' select * from t limit 1; +explain format = 'tidb_json' select * from t limit 1; +explain format = 'verbose' select * from t limit 1; +explain format = 'cost_trace' select * from t limit 1; +--disable_warnings +set tidb_enable_non_prepared_plan_cache=DEFAULT; + + +# TestIssue42150 +drop table if exists t, t1, t2; +CREATE TABLE `t1` (`c_int` int(11) NOT NULL, `c_str` varchar(40) CHARACTER SET utf8 COLLATE utf8_bin DEFAULT NULL, `c_datetime` datetime DEFAULT NULL, `c_timestamp` timestamp NULL DEFAULT NULL, `c_double` double DEFAULT NULL, `c_decimal` decimal(12,6) DEFAULT NULL, `c_enum` enum('blue','green','red','yellow','white','orange','purple') NOT NULL, PRIMARY KEY (`c_int`,`c_enum`) /*T![clustered_index] CLUSTERED */, KEY `c_decimal` (`c_decimal`), UNIQUE KEY `c_datetime` (`c_datetime`), UNIQUE KEY `c_timestamp` (`c_timestamp`)) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin; +CREATE TABLE `t2` (`c_int` int(11) NOT NULL, `c_str` varchar(40) CHARACTER SET utf8 COLLATE utf8_bin DEFAULT NULL, `c_datetime` datetime DEFAULT NULL, `c_timestamp` timestamp NULL DEFAULT NULL, `c_double` double DEFAULT NULL, `c_decimal` decimal(12,6) DEFAULT NULL, `c_enum` enum('blue','green','red','yellow','white','orange','purple') NOT NULL, PRIMARY KEY (`c_int`,`c_enum`) /*T![clustered_index] CLUSTERED */, KEY `c_decimal` (`c_decimal`), UNIQUE KEY `c_datetime` (`c_datetime`), UNIQUE KEY `c_timestamp` (`c_timestamp`)) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin; +create table t (a int, b int, primary key(a), key(b)); +set @v0 = 'nice hellman', @v1 = 'flamboyant booth', @v2 = 'quirky brahmagupta'; +prepare stmt16 from 'select * from t1 where c_enum in (select c_enum from t2 where t1.c_str in (?, ?, ?))'; +execute stmt16 using @v0, @v1, @v2; +execute stmt16 using @v0, @v1, @v2; +select @@last_plan_from_cache; +prepare stmt from 'select c_enum from t1'; +execute stmt; +execute stmt; +select @@last_plan_from_cache; +prepare st from 'select a from t use index(b)'; +execute st; +execute st; +select @@last_plan_from_cache; + + +# TestNonPreparedPlanCacheDML +set tidb_enable_non_prepared_plan_cache=1; +set tidb_enable_non_prepared_plan_cache_for_dml=1; +drop table if exists t; +create table t (a int default 0, b int default 0); +select a from t for update; +select a from t for update; +select @@last_plan_from_cache; +select a from t where a<10 for update; +select a from t where a<10 for update; +select @@last_plan_from_cache; +insert into t values (1, 1); +insert into t values (1, 1); +select @@last_plan_from_cache; +insert into t (a, b) values (1, 1); +insert into t (a, b) values (1, 1); +select @@last_plan_from_cache; +insert into t (a) values (1); +insert into t (a) values (1); +select @@last_plan_from_cache; +insert into t (b) values (1); +insert into t (b) values (1); +select @@last_plan_from_cache; +insert into t select * from t; +insert into t select * from t; +select @@last_plan_from_cache; +insert into t select * from t where a>10; +insert into t select * from t where a>10; +select @@last_plan_from_cache; +update t set a=1; +update t set a=1; +select @@last_plan_from_cache; +update t set a=1 where a>10; +update t set a=1 where a>10; +select @@last_plan_from_cache; +update t set a=1, b=1; +update t set a=1, b=1; +select @@last_plan_from_cache; +update t set a=a+1 where a>10; +update t set a=a+1 where a>10; +select @@last_plan_from_cache; +delete from t; +delete from t; +select @@last_plan_from_cache; +delete from t where a>10; +delete from t where a>10; +select @@last_plan_from_cache; +set tidb_enable_non_prepared_plan_cache=DEFAULT; +set tidb_enable_non_prepared_plan_cache_for_dml=DEFAULT; + + +# TestNonPreparedPlanCacheMultiStmt +set tidb_enable_non_prepared_plan_cache=1; +set tidb_enable_non_prepared_plan_cache_for_dml=1; +drop table if exists t; +create table t (a int); +update t set a=1 where a<10; +update t set a=2 where a<12; +select @@last_plan_from_cache; +update t set a=1 where a<10; update t set a=2 where a<12; +update t set a=1 where a<10; update t set a=2 where a<12; +select @@last_plan_from_cache; +update t set a=2 where a<12; +select @@last_plan_from_cache; +set tidb_enable_non_prepared_plan_cache=DEFAULT; +set tidb_enable_non_prepared_plan_cache_for_dml=DEFAULT; + + +# TestNonPreparedPlanCacheJoin +set tidb_enable_non_prepared_plan_cache=1; +drop table if exists t1, t2, t3, t4; +create table t1 (a int, b int, c int); +create table t2 (a int, b int, c int); +create table t3 (a int, b int, c int); +create table t4 (a int, x int); +select * from t1, t2 where t1.a=t2.a and t1.b<10; +select * from t1, t2 where t1.a=t2.a and t1.b<10; +select @@last_plan_from_cache; +select * from t1, t2; +select * from t1, t2; +select @@last_plan_from_cache; +select * from t1, t2 where t1.a10, N'x', N'y')) from t1; +select concat(a, if(b>10, N'x', N'y')) from t1; +select @@last_plan_from_cache; +set tidb_enable_non_prepared_plan_cache=DEFAULT; + + +# TestIssue45253 +set tidb_enable_non_prepared_plan_cache=1; +drop table if exists t1; +CREATE TABLE t1 (c1 INT); +INSERT INTO t1 VALUES (1); +SELECT c1 FROM t1 WHERE TO_BASE64('牵'); +SELECT c1 FROM t1 WHERE TO_BASE64('牵'); +select @@last_plan_from_cache; +SELECT c1 FROM t1 WHERE TO_BASE64('哈'); +select @@last_plan_from_cache; +SELECT c1 FROM t1 WHERE TO_BASE64(''); +set tidb_enable_non_prepared_plan_cache=DEFAULT; + + +# TestIssue45378 +set tidb_enable_non_prepared_plan_cache=1; +drop table if exists t1; +CREATE TABLE t1(c1 INT); +INSERT INTO t1 VALUES (1); +SELECT c1 FROM t1 WHERE UNHEX(2038330881); +SELECT c1 FROM t1 WHERE UNHEX(2038330881); +select @@last_plan_from_cache; +set tidb_enable_non_prepared_plan_cache=DEFAULT; + + +# TestIssue46159 +drop table if exists t; +create table t (a varchar(10), key(a(5))); +prepare st from 'select a from t use index(a) where a=?'; +set @a='a'; +execute st using @a; +--enable_warnings +execute st using @a; +--disable_warnings + + +# TestIssue47008 +set @@time_zone='UTC'; +set @@collation_connection='utf8_general_ci'; +prepare s from 'select DATE_FORMAT("2020-01-01","%W") = "wednesday"'; +--sorted_result +execute s; +set @@collation_connection='utf8_bin'; +--sorted_result +execute s; +select @@last_plan_from_cache; +set @@time_zone=DEFAULT; +set @@collation_connection=DEFAULT; + + +# TestNonPreparedPlanCacheBuiltinFuncs +set tidb_enable_non_prepared_plan_cache=1; +drop table if exists t; +create table t (a int, b varchar(32), c datetime, key(a)); +select * from t where mod(a, 5) < 2; +select * from t where mod(a, 5) < 2; +select @@last_plan_from_cache; +select * from t where c < now(); +select * from t where c < now(); +select @@last_plan_from_cache; +select date_format(c, '%Y-%m-%d') from t where a < 10; +select date_format(c, '%Y-%m-%d') from t where a < 10; +select @@last_plan_from_cache; +select str_to_date(b, '%Y-%m-%d') from t where a < 10; +select str_to_date(b, '%Y-%m-%d') from t where a < 10; +select @@last_plan_from_cache; +select * from t where a-2 < 20; +select * from t where a-2 < 20; +select @@last_plan_from_cache; +select * from t where a+b > 100; +select * from t where a+b > 100; +select @@last_plan_from_cache; +select * from t where -a > 10; +select * from t where -a > 10; +select @@last_plan_from_cache; +select * from t where a < 1 and b like '%abc%'; +select * from t where a < 1 and b like '%abc%'; +select @@last_plan_from_cache; +select database() from t; +select database() from t; +select @@last_plan_from_cache; +set tidb_enable_non_prepared_plan_cache=DEFAULT; +