-
Notifications
You must be signed in to change notification settings - Fork 5.8k
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 all 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 |
---|---|---|
|
@@ -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", | ||
|
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, IndexScan is always better than TableScan.