-
Notifications
You must be signed in to change notification settings - Fork 5.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
planner: update some UTs from cost model1 to model2 #39065
Changes from 11 commits
2b3a37e
198f94d
a2afbd1
d3a1bfd
11e0f33
871577a
208d4a9
725de71
8f0e0ae
593b955
7fd5e52
1f506c9
404ebb7
5cd3f91
a4e5599
64baf2e
8835e52
517b2fe
cdd04eb
f3e1c73
91f518a
41b5071
90cbff3
60335af
c0a60cc
8a398a4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -980,6 +980,7 @@ func TestSetOperations4PlanCache(t *testing.T) { | |
func TestSPM4PlanCache(t *testing.T) { | ||
store := testkit.CreateMockStore(t) | ||
tk := testkit.NewTestKit(t, store) | ||
tk.MustExec("set tidb_cost_model_version=2") | ||
tk.MustExec(`set tidb_enable_prepared_plan_cache=1`) | ||
|
||
tk.MustExec("use test") | ||
|
@@ -990,8 +991,8 @@ func TestSPM4PlanCache(t *testing.T) { | |
tk.MustExec("admin reload bindings;") | ||
|
||
res := tk.MustQuery("explain format = 'brief' select * from t;") | ||
require.Regexp(t, ".*TableReader.*", res.Rows()[0][0]) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Expected, IndexScan is always better than TableScan. |
||
require.Regexp(t, ".*TableFullScan.*", res.Rows()[1][0]) | ||
require.Regexp(t, ".*IndexReader.*", res.Rows()[0][0]) | ||
require.Regexp(t, ".*IndexFullScan.*", res.Rows()[1][0]) | ||
|
||
tk.MustExec("prepare stmt from 'select * from t;';") | ||
tk.MustQuery("execute stmt;").Check(testkit.Rows()) | ||
|
@@ -1000,8 +1001,8 @@ func TestSPM4PlanCache(t *testing.T) { | |
ps := []*util.ProcessInfo{tkProcess} | ||
tk.Session().SetSessionManager(&testkit.MockSessionManager{PS: ps}) | ||
res = tk.MustQuery("explain for connection " + strconv.FormatUint(tkProcess.ID, 10)) | ||
require.Regexp(t, ".*TableReader.*", res.Rows()[0][0]) | ||
require.Regexp(t, ".*TableFullScan.*", res.Rows()[1][0]) | ||
require.Regexp(t, ".*IndexReader.*", res.Rows()[0][0]) | ||
require.Regexp(t, ".*IndexFullScan.*", res.Rows()[1][0]) | ||
|
||
tk.MustExec("create global binding for select * from t using select * from t use index(idx_a);") | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -910,6 +910,7 @@ func TestGlobalStatsAndSQLBinding(t *testing.T) { | |
tk.MustExec("create database test_global_stats") | ||
tk.MustExec("use test_global_stats") | ||
tk.MustExec("set @@tidb_partition_prune_mode = 'dynamic'") | ||
tk.MustExec("set tidb_cost_model_version=2") | ||
|
||
// hash and range and list partition | ||
tk.MustExec("create table thash(a int, b int, key(a)) partition by hash(a) partitions 4") | ||
|
@@ -953,10 +954,9 @@ func TestGlobalStatsAndSQLBinding(t *testing.T) { | |
tk.MustExec("analyze table trange") | ||
tk.MustExec("analyze table tlist") | ||
|
||
// after analyzing, the planner will use the Index(a) | ||
tk.MustIndexLookup("select * from thash where a<100") | ||
tk.MustIndexLookup("select * from trange where a<100") | ||
tk.MustIndexLookup("select * from tlist where a<1") | ||
require.True(t, tk.HasPlan("select * from thash where a<100", "TableFullScan")) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Expected, model2 prefers to use Scan instead of Lookup to avoid triggering too many double-read requests. |
||
require.True(t, tk.HasPlan("select * from trange where a<100", "TableFullScan")) | ||
require.True(t, tk.HasPlan("select * from tlist where a<1", "TableFullScan")) | ||
|
||
// create SQL bindings | ||
tk.MustExec("create session binding for select * from thash where a<100 using select * from thash ignore index(a) where a<100") | ||
|
@@ -973,10 +973,9 @@ func TestGlobalStatsAndSQLBinding(t *testing.T) { | |
tk.MustExec("drop session binding for select * from trange where a<100") | ||
tk.MustExec("drop session binding for select * from tlist where a<100") | ||
|
||
// use Index(a) again | ||
tk.MustIndexLookup("select * from thash where a<100") | ||
tk.MustIndexLookup("select * from trange where a<100") | ||
tk.MustIndexLookup("select * from tlist where a<1") | ||
require.True(t, tk.HasPlan("select * from thash where a<100", "TableFullScan")) | ||
require.True(t, tk.HasPlan("select * from trange where a<100", "TableFullScan")) | ||
require.True(t, tk.HasPlan("select * from tlist where a<1", "TableFullScan")) | ||
} | ||
|
||
func TestPartitionTableWithDifferentJoin(t *testing.T) { | ||
|
@@ -3435,6 +3434,7 @@ func TestPartitionTableExplain(t *testing.T) { | |
|
||
tk := testkit.NewTestKit(t, store) | ||
tk.MustExec("create database TestPartitionTableExplain") | ||
tk.MustExec("set tidb_cost_model_version=2") | ||
tk.MustExec("use TestPartitionTableExplain") | ||
tk.MustExec("set @@tidb_partition_prune_mode = 'static'") | ||
tk.MustExec(`create table t (a int primary key, b int, key (b)) partition by hash(a) (partition P0, partition p1, partition P2)`) | ||
|
@@ -3571,22 +3571,20 @@ func TestPartitionTableExplain(t *testing.T) { | |
"└─IndexRangeScan 2.00 cop[tikv] table:t, index:b(b) range:[2,2], [3,3], keep order:false")) | ||
tk.MustQuery(`explain format = 'brief' select * from t,t2 where t2.a = 1 and t2.b = t.b`).Check(testkit.Rows( | ||
"Projection 1.00 root testpartitiontableexplain.t.a, testpartitiontableexplain.t.b, testpartitiontableexplain.t2.a, testpartitiontableexplain.t2.b", | ||
"└─IndexJoin 1.00 root inner join, inner:IndexReader, outer key:testpartitiontableexplain.t2.b, inner key:testpartitiontableexplain.t.b, equal cond:eq(testpartitiontableexplain.t2.b, testpartitiontableexplain.t.b)", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Expected, model2 prefers to avoid using double-read IndexJoin. |
||
"└─HashJoin 1.00 root inner join, equal:[eq(testpartitiontableexplain.t2.b, testpartitiontableexplain.t.b)]", | ||
" ├─TableReader(Build) 1.00 root data:Selection", | ||
" │ └─Selection 1.00 cop[tikv] eq(testpartitiontableexplain.t2.a, 1), not(isnull(testpartitiontableexplain.t2.b))", | ||
" │ └─TableFullScan 3.00 cop[tikv] table:t2 keep order:false", | ||
" └─IndexReader(Probe) 1.00 root partition:all index:Selection", | ||
" └─Selection 1.00 cop[tikv] not(isnull(testpartitiontableexplain.t.b))", | ||
" └─IndexRangeScan 1.00 cop[tikv] table:t, index:b(b) range: decided by [eq(testpartitiontableexplain.t.b, testpartitiontableexplain.t2.b)], keep order:false")) | ||
" └─IndexReader(Probe) 3.00 root partition:all index:IndexFullScan", | ||
" └─IndexFullScan 3.00 cop[tikv] table:t, index:b(b) keep order:false")) | ||
tk.MustQuery(`explain format = 'brief' select * from t partition (p1),t2 where t2.a = 1 and t2.b = t.b`).Check(testkit.Rows( | ||
"Projection 1.00 root testpartitiontableexplain.t.a, testpartitiontableexplain.t.b, testpartitiontableexplain.t2.a, testpartitiontableexplain.t2.b", | ||
"└─IndexJoin 1.00 root inner join, inner:IndexReader, outer key:testpartitiontableexplain.t2.b, inner key:testpartitiontableexplain.t.b, equal cond:eq(testpartitiontableexplain.t2.b, testpartitiontableexplain.t.b)", | ||
"└─HashJoin 1.00 root inner join, equal:[eq(testpartitiontableexplain.t2.b, testpartitiontableexplain.t.b)]", | ||
" ├─TableReader(Build) 1.00 root data:Selection", | ||
" │ └─Selection 1.00 cop[tikv] eq(testpartitiontableexplain.t2.a, 1), not(isnull(testpartitiontableexplain.t2.b))", | ||
" │ └─TableFullScan 3.00 cop[tikv] table:t2 keep order:false", | ||
" └─IndexReader(Probe) 1.00 root partition:p1 index:Selection", | ||
" └─Selection 1.00 cop[tikv] not(isnull(testpartitiontableexplain.t.b))", | ||
" └─IndexRangeScan 1.00 cop[tikv] table:t, index:b(b) range: decided by [eq(testpartitiontableexplain.t.b, testpartitiontableexplain.t2.b)], keep order:false")) | ||
" └─IndexReader(Probe) 3.00 root partition:p1 index:IndexFullScan", | ||
" └─IndexFullScan 3.00 cop[tikv] table:t, index:b(b) keep order:false")) | ||
tk.MustQuery(`explain format = 'brief' select * from t,t2 where t2.a = 1 and t2.b = t.b and t.a = 1`).Check(testkit.Rows( | ||
"HashJoin 1.00 root inner join, equal:[eq(testpartitiontableexplain.t.b, testpartitiontableexplain.t2.b)]", | ||
"├─TableReader(Build) 1.00 root data:Selection", | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -68,6 +68,7 @@ func TestHashPartitionPruner(t *testing.T) { | |
func TestRangeColumnPartitionPruningForIn(t *testing.T) { | ||
store := testkit.CreateMockStore(t) | ||
tk := testkit.NewTestKit(t, store) | ||
tk.MustExec("set tidb_cost_model_version=2") | ||
tk.MustExec("drop database if exists test_range_col_in") | ||
tk.MustExec("create database test_range_col_in") | ||
tk.MustExec("use test_range_col_in") | ||
|
@@ -88,16 +89,14 @@ func TestRangeColumnPartitionPruningForIn(t *testing.T) { | |
tk.MustQuery(`explain format='brief' select /*+ HASH_AGG() */ count(1) from t1 where dt in ('2020-11-27','2020-11-28')`).Check( | ||
testkit.Rows("HashAgg 1.00 root funcs:count(Column#5)->Column#4", | ||
"└─PartitionUnion 2.00 root ", | ||
" ├─HashAgg 1.00 root funcs:count(Column#7)->Column#5", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Expected, it will resolved by #38874. |
||
" │ └─IndexReader 1.00 root index:HashAgg", | ||
" │ └─HashAgg 1.00 cop[tikv] funcs:count(1)->Column#7", | ||
" │ └─Selection 20.00 cop[tikv] in(test_range_col_in.t1.dt, 2020-11-27 00:00:00.000000, 2020-11-28 00:00:00.000000)", | ||
" │ └─IndexFullScan 10000.00 cop[tikv] table:t1, partition:p20201127, index:PRIMARY(id, dt) keep order:false, stats:pseudo", | ||
" └─HashAgg 1.00 root funcs:count(Column#10)->Column#5", | ||
" └─IndexReader 1.00 root index:HashAgg", | ||
" └─HashAgg 1.00 cop[tikv] funcs:count(1)->Column#10", | ||
" └─Selection 20.00 cop[tikv] in(test_range_col_in.t1.dt, 2020-11-27 00:00:00.000000, 2020-11-28 00:00:00.000000)", | ||
" └─IndexFullScan 10000.00 cop[tikv] table:t1, partition:p20201128, index:PRIMARY(id, dt) keep order:false, stats:pseudo")) | ||
" ├─HashAgg 1.00 root funcs:count(1)->Column#5", | ||
" │ └─IndexReader 20.00 root index:Selection", | ||
" │ └─Selection 20.00 cop[tikv] in(test_range_col_in.t1.dt, 2020-11-27 00:00:00.000000, 2020-11-28 00:00:00.000000)", | ||
" │ └─IndexFullScan 10000.00 cop[tikv] table:t1, partition:p20201127, index:PRIMARY(id, dt) keep order:false, stats:pseudo", | ||
" └─HashAgg 1.00 root funcs:count(1)->Column#5", | ||
" └─IndexReader 20.00 root index:Selection", | ||
" └─Selection 20.00 cop[tikv] in(test_range_col_in.t1.dt, 2020-11-27 00:00:00.000000, 2020-11-28 00:00:00.000000)", | ||
" └─IndexFullScan 10000.00 cop[tikv] table:t1, partition:p20201128, index:PRIMARY(id, dt) keep order:false, stats:pseudo")) | ||
|
||
tk.MustExec(`insert into t1 values (1, "2020-11-25")`) | ||
tk.MustExec(`insert into t1 values (2, "2020-11-26")`) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Expected, the Agg is not pushed down in model2 since there are only 4 rows.