From a8dd684153b17113af6007c285dc595a3fd83b3d Mon Sep 17 00:00:00 2001 From: Ti Chi Robot Date: Thu, 1 Aug 2024 10:26:58 +0800 Subject: [PATCH] planner: return an error when meeting unexpected operator under UnionScan (#53956) (#53971) ref pingcap/tidb#53951 --- pkg/executor/builder.go | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/pkg/executor/builder.go b/pkg/executor/builder.go index ef9810f66aea9..297506380aae0 100644 --- a/pkg/executor/builder.go +++ b/pkg/executor/builder.go @@ -1353,9 +1353,14 @@ func (b *executorBuilder) buildUnionScanFromReader(reader exec.Executor, v *plan us.columns = x.columns us.table = x.table us.virtualColumnIndex = buildVirtualColumnIndex(us.Schema(), us.columns) - default: - // The mem table will not be written by sql directly, so we can omit the union scan to avoid err reporting. + case *PointGetExecutor, *BatchPointGetExec, // PointGet and BatchPoint can handle virtual columns and dirty txn data themselves. + *TableDualExec, // If TableDual, the result must be empty, so we can skip UnionScan and use TableDual directly here. + *TableSampleExecutor: // TableSample only supports sampling from disk, don't need to consider in-memory txn data for simplicity. return originReader + default: + // TODO: consider more operators like Projection. + b.err = errors.NewNoStackErrorf("unexpected operator %T under UnionScan", reader) + return nil } return us } @@ -4080,6 +4085,9 @@ func (builder *dataReaderBuilder) buildUnionScanForIndexJoin(ctx context.Context } ret := builder.buildUnionScanFromReader(reader, v) + if builder.err != nil { + return nil, builder.err + } if us, ok := ret.(*UnionScanExec); ok { err = us.open(ctx) }