@@ -19,6 +19,7 @@ import (
19
19
20
20
"github.com/pingcap/tidb/pkg/testkit"
21
21
"github.com/pingcap/tidb/pkg/testkit/testdata"
22
+ "github.com/stretchr/testify/require"
22
23
)
23
24
24
25
func TestQ1 (t * testing.T ) {
@@ -186,7 +187,8 @@ CREATE TABLE lineitem (
186
187
testkit .LoadTableStats ("orders_stats.json" , dom )
187
188
testkit .SetTiFlashReplica (t , dom , "olap" , "orders" )
188
189
testkit .SetTiFlashReplica (t , dom , "olap" , "lineitem" )
189
- q4 := `explain format='brief' select
190
+ briefFormat := `explain format='brief' `
191
+ q4 := `select
190
192
o_orderpriority,
191
193
count(*) as order_count
192
194
from
@@ -203,7 +205,7 @@ where
203
205
and l_commitdate < l_receiptdate )
204
206
group by o_orderpriority
205
207
order by o_orderpriority`
206
- tk .MustQuery (q4 ).Check (testkit .Rows (
208
+ tk .MustQuery (briefFormat + q4 ).Check (testkit .Rows (
207
209
"Sort 1.00 root olap.orders.o_orderpriority" ,
208
210
"└─Projection 1.00 root olap.orders.o_orderpriority, Column#26" ,
209
211
" └─HashAgg 1.00 root group by:olap.orders.o_orderpriority, funcs:count(1)->Column#26, funcs:firstrow(olap.orders.o_orderpriority)->olap.orders.o_orderpriority" ,
@@ -215,9 +217,10 @@ order by o_orderpriority`
215
217
" └─Selection 45161741.07 cop[tikv] lt(olap.lineitem.l_commitdate, olap.lineitem.l_receiptdate)" ,
216
218
" └─TableRangeScan 56452176.33 cop[tikv] table:lineitem range: decided by [eq(olap.lineitem.l_orderkey, olap.orders.o_orderkey)], keep order:false" ,
217
219
))
220
+ checkCost (t , tk , q4 )
218
221
// https://github.com/pingcap/tidb/issues/60991
219
222
tk .MustExec (`set @@session.tidb_enforce_mpp=1;` )
220
- tk .MustQuery (q4 ).Check (testkit .Rows ("Sort 1.00 root olap.orders.o_orderpriority" ,
223
+ tk .MustQuery (briefFormat + q4 ).Check (testkit .Rows ("Sort 1.00 root olap.orders.o_orderpriority" ,
221
224
"└─TableReader 1.00 root MppVersion: 3, data:ExchangeSender" ,
222
225
" └─ExchangeSender 1.00 mpp[tiflash] ExchangeType: PassThrough" ,
223
226
" └─Projection 1.00 mpp[tiflash] olap.orders.o_orderpriority, Column#26" ,
@@ -236,6 +239,21 @@ order by o_orderpriority`
236
239
" └─Projection 4799991767.20 mpp[tiflash] olap.lineitem.l_orderkey" ,
237
240
" └─Selection 4799991767.20 mpp[tiflash] lt(olap.lineitem.l_commitdate, olap.lineitem.l_receiptdate)" ,
238
241
" └─TableFullScan 5999989709.00 mpp[tiflash] table:lineitem pushed down filter:empty, keep order:false" ))
242
+ checkCost (t , tk , q4 )
243
+ }
244
+
245
+ // check the cost trace's cost and verbose's cost. they should be the same.
246
+ // it is from https://github.com/pingcap/tidb/issues/61155
247
+ func checkCost (t * testing.T , tk * testkit.TestKit , q4 string ) {
248
+ costTraceFormat := `explain format='cost_trace' `
249
+ verboseFormat := `explain format='verbose' `
250
+ costTraceRows := tk .MustQuery (costTraceFormat + q4 )
251
+ verboseRows := tk .MustQuery (verboseFormat + q4 )
252
+ require .Equal (t , len (costTraceRows .Rows ()), len (verboseRows .Rows ()))
253
+ for i := 0 ; i < len (costTraceRows .Rows ()); i ++ {
254
+ // check id / estRows / estCost. they should be the same one
255
+ require .Equal (t , costTraceRows .Rows ()[i ][:3 ], verboseRows .Rows ()[i ][:3 ])
256
+ }
239
257
}
240
258
241
259
func TestQ9 (t * testing.T ) {
0 commit comments