Skip to content

executor: ignore ExplainID with cost_trace #61205

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

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions pkg/executor/select.go
Original file line number Diff line number Diff line change
Expand Up @@ -1027,8 +1027,10 @@ func ResetContextOfStmt(ctx sessionctx.Context, s ast.StmtNode) (err error) {
sc.InExplainStmt = true
sc.ExplainFormat = explainStmt.Format
sc.InExplainAnalyzeStmt = explainStmt.Analyze
sc.IgnoreExplainIDSuffix = strings.ToLower(explainStmt.Format) == types.ExplainFormatBrief
sc.InVerboseExplain = strings.ToLower(explainStmt.Format) == types.ExplainFormatVerbose
sc.IgnoreExplainIDSuffix =
strings.EqualFold(explainStmt.Format, types.ExplainFormatBrief) ||
strings.EqualFold(explainStmt.Format, types.ExplainFormatCostTrace)
sc.InVerboseExplain = strings.EqualFold(explainStmt.Format, types.ExplainFormatVerbose)
s = explainStmt.Stmt
} else {
sc.ExplainFormat = ""
Expand Down
2 changes: 1 addition & 1 deletion pkg/planner/core/casetest/tpch/tpch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ func checkCost(t *testing.T, tk *testkit.TestKit, q4 string) {
require.Equal(t, len(costTraceRows.Rows()), len(verboseRows.Rows()))
for i := 0; i < len(costTraceRows.Rows()); i++ {
// check id / estRows / estCost. they should be the same one
require.Equal(t, costTraceRows.Rows()[i][:3], verboseRows.Rows()[i][:3])
require.Equal(t, costTraceRows.Rows()[i][1:3], verboseRows.Rows()[i][1:3])
}
}

Expand Down
4 changes: 2 additions & 2 deletions tests/integrationtest/r/executor/explain.result
Original file line number Diff line number Diff line change
Expand Up @@ -248,8 +248,8 @@ select @@last_plan_from_cache;
0
explain format = 'cost_trace' select * from t;
id estRows estCost costFormula task access object operator info
TableReader_5 10000.00 313573.33 (((((scan(10000*logrowsize(32)*tikv_scan_factor(40.7))) + (scan(10000*logrowsize(32)*tikv_scan_factor(40.7))))*1.00) + (net(10000*rowsize(16)*tidb_kv_net_factor(3.96))))/15.00)*1.00 root data:TableFullScan_4
└─TableFullScan_4 10000.00 4070000.00 ((scan(10000*logrowsize(32)*tikv_scan_factor(40.7))) + (scan(10000*logrowsize(32)*tikv_scan_factor(40.7))))*1.00 cop[tikv] table:t keep order:false, stats:pseudo
TableReader 10000.00 313573.33 (((((scan(10000*logrowsize(32)*tikv_scan_factor(40.7))) + (scan(10000*logrowsize(32)*tikv_scan_factor(40.7))))*1.00) + (net(10000*rowsize(16)*tidb_kv_net_factor(3.96))))/15.00)*1.00 root data:TableFullScan
└─TableFullScan 10000.00 4070000.00 ((scan(10000*logrowsize(32)*tikv_scan_factor(40.7))) + (scan(10000*logrowsize(32)*tikv_scan_factor(40.7))))*1.00 cop[tikv] table:t keep order:false, stats:pseudo
select @@last_plan_from_cache;
@@last_plan_from_cache
0
Expand Down
16 changes: 8 additions & 8 deletions tests/integrationtest/r/planner/core/cbo.result
Original file line number Diff line number Diff line change
Expand Up @@ -43,21 +43,21 @@ insert into t values (1);
set tidb_cost_model_version=2;
explain format='cost_trace' select * from t;
id estRows estCost costFormula task access object operator info
TableReader_5 10000.00 313573.33 (((((scan(10000*logrowsize(32)*tikv_scan_factor(40.7))) + (scan(10000*logrowsize(32)*tikv_scan_factor(40.7))))*1.00) + (net(10000*rowsize(16)*tidb_kv_net_factor(3.96))))/15.00)*1.00 root data:TableFullScan_4
└─TableFullScan_4 10000.00 4070000.00 ((scan(10000*logrowsize(32)*tikv_scan_factor(40.7))) + (scan(10000*logrowsize(32)*tikv_scan_factor(40.7))))*1.00 cop[tikv] table:t keep order:false, stats:pseudo
TableReader 10000.00 313573.33 (((((scan(10000*logrowsize(32)*tikv_scan_factor(40.7))) + (scan(10000*logrowsize(32)*tikv_scan_factor(40.7))))*1.00) + (net(10000*rowsize(16)*tidb_kv_net_factor(3.96))))/15.00)*1.00 root data:TableFullScan
└─TableFullScan 10000.00 4070000.00 ((scan(10000*logrowsize(32)*tikv_scan_factor(40.7))) + (scan(10000*logrowsize(32)*tikv_scan_factor(40.7))))*1.00 cop[tikv] table:t keep order:false, stats:pseudo
explain analyze format='cost_trace' select * from t;
id estRows estCost costFormula actRows task access object execution info operator info memory disk
TableReader_5 10000.00 313573.33 (((((scan(10000*logrowsize(32)*tikv_scan_factor(40.7))) + (scan(10000*logrowsize(32)*tikv_scan_factor(40.7))))*1.00) + (net(10000*rowsize(16)*tidb_kv_net_factor(3.96))))/15.00)*1.00 1 root <execution_info> <operator_info> <memory> <disk>
└─TableFullScan_4 10000.00 4070000.00 ((scan(10000*logrowsize(32)*tikv_scan_factor(40.7))) + (scan(10000*logrowsize(32)*tikv_scan_factor(40.7))))*1.00 1 cop[tikv] table:t <execution_info> <operator_info> <memory> <disk>
TableReader 10000.00 313573.33 (((((scan(10000*logrowsize(32)*tikv_scan_factor(40.7))) + (scan(10000*logrowsize(32)*tikv_scan_factor(40.7))))*1.00) + (net(10000*rowsize(16)*tidb_kv_net_factor(3.96))))/15.00)*1.00 1 root <execution_info> <operator_info> <memory> <disk>
└─TableFullScan 10000.00 4070000.00 ((scan(10000*logrowsize(32)*tikv_scan_factor(40.7))) + (scan(10000*logrowsize(32)*tikv_scan_factor(40.7))))*1.00 1 cop[tikv] table:t <execution_info> <operator_info> <memory> <disk>
set tidb_cost_model_version=1;
explain format='cost_trace' select * from t;
id estRows estCost costFormula task access object operator info
TableReader_5 10000.00 34418.00 N/A root data:TableFullScan_4
└─TableFullScan_4 10000.00 435000.00 N/A cop[tikv] table:t keep order:false, stats:pseudo
TableReader 10000.00 34418.00 N/A root data:TableFullScan
└─TableFullScan 10000.00 435000.00 N/A cop[tikv] table:t keep order:false, stats:pseudo
explain analyze format='cost_trace' select * from t;
id estRows estCost costFormula actRows task access object execution info operator info memory disk
TableReader_5 10000.00 34418.00 N/A 1 root <execution_info> <operator_info> <memory> <disk>
└─TableFullScan_4 10000.00 435000.00 N/A 1 cop[tikv] table:t <execution_info> <operator_info> <memory> <disk>
TableReader 10000.00 34418.00 N/A 1 root <execution_info> <operator_info> <memory> <disk>
└─TableFullScan 10000.00 435000.00 N/A 1 cop[tikv] table:t <execution_info> <operator_info> <memory> <disk>
set tidb_cost_model_version=default;
drop table if exists t1, t2;
set sql_mode='STRICT_TRANS_TABLES';
Expand Down
12 changes: 6 additions & 6 deletions tests/integrationtest/r/planner/core/plan_cache.result
Original file line number Diff line number Diff line change
Expand Up @@ -1636,8 +1636,8 @@ select @@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)))*1.00) + (net(10000*rowsize(16)*tidb_kv_net_factor(3.96))))/15.00)*1.00 root index:IndexFullScan_6
└─IndexFullScan_6 10000.00 1628000.00 (scan(10000*logrowsize(16)*tikv_scan_factor(40.7)))*1.00 cop[tikv] table:t, index:a(a) keep order:false, stats:pseudo
IndexReader 10000.00 150773.33 ((((scan(10000*logrowsize(16)*tikv_scan_factor(40.7)))*1.00) + (net(10000*rowsize(16)*tidb_kv_net_factor(3.96))))/15.00)*1.00 root index:IndexFullScan
└─IndexFullScan 10000.00 1628000.00 (scan(10000*logrowsize(16)*tikv_scan_factor(40.7)))*1.00 cop[tikv] table:t, index:a(a) keep order:false, stats:pseudo
select @@last_plan_from_cache;
@@last_plan_from_cache
0
Expand Down Expand Up @@ -1716,10 +1716,10 @@ Limit_7 1.00 12.97 root 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)))*1.00)) + (net(1*rowsize(8)*tidb_kv_net_factor(3.96))))/15.00)*1.00) root offset:0, count:1
└─IndexReader_12 1.00 12.97 (((((scan(1*logrowsize(16)*tikv_scan_factor(40.7)))*1.00)) + (net(1*rowsize(8)*tidb_kv_net_factor(3.96))))/15.00)*1.00 root index:Limit_11
└─Limit_11 1.00 162.80 ((scan(1*logrowsize(16)*tikv_scan_factor(40.7)))*1.00) cop[tikv] offset:0, count:1
└─IndexFullScan_10 1.00 162.80 (scan(1*logrowsize(16)*tikv_scan_factor(40.7)))*1.00 cop[tikv] table:t, index:a(a) keep order:false, stats:pseudo
Limit 1.00 12.97 ((((((scan(1*logrowsize(16)*tikv_scan_factor(40.7)))*1.00)) + (net(1*rowsize(8)*tidb_kv_net_factor(3.96))))/15.00)*1.00) root offset:0, count:1
└─IndexReader 1.00 12.97 (((((scan(1*logrowsize(16)*tikv_scan_factor(40.7)))*1.00)) + (net(1*rowsize(8)*tidb_kv_net_factor(3.96))))/15.00)*1.00 root index:Limit
└─Limit 1.00 162.80 ((scan(1*logrowsize(16)*tikv_scan_factor(40.7)))*1.00) cop[tikv] offset:0, count:1
└─IndexFullScan 1.00 162.80 (scan(1*logrowsize(16)*tikv_scan_factor(40.7)))*1.00 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;
Expand Down
Loading