diff --git a/planner/core/rule_column_pruning.go b/planner/core/rule_column_pruning.go index fcf503e23b2aa..2a0d956d0e441 100644 --- a/planner/core/rule_column_pruning.go +++ b/planner/core/rule_column_pruning.go @@ -87,7 +87,12 @@ func (p *LogicalProjection) PruneColumns(parentUsedCols []*expression.Column, op func (p *LogicalSelection) PruneColumns(parentUsedCols []*expression.Column, opt *logicalOptimizeOp) error { child := p.children[0] parentUsedCols = expression.ExtractColumnsFromExpressions(parentUsedCols, p.Conditions, nil) - return child.PruneColumns(parentUsedCols, opt) + err := child.PruneColumns(parentUsedCols, opt) + if err != nil { + return err + } + addConstOneForEmptyProjection(p.children[0]) + return nil } // PruneColumns implements LogicalPlan interface.