diff --git a/executor/builder.go b/executor/builder.go index 4ed4988dd7c92..d756da4cfc47e 100644 --- a/executor/builder.go +++ b/executor/builder.go @@ -3103,13 +3103,18 @@ func constructDAGReq(ctx sessionctx.Context, plans []plannercore.PhysicalPlan, s func (b *executorBuilder) corColInDistPlan(plans []plannercore.PhysicalPlan) bool { for _, p := range plans { - x, ok := p.(*plannercore.PhysicalSelection) - if !ok { - continue - } - for _, cond := range x.Conditions { - if len(expression.ExtractCorColumns(cond)) > 0 { - return true + switch x := p.(type) { + case *plannercore.PhysicalSelection: + for _, cond := range x.Conditions { + if len(expression.ExtractCorColumns(cond)) > 0 { + return true + } + } + case *plannercore.PhysicalTableScan: + for _, cond := range x.LateMaterializationFilterCondition { + if len(expression.ExtractCorColumns(cond)) > 0 { + return true + } } } } diff --git a/executor/table_reader.go b/executor/table_reader.go index f45fd1d759d92..69d011922f137 100644 --- a/executor/table_reader.go +++ b/executor/table_reader.go @@ -110,7 +110,8 @@ type TableReaderExecutor struct { byItems []*util.ByItems paging bool storeType kv.StoreType - // corColInFilter tells whether there's correlated column in filter. + // corColInFilter tells whether there's correlated column in filter (both conditions in PhysicalSelection and LateMaterializationFilterCondition in PhysicalTableScan) + // If true, we will need to revise the dagPB (fill correlated column value in filter) each time call Open(). corColInFilter bool // corColInAccess tells whether there's correlated column in access conditions. corColInAccess bool @@ -154,6 +155,7 @@ func (e *TableReaderExecutor) Open(ctx context.Context) error { var err error if e.corColInFilter { + // If there's correlated column in filter, need to rewrite dagPB if e.storeType == kv.TiFlash { execs, err := constructDistExecForTiFlash(e.ctx, e.tablePlan) if err != nil { diff --git a/planner/core/explain.go b/planner/core/explain.go index 8d76fa33f1d34..5a8fd7b380978 100644 --- a/planner/core/explain.go +++ b/planner/core/explain.go @@ -216,11 +216,15 @@ func (p *PhysicalTableScan) OperatorInfo(normalized bool) string { } if p.ctx.GetSessionVars().EnableLateMaterialization && len(p.filterCondition) > 0 && p.StoreType == kv.TiFlash { buffer.WriteString("pushed down filter:") - if len(p.lateMaterializationFilterCondition) > 0 { + if len(p.LateMaterializationFilterCondition) > 0 { if normalized { - buffer.Write(expression.SortedExplainNormalizedExpressionList(p.lateMaterializationFilterCondition)) + buffer.Write(expression.SortedExplainNormalizedExpressionList(p.LateMaterializationFilterCondition)) } else { +<<<<<<< HEAD:planner/core/explain.go buffer.Write(expression.SortedExplainExpressionList(p.lateMaterializationFilterCondition)) +======= + buffer.Write(expression.SortedExplainExpressionList(p.SCtx(), p.LateMaterializationFilterCondition)) +>>>>>>> 3fb6b98d1d0 (executor: fill correlated column value in late materialization filter conditions (#49244)):pkg/planner/core/explain.go } } else { buffer.WriteString("empty") diff --git a/planner/core/physical_plans.go b/planner/core/physical_plans.go index 76f2527fafd2d..5b1b960e25323 100644 --- a/planner/core/physical_plans.go +++ b/planner/core/physical_plans.go @@ -808,10 +808,10 @@ type PhysicalTableScan struct { // AccessCondition is used to calculate range. AccessCondition []expression.Expression filterCondition []expression.Expression - // lateMaterializationFilterCondition is used to record the filter conditions + // LateMaterializationFilterCondition is used to record the filter conditions // that are pushed down to table scan from selection by late materialization. // TODO: remove this field after we support pushing down selection to coprocessor. - lateMaterializationFilterCondition []expression.Expression + LateMaterializationFilterCondition []expression.Expression Table *model.TableInfo Columns []*model.ColumnInfo diff --git a/planner/core/plan_to_pb.go b/planner/core/plan_to_pb.go index 3ebcece46ef25..40311939a8af4 100644 --- a/planner/core/plan_to_pb.go +++ b/planner/core/plan_to_pb.go @@ -228,10 +228,16 @@ func (p *PhysicalTableScan) ToPB(ctx sessionctx.Context, storeType kv.StoreType) tsExec.KeepOrder = &keepOrder tsExec.IsFastScan = &(ctx.GetSessionVars().TiFlashFastScan) +<<<<<<< HEAD:planner/core/plan_to_pb.go if len(p.lateMaterializationFilterCondition) > 0 { sc := ctx.GetSessionVars().StmtCtx client := ctx.GetClient() conditions, err := expression.ExpressionsToPBList(sc, p.lateMaterializationFilterCondition, client) +======= + if len(p.LateMaterializationFilterCondition) > 0 { + client := ctx.GetClient() + conditions, err := expression.ExpressionsToPBList(ctx, p.LateMaterializationFilterCondition, client) +>>>>>>> 3fb6b98d1d0 (executor: fill correlated column value in late materialization filter conditions (#49244)):pkg/planner/core/plan_to_pb.go if err != nil { return nil, err } @@ -261,10 +267,16 @@ func (p *PhysicalTableScan) partitionTableScanToPBForFlash(ctx sessionctx.Contex telemetry.CurrentTiflashTableScanWithFastScanCount.Inc() } +<<<<<<< HEAD:planner/core/plan_to_pb.go if len(p.lateMaterializationFilterCondition) > 0 { sc := ctx.GetSessionVars().StmtCtx client := ctx.GetClient() conditions, err := expression.ExpressionsToPBList(sc, p.lateMaterializationFilterCondition, client) +======= + if len(p.LateMaterializationFilterCondition) > 0 { + client := ctx.GetClient() + conditions, err := expression.ExpressionsToPBList(ctx, p.LateMaterializationFilterCondition, client) +>>>>>>> 3fb6b98d1d0 (executor: fill correlated column value in late materialization filter conditions (#49244)):pkg/planner/core/plan_to_pb.go if err != nil { return nil, err } diff --git a/planner/core/tiflash_selection_late_materialization.go b/planner/core/tiflash_selection_late_materialization.go index 4c4f3d46339ea..321d36e8cceca 100644 --- a/planner/core/tiflash_selection_late_materialization.go +++ b/planner/core/tiflash_selection_late_materialization.go @@ -249,7 +249,7 @@ func predicatePushDownToTableScanImpl(sctx sessionctx.Context, physicalSelection // remove the pushed down conditions from selection removeSpecificExprsFromSelection(physicalSelection, selectedConds) // add the pushed down conditions to table scan - physicalTableScan.lateMaterializationFilterCondition = selectedConds + physicalTableScan.LateMaterializationFilterCondition = selectedConds // Update the row count of table scan after pushing down the conditions. physicalTableScan.stats.RowCount *= selectedSelectivity }