Skip to content

Commit

Permalink
planner: udpate cost model ver2 and some related UT (#38833)
Browse files Browse the repository at this point in the history
ref #35240
  • Loading branch information
qw4990 committed Nov 2, 2022
1 parent e6f020a commit 64ca5d4
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 28 deletions.
1 change: 1 addition & 0 deletions planner/core/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4748,6 +4748,7 @@ func TestLimitIndexLookUpKeepOrder(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, index idx(a,b,c));")

Expand Down
30 changes: 15 additions & 15 deletions planner/core/plan_cost_ver2.go
Original file line number Diff line number Diff line change
Expand Up @@ -819,21 +819,21 @@ func (c costVer2Factors) tolist() (l []costVer2Factor) {
}

var defaultVer2Factors = costVer2Factors{
TiDBTemp: costVer2Factor{"tidb_temp_table_factor", 0},
TiKVScan: costVer2Factor{"tikv_scan_factor", 100},
TiKVDescScan: costVer2Factor{"tikv_desc_scan_factor", 150},
TiFlashScan: costVer2Factor{"tiflash_scan_factor", 5},
TiDBCPU: costVer2Factor{"tidb_cpu_factor", 30},
TiKVCPU: costVer2Factor{"tikv_cpu_factor", 30},
TiFlashCPU: costVer2Factor{"tiflash_cpu_factor", 5},
TiDB2KVNet: costVer2Factor{"tidb_kv_net_factor", 8},
TiDB2FlashNet: costVer2Factor{"tidb_flash_net_factor", 4},
TiFlashMPPNet: costVer2Factor{"tiflash_mpp_net_factor", 4},
TiDBMem: costVer2Factor{"tidb_mem_factor", 1},
TiKVMem: costVer2Factor{"tikv_mem_factor", 1},
TiFlashMem: costVer2Factor{"tiflash_mem_factor", 1},
TiDBDisk: costVer2Factor{"tidb_disk_factor", 1000},
TiDBRequest: costVer2Factor{"tidb_request_factor", 9500000},
TiDBTemp: costVer2Factor{"tidb_temp_table_factor", 0.00},
TiKVScan: costVer2Factor{"tikv_scan_factor", 40.70},
TiKVDescScan: costVer2Factor{"tikv_desc_scan_factor", 61.05},
TiFlashScan: costVer2Factor{"tiflash_scan_factor", 11.60},
TiDBCPU: costVer2Factor{"tidb_cpu_factor", 49.90},
TiKVCPU: costVer2Factor{"tikv_cpu_factor", 49.90},
TiFlashCPU: costVer2Factor{"tiflash_cpu_factor", 2.40},
TiDB2KVNet: costVer2Factor{"tidb_kv_net_factor", 3.96},
TiDB2FlashNet: costVer2Factor{"tidb_flash_net_factor", 2.20},
TiFlashMPPNet: costVer2Factor{"tiflash_mpp_net_factor", 1.00},
TiDBMem: costVer2Factor{"tidb_mem_factor", 0.20},
TiKVMem: costVer2Factor{"tikv_mem_factor", 0.20},
TiFlashMem: costVer2Factor{"tiflash_mem_factor", 0.05},
TiDBDisk: costVer2Factor{"tidb_disk_factor", 200.00},
TiDBRequest: costVer2Factor{"tidb_request_factor", 6000000.00},
}

func getTaskCPUFactorVer2(p PhysicalPlan, taskType property.TaskType) costVer2Factor {
Expand Down
6 changes: 3 additions & 3 deletions planner/core/plan_cost_ver2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,9 +145,9 @@ func TestCostModelShowFormula(t *testing.T) {
fmt.Println(actual)
}
require.Equal(t, actual, [][]interface{}{
{"TableReader_7", "((Selection_6) + (net(2*rowsize(16)*tidb_kv_net_factor(8))))/15"},
{"└─Selection_6", "(cpu(3*filters(1)*tikv_cpu_factor(30))) + (TableFullScan_5)"},
{" └─TableFullScan_5", "scan(3*logrowsize(29)*tikv_scan_factor(100))"},
{"TableReader_7", "((Selection_6) + (net(2*rowsize(16)*tidb_kv_net_factor(3.96))))/15"},
{"└─Selection_6", "(cpu(3*filters(1)*tikv_cpu_factor(49.9))) + (TableFullScan_5)"},
{" └─TableFullScan_5", "scan(3*logrowsize(29)*tikv_scan_factor(40.7))"},
})
}

Expand Down
20 changes: 10 additions & 10 deletions planner/core/testdata/integration_suite_out.json
Original file line number Diff line number Diff line change
Expand Up @@ -6268,22 +6268,22 @@
{
"SQL": "desc format = 'brief' select * from t where a = 1 and b > 2 and b < 10 and d = 10 order by b,c limit 10",
"Plan": [
"TopN 0.00 root test.t.b, test.t.c, offset:0, count:10",
"└─IndexLookUp 0.00 root ",
" ├─IndexRangeScan(Build) 2.50 cop[tikv] table:t, index:idx(a, b, c) range:(1 2,1 10), keep order:false, stats:pseudo",
" └─TopN(Probe) 0.00 cop[tikv] test.t.b, test.t.c, offset:0, count:10",
" └─Selection 0.00 cop[tikv] eq(test.t.d, 10)",
"Limit 0.00 root offset:0, count:10",
"└─Projection 0.00 root test.t.a, test.t.b, test.t.c, test.t.d",
" └─IndexLookUp 0.00 root ",
" ├─IndexRangeScan(Build) 2.50 cop[tikv] table:t, index:idx(a, b, c) range:(1 2,1 10), keep order:true, stats:pseudo",
" └─Selection(Probe) 0.00 cop[tikv] eq(test.t.d, 10)",
" └─TableRowIDScan 2.50 cop[tikv] table:t keep order:false, stats:pseudo"
]
},
{
"SQL": "desc format = 'brief' select * from t where a = 1 and b > 2 and b < 10 and d = 10 order by b desc, c desc limit 10",
"Plan": [
"TopN 0.00 root test.t.b:desc, test.t.c:desc, offset:0, count:10",
"└─IndexLookUp 0.00 root ",
" ├─IndexRangeScan(Build) 2.50 cop[tikv] table:t, index:idx(a, b, c) range:(1 2,1 10), keep order:false, stats:pseudo",
" └─TopN(Probe) 0.00 cop[tikv] test.t.b:desc, test.t.c:desc, offset:0, count:10",
" └─Selection 0.00 cop[tikv] eq(test.t.d, 10)",
"Limit 0.00 root offset:0, count:10",
"└─Projection 0.00 root test.t.a, test.t.b, test.t.c, test.t.d",
" └─IndexLookUp 0.00 root ",
" ├─IndexRangeScan(Build) 2.50 cop[tikv] table:t, index:idx(a, b, c) range:(1 2,1 10), keep order:true, desc, stats:pseudo",
" └─Selection(Probe) 0.00 cop[tikv] eq(test.t.d, 10)",
" └─TableRowIDScan 2.50 cop[tikv] table:t keep order:false, stats:pseudo"
]
}
Expand Down

0 comments on commit 64ca5d4

Please sign in to comment.