Skip to content

Commit

Permalink
executor: check schema when build table reader executor (#50425) (#50561
Browse files Browse the repository at this point in the history
)

ref #50358
  • Loading branch information
ti-chi-bot committed Apr 1, 2024
1 parent 6db72f2 commit d33f39f
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
4 changes: 4 additions & 0 deletions executor/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -3466,6 +3466,10 @@ func (b *executorBuilder) buildTableReader(v *plannercore.PhysicalTableReader) E
failpoint.Return(nil)
}
})
// https://github.com/pingcap/tidb/issues/50358
if len(v.Schema().Columns) == 0 && len(v.GetTablePlan().Schema().Columns) > 0 {
v.SetSchema(v.GetTablePlan().Schema())
}
if useMPPExecution(b.ctx, v) {
return b.buildMPPGather(v)
}
Expand Down
29 changes: 29 additions & 0 deletions executor/tiflashtest/tiflash_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1348,3 +1348,32 @@ func TestMPPMemoryTracker(t *testing.T) {
require.NotNil(t, err)
require.True(t, strings.Contains(err.Error(), memory.PanicMemoryExceedWarnMsg+memory.WarnMsgSuffixForSingleQuery))
}

func TestIssue50358(t *testing.T) {
store := testkit.CreateMockStore(t, withMockTiFlash(1))
tk := testkit.NewTestKit(t, store)
tk.MustExec("use test")
tk.MustExec("drop table if exists t")
tk.MustExec("create table t(a int not null primary key, b int not null)")
tk.MustExec("alter table t set tiflash replica 1")
tb := external.GetTableByName(t, tk, "test", "t")
err := domain.GetDomain(tk.Session()).DDL().UpdateTableReplicaInfo(tk.Session(), tb.Meta().ID, true)
require.NoError(t, err)
tk.MustExec("insert into t values(1,0)")
tk.MustExec("insert into t values(2,0)")

tk.MustExec("drop table if exists t1")
tk.MustExec("create table t1(c int not null primary key)")
tk.MustExec("alter table t1 set tiflash replica 1")
tb = external.GetTableByName(t, tk, "test", "t1")
err = domain.GetDomain(tk.Session()).DDL().UpdateTableReplicaInfo(tk.Session(), tb.Meta().ID, true)
require.NoError(t, err)
tk.MustExec("insert into t1 values(3)")

tk.MustExec("set @@session.tidb_isolation_read_engines=\"tiflash\"")
tk.MustExec("set @@session.tidb_allow_mpp=ON")
for i := 0; i < 20; i++ {
// test if it is stable.
tk.MustQuery("select 8 from t join t1").Check(testkit.Rows("8", "8"))
}
}

0 comments on commit d33f39f

Please sign in to comment.