Skip to content
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

planner: fix unstable test TestDAGPlanBuilderUnionScan (#37895) #38519

Closed
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
1 change: 0 additions & 1 deletion build/nogo_config.json
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,6 @@
"nilness": {
"exclude_files": {
"/external/": "no need to vet third party code",
"planner/core/physical_plan_test.go": "please fix it",
".*_generated\\.go$": "ignore generated code",
"/cgo/": "ignore cgo"
}
Expand Down
27 changes: 14 additions & 13 deletions planner/core/physical_plan_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -363,36 +363,37 @@ func TestDAGPlanBuilderUnion(t *testing.T) {

func TestDAGPlanBuilderUnionScan(t *testing.T) {
store := testkit.CreateMockStore(t)

tk := testkit.NewTestKit(t, store)
tk.MustExec("use test")
tk.MustExec("drop table if exists t")
tk.MustExec("create table t(a int, b int, c int)")

var input []string
var output []struct {
SQL string
Best string
}
planSuiteData := core.GetPlanSuiteData()
planSuiteData.LoadTestCases(t, &input, &output)

p := parser.New()
is := infoschema.MockInfoSchema([]*model.TableInfo{core.MockSignedTable(), core.MockUnsignedTable()})
for i, tt := range input {
tk.MustExec("begin;")
tk.MustExec("insert into t values(2, 2, 2);")

comment := fmt.Sprintf("input: %s", tt)
stmt, err := p.ParseOneStmt(tt, "", "")
require.NoError(t, err, comment)
require.NoError(t, sessiontxn.NewTxn(context.Background(), tk.Session()))

// Make txn not read only.
txn, err := tk.Session().Txn(true)
require.NoError(t, err)
err = txn.Set(kv.Key("AAA"), []byte("BBB"))
require.NoError(t, err)
tk.Session().StmtCommit()
p, _, err := planner.Optimize(context.TODO(), tk.Session(), stmt, is)
dom := domain.GetDomain(tk.Session())
require.NoError(t, dom.Reload())
plan, _, err := planner.Optimize(context.TODO(), tk.Session(), stmt, dom.InfoSchema())
require.NoError(t, err)
testdata.OnRecord(func() {
output[i].SQL = tt
output[i].Best = core.ToString(p)
output[i].Best = core.ToString(plan)
})
require.Equal(t, output[i].Best, core.ToString(p), fmt.Sprintf("input: %s", tt))
require.Equal(t, output[i].Best, core.ToString(plan), fmt.Sprintf("input: %s", tt))
tk.MustExec("rollback;")
}
}

Expand Down
35 changes: 34 additions & 1 deletion planner/core/testdata/plan_suite_out.json
Original file line number Diff line number Diff line change
Expand Up @@ -831,7 +831,40 @@
},
{
"Name": "TestDAGPlanBuilderUnionScan",
"Cases": null
"Cases": [
{
"SQL": "select * from t",
"Best": "TableReader(Table(t))->UnionScan([])->Projection"
},
{
"SQL": "select * from t where b = 1",
"Best": "TableReader(Table(t)->Sel([eq(test.t.b, 1)]))->UnionScan([eq(test.t.b, 1)])->Projection"
},
{
"SQL": "select * from t where a = 1",
"Best": "TableReader(Table(t)->Sel([eq(test.t.a, 1)]))->UnionScan([eq(test.t.a, 1)])->Projection"
},
{
"SQL": "select * from t where a = 1 order by a",
"Best": "TableReader(Table(t)->Sel([eq(test.t.a, 1)]))->UnionScan([eq(test.t.a, 1)])->Projection->Sort"
},
{
"SQL": "select * from t where a = 1 order by b",
"Best": "TableReader(Table(t)->Sel([eq(test.t.a, 1)]))->UnionScan([eq(test.t.a, 1)])->Projection->Sort"
},
{
"SQL": "select * from t where a = 1 limit 1",
"Best": "TableReader(Table(t)->Sel([eq(test.t.a, 1)]))->UnionScan([eq(test.t.a, 1)])->Limit"
},
{
"SQL": "select * from t where c = 1",
"Best": "TableReader(Table(t)->Sel([eq(test.t.c, 1)]))->UnionScan([eq(test.t.c, 1)])->Projection"
},
{
"SQL": "select c from t where c = 1",
"Best": "TableReader(Table(t)->Sel([eq(test.t.c, 1)]))->UnionScan([eq(test.t.c, 1)])->Projection"
}
]
},
{
"Name": "TestDAGPlanBuilderAgg",
Expand Down