diff --git a/executor/builder.go b/executor/builder.go index 83a932d1e1064..ee5705bdd0b36 100644 --- a/executor/builder.go +++ b/executor/builder.go @@ -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) } diff --git a/executor/tiflashtest/tiflash_test.go b/executor/tiflashtest/tiflash_test.go index d52049a0f5b38..e42947f371483 100644 --- a/executor/tiflashtest/tiflash_test.go +++ b/executor/tiflashtest/tiflash_test.go @@ -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")) + } +}