@@ -123,16 +123,22 @@ func (p *LogicalSelection) PredicatePushDown(predicates []expression.Expression,
123
123
124
124
// PredicatePushDown implements LogicalPlan PredicatePushDown interface.
125
125
func (p * LogicalUnionScan ) PredicatePushDown (predicates []expression.Expression , opt * logicalOptimizeOp ) ([]expression.Expression , LogicalPlan ) {
126
- if expression .ContainVirtualColumn (predicates ) {
127
- // predicates with virtual columns can't be pushed down to TiKV/TiFlash so they'll be put into a Projection
128
- // below the UnionScan, but the current UnionScan doesn't support placing Projection below it, see #53951.
129
- return predicates , p
126
+ var predicatesWithVCol , predicatesWithoutVCol []expression.Expression
127
+ // predicates with virtual columns can't be pushed down to TiKV/TiFlash so they'll be put into a Projection
128
+ // below the UnionScan, but the current UnionScan doesn't support placing Projection below it, see #53951.
129
+ for _ , expr := range predicates {
130
+ if expression .ContainVirtualColumn ([]expression.Expression {expr }) {
131
+ predicatesWithVCol = append (predicatesWithVCol , expr )
132
+ } else {
133
+ predicatesWithoutVCol = append (predicatesWithoutVCol , expr )
134
+ }
130
135
}
131
-
136
+ predicates = predicatesWithoutVCol
132
137
retainedPredicates , _ := p .children [0 ].PredicatePushDown (predicates , opt )
133
138
p .conditions = make ([]expression.Expression , 0 , len (predicates ))
134
139
p .conditions = append (p .conditions , predicates ... )
135
140
// The conditions in UnionScan is only used for added rows, so parent Selection should not be removed.
141
+ retainedPredicates = append (retainedPredicates , predicatesWithVCol ... )
136
142
return retainedPredicates , p
137
143
}
138
144
0 commit comments