Skip to content

Commit

Permalink
planner: update some UTs from cost model1 to model2 (pingcap#39013)
Browse files Browse the repository at this point in the history
  • Loading branch information
qw4990 authored Nov 9, 2022
1 parent 39f35c0 commit 6399e6c
Show file tree
Hide file tree
Showing 20 changed files with 231 additions and 206 deletions.
2 changes: 1 addition & 1 deletion ddl/column_type_change_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1946,7 +1946,7 @@ func TestChangeIntToBitWillPanicInBackfillIndexes(t *testing.T) {
" KEY `idx3` (`a`,`b`),\n" +
" KEY `idx4` (`a`,`b`,`c`)\n" +
") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin"))
tk.MustQuery("select * from t").Check(testkit.Rows("\x13 1 1.00", "\x11 2 2.00"))
tk.MustQuery("select * from t").Sort().Check(testkit.Rows("\x11 2 2.00", "\x13 1 1.00"))
}

// Close issue #24584
Expand Down
4 changes: 2 additions & 2 deletions executor/aggregate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1642,11 +1642,11 @@ func TestIssue26885(t *testing.T) {
tk.MustExec("INSERT INTO t1 (c1) VALUES ('');")
tk.MustExec("INSERT INTO t1 (c1) VALUES (0);")
tk.MustQuery("select * from t1").Check(testkit.Rows("b", "", "a", "", ""))
tk.MustQuery("select c1 + 0 from t1").Check(testkit.Rows("3", "2", "1", "2", "0"))
tk.MustQuery("select c1 + 0 from t1").Sort().Check(testkit.Rows("0", "1", "2", "2", "3"))
tk.MustQuery("SELECT c1 + 0, COUNT(c1) FROM t1 GROUP BY c1 order by c1;").Check(testkit.Rows("0 1", "1 1", "2 2", "3 1"))

tk.MustExec("alter table t1 add index idx(c1); ")
tk.MustQuery("select c1 + 0 from t1").Check(testkit.Rows("3", "2", "1", "2", "0"))
tk.MustQuery("select c1 + 0 from t1").Sort().Check(testkit.Rows("0", "1", "2", "2", "3"))
tk.MustQuery("SELECT c1 + 0, COUNT(c1) FROM t1 GROUP BY c1 order by c1;").Check(testkit.Rows("0 1", "1 1", "2 2", "3 1"))

tk.MustExec(`DROP TABLE IF EXISTS t1;`)
Expand Down
1 change: 1 addition & 0 deletions planner/core/cbo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,7 @@ func TestCorrelatedEstimation(t *testing.T) {
store := testkit.CreateMockStore(t)
tk := testkit.NewTestKit(t, store)
tk.MustExec("use test")
tk.MustExec("set tidb_cost_model_version=2")
tk.MustExec("set sql_mode='STRICT_TRANS_TABLES'") // disable only full group by
tk.MustExec("create table t(a int, b int, c int, index idx(c,b,a))")
tk.MustExec("insert into t values(1,1,1), (2,2,2), (3,3,3), (4,4,4), (5,5,5), (6,6,6), (7,7,7), (8,8,8), (9,9,9),(10,10,10)")
Expand Down
22 changes: 13 additions & 9 deletions planner/core/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1321,6 +1321,7 @@ func TestReadFromStorageHintAndIsolationRead(t *testing.T) {
tk := testkit.NewTestKit(t, store)

tk.MustExec("use test")
tk.MustExec("set tidb_cost_model_version=2")
tk.MustExec("drop table if exists t, tt, ttt")
tk.MustExec("create table t(a int, b int, index ia(a))")
tk.MustExec("set @@session.tidb_isolation_read_engines=\"tikv\"")
Expand Down Expand Up @@ -5698,6 +5699,7 @@ func TestOutputSkylinePruningInfo(t *testing.T) {
store := testkit.CreateMockStore(t)
tk := testkit.NewTestKit(t, store)
tk.MustExec("use test")
tk.MustExec("set tidb_cost_model_version=2")
tk.MustExec("drop table if exists t")
tk.MustExec("create table t(a int, b int, c int, d int, e int, f int, g int, primary key (a), unique key c_d_e (c, d, e), unique key f (f), unique key f_g (f, g), key g (g))")

Expand Down Expand Up @@ -5727,6 +5729,7 @@ func TestPreferRangeScanForUnsignedIntHandle(t *testing.T) {
store := testkit.CreateMockStore(t)
tk := testkit.NewTestKit(t, store)
tk.MustExec("use test")
tk.MustExec("set tidb_cost_model_version=2")
tk.MustExec("drop table if exists t")
tk.MustExec("create table t(a int unsigned primary key, b int, c int, index idx_b(b))")
tk.MustExec("insert into t values (1,2,3), (4,5,6), (7,8,9), (10,11,12), (13,14,15)")
Expand Down Expand Up @@ -7089,6 +7092,7 @@ func TestAggWithJsonPushDownToTiFlash(t *testing.T) {
store := testkit.CreateMockStore(t)
tk := testkit.NewTestKit(t, store)
tk.MustExec("use test")
tk.MustExec("set tidb_cost_model_version=2")
tk.MustExec("drop table if exists t")
tk.MustExec("create table t(a json);")
tk.MustExec("insert into t values(null);")
Expand All @@ -7110,26 +7114,26 @@ func TestAggWithJsonPushDownToTiFlash(t *testing.T) {
}

rows := [][]interface{}{
{"HashAgg_6", "root", "funcs:avg(Column#4)->Column#3"},
{"HashAgg_8", "root", "funcs:avg(Column#4)->Column#3"},
{"└─Projection_19", "root", "cast(test.t.a, double BINARY)->Column#4"},
{" └─TableReader_12", "root", "data:TableFullScan_11"},
{" └─TableFullScan_11", "cop[tiflash]", "keep order:false, stats:pseudo"},
{" └─TableReader_14", "root", "data:TableFullScan_13"},
{" └─TableFullScan_13", "cop[tiflash]", "keep order:false, stats:pseudo"},
}
tk.MustQuery("explain select avg(a) from t;").CheckAt([]int{0, 2, 4}, rows)

rows = [][]interface{}{
{"HashAgg_6", "root", "funcs:sum(Column#4)->Column#3"},
{"HashAgg_8", "root", "funcs:sum(Column#4)->Column#3"},
{"└─Projection_19", "root", "cast(test.t.a, double BINARY)->Column#4"},
{" └─TableReader_12", "root", "data:TableFullScan_11"},
{" └─TableFullScan_11", "cop[tiflash]", "keep order:false, stats:pseudo"},
{" └─TableReader_14", "root", "data:TableFullScan_13"},
{" └─TableFullScan_13", "cop[tiflash]", "keep order:false, stats:pseudo"},
}
tk.MustQuery("explain select sum(a) from t;").CheckAt([]int{0, 2, 4}, rows)

rows = [][]interface{}{
{"HashAgg_6", "root", "funcs:group_concat(Column#4 separator \",\")->Column#3"},
{"HashAgg_8", "root", "funcs:group_concat(Column#4 separator \",\")->Column#3"},
{"└─Projection_13", "root", "cast(test.t.a, var_string(4294967295))->Column#4"},
{" └─TableReader_10", "root", "data:TableFullScan_9"},
{" └─TableFullScan_9", "cop[tiflash]", "keep order:false, stats:pseudo"},
{" └─TableReader_12", "root", "data:TableFullScan_11"},
{" └─TableFullScan_11", "cop[tiflash]", "keep order:false, stats:pseudo"},
}
tk.MustQuery("explain select /*+ hash_agg() */ group_concat(a) from t;").CheckAt([]int{0, 2, 4}, rows)
}
Expand Down
8 changes: 8 additions & 0 deletions planner/core/physical_plan_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,7 @@ func TestDAGPlanBuilderAgg(t *testing.T) {
store := testkit.CreateMockStore(t)
tk := testkit.NewTestKit(t, store)
tk.MustExec("use test")
tk.MustExec("set tidb_cost_model_version=2")
tk.MustExec("set sql_mode='STRICT_TRANS_TABLES'") // disable only full group by
sessionVars := tk.Session().GetSessionVars()
sessionVars.SetHashAggFinalConcurrency(1)
Expand Down Expand Up @@ -443,6 +444,7 @@ func TestRefine(t *testing.T) {

tk := testkit.NewTestKit(t, store)
tk.MustExec("use test")
tk.MustExec("set tidb_cost_model_version=2")

var input []string
var output []struct {
Expand Down Expand Up @@ -1611,6 +1613,7 @@ func TestQueryBlockHint(t *testing.T) {

tk := testkit.NewTestKit(t, store)
tk.MustExec("use test")
tk.MustExec("set tidb_cost_model_version=2")

var input []string
var output []struct {
Expand Down Expand Up @@ -1766,6 +1769,7 @@ func TestIndexJoinHint(t *testing.T) {

tk := testkit.NewTestKit(t, store)
tk.MustExec("use test")
tk.MustExec("set tidb_cost_model_version=2")
tk.MustExec(`drop table if exists test.t1, test.t2, test.t;`)
tk.MustExec(`create table test.t1(a bigint, b bigint, index idx_a(a), index idx_b(b));`)
tk.MustExec(`create table test.t2(a bigint, b bigint, index idx_a(a), index idx_b(b));`)
Expand Down Expand Up @@ -2169,6 +2173,7 @@ func TestHJBuildAndProbeHint(t *testing.T) {
store := testkit.CreateMockStore(t)
tk := testkit.NewTestKit(t, store)
tk.MustExec("use test")
tk.MustExec("set tidb_cost_model_version=2")
tk.MustExec("drop table if exists t1, t2, t3")
tk.MustExec("create table t1(a int primary key, b int not null)")
tk.MustExec("create table t2(a int primary key, b int not null)")
Expand Down Expand Up @@ -2205,6 +2210,7 @@ func TestHJBuildAndProbeHint4StaticPartitionTable(t *testing.T) {
store := testkit.CreateMockStore(t)
tk := testkit.NewTestKit(t, store)
tk.MustExec("use test")
tk.MustExec("set tidb_cost_model_version=2")
tk.MustExec("drop table if exists t1, t2, t3")
tk.MustExec(`create table t1(a int, b int) partition by hash(a) partitions 4`)
tk.MustExec(`create table t2(a int, b int) partition by hash(a) partitions 5`)
Expand Down Expand Up @@ -2279,6 +2285,7 @@ func TestHJBuildAndProbeHint4TiFlash(t *testing.T) {
store := testkit.CreateMockStore(t)
tk := testkit.NewTestKit(t, store)
tk.MustExec("use test")
tk.MustExec("set tidb_cost_model_version=2")
tk.MustExec("drop table if exists t1, t2, t3")
tk.MustExec("create table t1(a int primary key, b int not null)")
tk.MustExec("create table t2(a int primary key, b int not null)")
Expand Down Expand Up @@ -2317,6 +2324,7 @@ func TestHJBuildAndProbeHintWithBinding(t *testing.T) {

tk := testkit.NewTestKit(t, store)
tk.MustExec("use test")
tk.MustExec("set tidb_cost_model_version=2")
tk.MustExec("drop table if exists t, t1, t2, t3;")
tk.MustExec("create table t(a int, b int, key(a));")
tk.MustExec("create table t1(a int, b int, key(a));")
Expand Down
4 changes: 2 additions & 2 deletions planner/core/plan_cost_ver2.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ func (p *PhysicalIndexReader) getPlanCostVer2(taskType property.TaskType, option
}

rows := getCardinality(p.indexPlan, option.CostFlag)
rowSize := getAvgRowSize(p.indexPlan.Stats(), p.indexPlan.Schema().Columns)
rowSize := getAvgRowSize(p.stats, p.schema.Columns)
netFactor := getTaskNetFactorVer2(p, taskType)
concurrency := float64(p.ctx.GetSessionVars().DistSQLScanConcurrency())

Expand All @@ -186,7 +186,7 @@ func (p *PhysicalTableReader) getPlanCostVer2(taskType property.TaskType, option
}

rows := getCardinality(p.tablePlan, option.CostFlag)
rowSize := getAvgRowSize(p.tablePlan.Stats(), p.tablePlan.Schema().Columns)
rowSize := getAvgRowSize(p.stats, p.schema.Columns)
netFactor := getTaskNetFactorVer2(p, taskType)
concurrency := float64(p.ctx.GetSessionVars().DistSQLScanConcurrency())
childType := property.CopSingleReadTaskType
Expand Down
1 change: 1 addition & 0 deletions planner/core/rule_result_reorder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ func TestOrderedResultModeOnOtherOperators(t *testing.T) {

tk := testkit.NewTestKit(t, store)
tk.MustExec("use test")
tk.MustExec("set tidb_cost_model_version=2")
tk.MustExec("set tidb_enable_ordered_result_mode=1")
tk.MustExec("drop table if exists t1")
tk.MustExec("drop table if exists t2")
Expand Down
1 change: 1 addition & 0 deletions planner/core/stats_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ func TestNDVGroupCols(t *testing.T) {
store := testkit.CreateMockStore(t)
tk := testkit.NewTestKit(t, store)
tk.MustExec("use test")
tk.MustExec("set tidb_cost_model_version=2")
tk.MustExec("drop table if exists t1, t2")
tk.MustExec("create table t1(a int not null, b int not null, key(a,b))")
tk.MustExec("insert into t1 values(1,1),(1,2),(2,1),(2,2)")
Expand Down
16 changes: 8 additions & 8 deletions planner/core/testdata/analyze_suite_out.json
Original file line number Diff line number Diff line change
Expand Up @@ -380,22 +380,22 @@
[
"Projection 10.00 root Column#22",
"└─Apply 10.00 root CARTESIAN left outer semi join, other cond:eq(test.t.c, Column#21)",
" ├─TableReader(Build) 10.00 root data:TableFullScan",
" │ └─TableFullScan 10.00 cop[tikv] table:t keep order:false",
" ├─IndexReader(Build) 10.00 root index:IndexFullScan",
" │ └─IndexFullScan 10.00 cop[tikv] table:t, index:idx(c, b, a) keep order:false",
" └─StreamAgg(Probe) 10.00 root funcs:count(1)->Column#21",
" └─HashJoin 10.00 root inner join, equal:[eq(test.t.a, test.t.a)]",
" ├─TableReader(Build) 10.00 root data:Selection",
" ├─IndexReader(Build) 10.00 root index:Selection",
" │ └─Selection 10.00 cop[tikv] eq(test.t.a, test.t.a), not(isnull(test.t.a))",
" │ └─TableFullScan 100.00 cop[tikv] table:t1 keep order:false",
" └─TableReader(Probe) 10.00 root data:Selection",
" │ └─IndexFullScan 100.00 cop[tikv] table:t1, index:idx(c, b, a) keep order:false",
" └─IndexReader(Probe) 10.00 root index:Selection",
" └─Selection 10.00 cop[tikv] eq(test.t.a, test.t.a), not(isnull(test.t.a))",
" └─TableFullScan 100.00 cop[tikv] table:s keep order:false"
" └─IndexFullScan 100.00 cop[tikv] table:s, index:idx(c, b, a) keep order:false"
],
[
"Projection 10.00 root Column#13",
"└─Apply 10.00 root CARTESIAN left outer join",
" ├─TableReader(Build) 10.00 root data:TableFullScan",
" │ └─TableFullScan 10.00 cop[tikv] table:t keep order:false",
" ├─IndexReader(Build) 10.00 root index:IndexFullScan",
" │ └─IndexFullScan 10.00 cop[tikv] table:t, index:idx(c, b, a) keep order:false",
" └─MaxOneRow(Probe) 10.00 root ",
" └─Projection 1.00 root concat(cast(test.t.a, var_string(20)), ,, cast(test.t.b, var_string(20)))->Column#13",
" └─IndexReader 1.00 root index:Selection",
Expand Down
Loading

0 comments on commit 6399e6c

Please sign in to comment.