Skip to content

Commit

Permalink
fixup
Browse files Browse the repository at this point in the history
  • Loading branch information
qw4990 committed Jul 15, 2022
1 parent 1bf3b3a commit 46ae8b4
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions planner/core/plan_cost_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package core_test

import (
"fmt"
"strconv"
"strings"
"testing"

Expand Down Expand Up @@ -967,3 +968,39 @@ func TestTrueCardCost(t *testing.T) {
checkPlanCost(`select * from t where a>10 limit 10`)
checkPlanCost(`select sum(a), b*2 from t use index(b) group by b order by sum(a) limit 10`)
}

func TestIssue36243(t *testing.T) {
store, clean := testkit.CreateMockStore(t)
defer clean()
tk := testkit.NewTestKit(t, store)

tk.MustExec("use test")
tk.MustExec(`create table t (a int)`)
tk.MustExec(`insert into mysql.expr_pushdown_blacklist values ('>','tikv','')`)
tk.MustExec(`admin reload expr_pushdown_blacklist`)
tk.MustExec(`set @@tidb_enable_new_cost_interface=1`)

getCost := func() (selCost, readerCost float64) {
res := tk.MustQuery(`explain format=verbose select * from t where a>0`).Rows()
// TableScan -> TableReader -> Selection
require.Equal(t, len(res), 3)
require.Contains(t, res[0][0], "Selection")
require.Contains(t, res[1][0], "TableReader")
require.Contains(t, res[2][0], "Scan")
var err error
selCost, err = strconv.ParseFloat(res[0][2].(string), 64)
require.NoError(t, err)
readerCost, err = strconv.ParseFloat(res[1][2].(string), 64)
require.NoError(t, err)
return
}

tk.MustExec(`set @@tidb_cost_model_version=1`)
// Selection has the same cost with TableReader, ignore Selection cost for compatibility in cost model ver1.
selCost, readerCost := getCost()
require.Equal(t, selCost, readerCost)

tk.MustExec(`set @@tidb_cost_model_version=2`)
selCost, readerCost = getCost()
require.True(t, selCost > readerCost)
}

0 comments on commit 46ae8b4

Please sign in to comment.