Skip to content

Commit e146eda

Browse files
authored
executor: fill correlated column value in late materialization filter conditions (#49244) (#49431)
close #49241
1 parent e091ee5 commit e146eda

File tree

6 files changed

+25
-18
lines changed

6 files changed

+25
-18
lines changed

executor/builder.go

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3103,13 +3103,18 @@ func constructDAGReq(ctx sessionctx.Context, plans []plannercore.PhysicalPlan, s
31033103

31043104
func (b *executorBuilder) corColInDistPlan(plans []plannercore.PhysicalPlan) bool {
31053105
for _, p := range plans {
3106-
x, ok := p.(*plannercore.PhysicalSelection)
3107-
if !ok {
3108-
continue
3109-
}
3110-
for _, cond := range x.Conditions {
3111-
if len(expression.ExtractCorColumns(cond)) > 0 {
3112-
return true
3106+
switch x := p.(type) {
3107+
case *plannercore.PhysicalSelection:
3108+
for _, cond := range x.Conditions {
3109+
if len(expression.ExtractCorColumns(cond)) > 0 {
3110+
return true
3111+
}
3112+
}
3113+
case *plannercore.PhysicalTableScan:
3114+
for _, cond := range x.LateMaterializationFilterCondition {
3115+
if len(expression.ExtractCorColumns(cond)) > 0 {
3116+
return true
3117+
}
31133118
}
31143119
}
31153120
}

executor/table_reader.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,8 @@ type TableReaderExecutor struct {
110110
byItems []*util.ByItems
111111
paging bool
112112
storeType kv.StoreType
113-
// corColInFilter tells whether there's correlated column in filter.
113+
// corColInFilter tells whether there's correlated column in filter (both conditions in PhysicalSelection and LateMaterializationFilterCondition in PhysicalTableScan)
114+
// If true, we will need to revise the dagPB (fill correlated column value in filter) each time call Open().
114115
corColInFilter bool
115116
// corColInAccess tells whether there's correlated column in access conditions.
116117
corColInAccess bool
@@ -154,6 +155,7 @@ func (e *TableReaderExecutor) Open(ctx context.Context) error {
154155

155156
var err error
156157
if e.corColInFilter {
158+
// If there's correlated column in filter, need to rewrite dagPB
157159
if e.storeType == kv.TiFlash {
158160
execs, err := constructDistExecForTiFlash(e.ctx, e.tablePlan)
159161
if err != nil {

planner/core/explain.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -216,11 +216,11 @@ func (p *PhysicalTableScan) OperatorInfo(normalized bool) string {
216216
}
217217
if p.ctx.GetSessionVars().EnableLateMaterialization && len(p.filterCondition) > 0 && p.StoreType == kv.TiFlash {
218218
buffer.WriteString("pushed down filter:")
219-
if len(p.lateMaterializationFilterCondition) > 0 {
219+
if len(p.LateMaterializationFilterCondition) > 0 {
220220
if normalized {
221-
buffer.Write(expression.SortedExplainNormalizedExpressionList(p.lateMaterializationFilterCondition))
221+
buffer.Write(expression.SortedExplainNormalizedExpressionList(p.LateMaterializationFilterCondition))
222222
} else {
223-
buffer.Write(expression.SortedExplainExpressionList(p.lateMaterializationFilterCondition))
223+
buffer.Write(expression.SortedExplainExpressionList(p.LateMaterializationFilterCondition))
224224
}
225225
} else {
226226
buffer.WriteString("empty")

planner/core/physical_plans.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -808,10 +808,10 @@ type PhysicalTableScan struct {
808808
// AccessCondition is used to calculate range.
809809
AccessCondition []expression.Expression
810810
filterCondition []expression.Expression
811-
// lateMaterializationFilterCondition is used to record the filter conditions
811+
// LateMaterializationFilterCondition is used to record the filter conditions
812812
// that are pushed down to table scan from selection by late materialization.
813813
// TODO: remove this field after we support pushing down selection to coprocessor.
814-
lateMaterializationFilterCondition []expression.Expression
814+
LateMaterializationFilterCondition []expression.Expression
815815

816816
Table *model.TableInfo
817817
Columns []*model.ColumnInfo

planner/core/plan_to_pb.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -228,10 +228,10 @@ func (p *PhysicalTableScan) ToPB(ctx sessionctx.Context, storeType kv.StoreType)
228228
tsExec.KeepOrder = &keepOrder
229229
tsExec.IsFastScan = &(ctx.GetSessionVars().TiFlashFastScan)
230230

231-
if len(p.lateMaterializationFilterCondition) > 0 {
231+
if len(p.LateMaterializationFilterCondition) > 0 {
232232
sc := ctx.GetSessionVars().StmtCtx
233233
client := ctx.GetClient()
234-
conditions, err := expression.ExpressionsToPBList(sc, p.lateMaterializationFilterCondition, client)
234+
conditions, err := expression.ExpressionsToPBList(sc, p.LateMaterializationFilterCondition, client)
235235
if err != nil {
236236
return nil, err
237237
}
@@ -261,10 +261,10 @@ func (p *PhysicalTableScan) partitionTableScanToPBForFlash(ctx sessionctx.Contex
261261
telemetry.CurrentTiflashTableScanWithFastScanCount.Inc()
262262
}
263263

264-
if len(p.lateMaterializationFilterCondition) > 0 {
264+
if len(p.LateMaterializationFilterCondition) > 0 {
265265
sc := ctx.GetSessionVars().StmtCtx
266266
client := ctx.GetClient()
267-
conditions, err := expression.ExpressionsToPBList(sc, p.lateMaterializationFilterCondition, client)
267+
conditions, err := expression.ExpressionsToPBList(sc, p.LateMaterializationFilterCondition, client)
268268
if err != nil {
269269
return nil, err
270270
}

planner/core/tiflash_selection_late_materialization.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ func predicatePushDownToTableScanImpl(sctx sessionctx.Context, physicalSelection
249249
// remove the pushed down conditions from selection
250250
removeSpecificExprsFromSelection(physicalSelection, selectedConds)
251251
// add the pushed down conditions to table scan
252-
physicalTableScan.lateMaterializationFilterCondition = selectedConds
252+
physicalTableScan.LateMaterializationFilterCondition = selectedConds
253253
// Update the row count of table scan after pushing down the conditions.
254254
physicalTableScan.stats.RowCount *= selectedSelectivity
255255
}

0 commit comments

Comments
 (0)