From 5757002137f56158425add96ca8eb309ea1aa35a Mon Sep 17 00:00:00 2001 From: Mattias Jonsson Date: Tue, 2 Jan 2024 21:44:50 +0000 Subject: [PATCH] Renamed PartitionInfo to [Phys]PlanPartInfo to distinguish from model.PartitionInfo --- pkg/executor/builder.go | 45 ++++++++++------------ pkg/planner/core/access_object.go | 25 ++++++------ pkg/planner/core/exhaust_physical_plans.go | 6 +-- pkg/planner/core/find_best_task.go | 10 ++--- pkg/planner/core/fragment.go | 2 +- pkg/planner/core/physical_plans.go | 42 ++++++++++---------- pkg/planner/core/task.go | 14 +++---- 7 files changed, 70 insertions(+), 74 deletions(-) diff --git a/pkg/executor/builder.go b/pkg/executor/builder.go index 9ff3568fcd75a..cc102944dce64 100644 --- a/pkg/executor/builder.go +++ b/pkg/executor/builder.go @@ -3453,7 +3453,7 @@ func (b *executorBuilder) buildTableReader(v *plannercore.PhysicalTableReader) e tmp, _ := b.is.TableByID(ts.Table.ID) tbl := tmp.(table.PartitionedTable) - partitions, err := partitionPruning(b.ctx, tbl, v.PartitionInfo.PruningConds, v.PartitionInfo.PartitionNames, v.PartitionInfo.Columns, v.PartitionInfo.ColumnNames) + partitions, err := partitionPruning(b.ctx, tbl, &v.PlanPartInfo) if err != nil { b.err = err return nil @@ -3539,14 +3539,14 @@ func getPartitionKeyColOffsets(keyColIDs []int64, pt table.PartitionedTable) []i return keyColOffsets } -func (builder *dataReaderBuilder) prunePartitionForInnerExecutor(tbl table.Table, partitionInfo *plannercore.PartitionInfo, +func (builder *dataReaderBuilder) prunePartitionForInnerExecutor(tbl table.Table, physPlanPartInfo *plannercore.PhysPlanPartInfo, lookUpContent []*indexJoinLookUpContent) (usedPartition []table.PhysicalTable, canPrune bool, contentPos []int64, err error) { partitionTbl := tbl.(table.PartitionedTable) // In index join, this is called by multiple goroutines simultaneously, but partitionPruning is not thread-safe. // Use once.Do to avoid DATA RACE here. // TODO: condition based pruning can be do in advance. - condPruneResult, err := builder.partitionPruning(partitionTbl, partitionInfo.PruningConds, partitionInfo.PartitionNames, partitionInfo.Columns, partitionInfo.ColumnNames) + condPruneResult, err := builder.partitionPruning(partitionTbl, physPlanPartInfo) if err != nil { return nil, false, nil, err } @@ -3692,7 +3692,7 @@ func (b *executorBuilder) buildIndexReader(v *plannercore.PhysicalIndexReader) e b.err = exeerrors.ErrBuildExecutor return nil } - ret.partitionIDMap, err = getPartitionIdsAfterPruning(b.ctx, tbl, &v.PartitionInfo) + ret.partitionIDMap, err = getPartitionIdsAfterPruning(b.ctx, tbl, &v.PlanPartInfo) if err != nil { b.err = err return nil @@ -3702,7 +3702,7 @@ func (b *executorBuilder) buildIndexReader(v *plannercore.PhysicalIndexReader) e tmp, _ := b.is.TableByID(is.Table.ID) tbl := tmp.(table.PartitionedTable) - partitions, err := partitionPruning(b.ctx, tbl, v.PartitionInfo.PruningConds, v.PartitionInfo.PartitionNames, v.PartitionInfo.Columns, v.PartitionInfo.ColumnNames) + partitions, err := partitionPruning(b.ctx, tbl, &v.PlanPartInfo) if err != nil { b.err = err return nil @@ -3889,7 +3889,7 @@ func (b *executorBuilder) buildIndexLookUpReader(v *plannercore.PhysicalIndexLoo b.err = exeerrors.ErrBuildExecutor return nil } - ret.partitionIDMap, err = getPartitionIdsAfterPruning(b.ctx, tbl, &v.PartitionInfo) + ret.partitionIDMap, err = getPartitionIdsAfterPruning(b.ctx, tbl, &v.PlanPartInfo) if err != nil { b.err = err return nil @@ -3906,7 +3906,7 @@ func (b *executorBuilder) buildIndexLookUpReader(v *plannercore.PhysicalIndexLoo tmp, _ := b.is.TableByID(is.Table.ID) tbl := tmp.(table.PartitionedTable) - partitions, err := partitionPruning(b.ctx, tbl, v.PartitionInfo.PruningConds, v.PartitionInfo.PartitionNames, v.PartitionInfo.Columns, v.PartitionInfo.ColumnNames) + partitions, err := partitionPruning(b.ctx, tbl, &v.PlanPartInfo) if err != nil { b.err = err return nil @@ -4036,7 +4036,7 @@ func (b *executorBuilder) buildIndexMergeReader(v *plannercore.PhysicalIndexMerg } tmp, _ := b.is.TableByID(ts.Table.ID) - partitions, err := partitionPruning(b.ctx, tmp.(table.PartitionedTable), v.PartitionInfo.PruningConds, v.PartitionInfo.PartitionNames, v.PartitionInfo.Columns, v.PartitionInfo.ColumnNames) + partitions, err := partitionPruning(b.ctx, tmp.(table.PartitionedTable), &v.PlanPartInfo) if err != nil { b.err = err return nil @@ -4163,8 +4163,7 @@ func (builder *dataReaderBuilder) buildTableReaderForIndexJoin(ctx context.Conte } tbl, _ := builder.is.TableByID(tbInfo.ID) pt := tbl.(table.PartitionedTable) - partitionInfo := &v.PartitionInfo - usedPartitionList, err := builder.partitionPruning(pt, partitionInfo.PruningConds, partitionInfo.PartitionNames, partitionInfo.Columns, partitionInfo.ColumnNames) + usedPartitionList, err := builder.partitionPruning(pt, &v.PlanPartInfo) if err != nil { return nil, err } @@ -4428,7 +4427,7 @@ func (builder *dataReaderBuilder) buildIndexReaderForIndexJoin(ctx context.Conte if !ok { return nil, exeerrors.ErrBuildExecutor } - e.partitionIDMap, err = getPartitionIdsAfterPruning(builder.ctx, tbl, &v.PartitionInfo) + e.partitionIDMap, err = getPartitionIdsAfterPruning(builder.ctx, tbl, &v.PlanPartInfo) if err != nil { return nil, err } @@ -4443,7 +4442,7 @@ func (builder *dataReaderBuilder) buildIndexReaderForIndexJoin(ctx context.Conte } tbl, _ := builder.executorBuilder.is.TableByID(tbInfo.ID) - usedPartition, canPrune, contentPos, err := builder.prunePartitionForInnerExecutor(tbl, &v.PartitionInfo, lookUpContents) + usedPartition, canPrune, contentPos, err := builder.prunePartitionForInnerExecutor(tbl, &v.PlanPartInfo, lookUpContents) if err != nil { return nil, err } @@ -4503,7 +4502,7 @@ func (builder *dataReaderBuilder) buildIndexLookUpReaderForIndexJoin(ctx context if !ok { return nil, exeerrors.ErrBuildExecutor } - e.partitionIDMap, err = getPartitionIdsAfterPruning(builder.ctx, tbl, &v.PartitionInfo) + e.partitionIDMap, err = getPartitionIdsAfterPruning(builder.ctx, tbl, &v.PlanPartInfo) if err != nil { return nil, err } @@ -4518,7 +4517,7 @@ func (builder *dataReaderBuilder) buildIndexLookUpReaderForIndexJoin(ctx context } tbl, _ := builder.executorBuilder.is.TableByID(tbInfo.ID) - usedPartition, canPrune, contentPos, err := builder.prunePartitionForInnerExecutor(tbl, &v.PartitionInfo, lookUpContents) + usedPartition, canPrune, contentPos, err := builder.prunePartitionForInnerExecutor(tbl, &v.PlanPartInfo, lookUpContents) if err != nil { return nil, err } @@ -5154,19 +5153,17 @@ func (b *executorBuilder) buildAdminResetTelemetryID(v *plannercore.AdminResetTe return &AdminResetTelemetryIDExec{BaseExecutor: exec.NewBaseExecutor(b.ctx, v.Schema(), v.ID())} } -func (builder *dataReaderBuilder) partitionPruning(tbl table.PartitionedTable, conds []expression.Expression, partitionNames []model.CIStr, - columns []*expression.Column, columnNames types.NameSlice) ([]table.PhysicalTable, error) { +func (builder *dataReaderBuilder) partitionPruning(tbl table.PartitionedTable, planPartInfo *plannercore.PhysPlanPartInfo) ([]table.PhysicalTable, error) { builder.once.Do(func() { - condPruneResult, err := partitionPruning(builder.executorBuilder.ctx, tbl, conds, partitionNames, columns, columnNames) + condPruneResult, err := partitionPruning(builder.executorBuilder.ctx, tbl, planPartInfo) builder.once.condPruneResult = condPruneResult builder.once.err = err }) return builder.once.condPruneResult, builder.once.err } -func partitionPruning(ctx sessionctx.Context, tbl table.PartitionedTable, conds []expression.Expression, partitionNames []model.CIStr, - columns []*expression.Column, columnNames types.NameSlice) ([]table.PhysicalTable, error) { - idxArr, err := plannercore.PartitionPruning(ctx, tbl, conds, partitionNames, columns, columnNames) +func partitionPruning(ctx sessionctx.Context, tbl table.PartitionedTable, planPartInfo *plannercore.PhysPlanPartInfo) ([]table.PhysicalTable, error) { + idxArr, err := plannercore.PartitionPruning(ctx, tbl, planPartInfo.PruningConds, planPartInfo.PartitionNames, planPartInfo.Columns, planPartInfo.ColumnNames) if err != nil { return nil, err } @@ -5190,11 +5187,11 @@ func partitionPruning(ctx sessionctx.Context, tbl table.PartitionedTable, conds return ret, nil } -func getPartitionIdsAfterPruning(ctx sessionctx.Context, tbl table.PartitionedTable, partInfo *plannercore.PartitionInfo) (map[int64]struct{}, error) { - if partInfo == nil { - return nil, errors.New("partInfo in getPartitionIdsAfterPruning must not be nil") +func getPartitionIdsAfterPruning(ctx sessionctx.Context, tbl table.PartitionedTable, physPlanPartInfo *plannercore.PhysPlanPartInfo) (map[int64]struct{}, error) { + if physPlanPartInfo == nil { + return nil, errors.New("physPlanPartInfo in getPartitionIdsAfterPruning must not be nil") } - idxArr, err := plannercore.PartitionPruning(ctx, tbl, partInfo.PruningConds, partInfo.PartitionNames, partInfo.Columns, partInfo.ColumnNames) + idxArr, err := plannercore.PartitionPruning(ctx, tbl, physPlanPartInfo.PruningConds, physPlanPartInfo.PartitionNames, physPlanPartInfo.Columns, physPlanPartInfo.ColumnNames) if err != nil { return nil, err } diff --git a/pkg/planner/core/access_object.go b/pkg/planner/core/access_object.go index ea59145cbc956..eda9b0be08714 100644 --- a/pkg/planner/core/access_object.go +++ b/pkg/planner/core/access_object.go @@ -353,7 +353,7 @@ func (p *BatchPointGetPlan) AccessObject() AccessObject { return res } -func getDynamicAccessPartition(sctx sessionctx.Context, tblInfo *model.TableInfo, partitionInfo *PartitionInfo, asName string) (res *DynamicPartitionAccessObject) { +func getDynamicAccessPartition(sctx sessionctx.Context, tblInfo *model.TableInfo, physPlanPartInfo *PhysPlanPartInfo, asName string) (res *DynamicPartitionAccessObject) { pi := tblInfo.GetPartitionInfo() if pi == nil || !sctx.GetSessionVars().StmtCtx.UseDynamicPartitionPrune() { return nil @@ -377,7 +377,7 @@ func getDynamicAccessPartition(sctx sessionctx.Context, tblInfo *model.TableInfo } tbl := tmp.(table.PartitionedTable) - idxArr, err := PartitionPruning(sctx, tbl, partitionInfo.PruningConds, partitionInfo.PartitionNames, partitionInfo.Columns, partitionInfo.ColumnNames) + idxArr, err := PartitionPruning(sctx, tbl, physPlanPartInfo.PruningConds, physPlanPartInfo.PartitionNames, physPlanPartInfo.Columns, physPlanPartInfo.ColumnNames) if err != nil { res.err = "partition pruning error:" + err.Error() return res @@ -398,7 +398,7 @@ func (p *PhysicalTableReader) accessObject(sctx sessionctx.Context) AccessObject if !sctx.GetSessionVars().StmtCtx.UseDynamicPartitionPrune() { return DynamicPartitionAccessObjects(nil) } - if len(p.PartitionInfos) == 0 { + if len(p.TableScanAndPartitionInfos) == 0 { ts, ok := p.TablePlans[0].(*PhysicalTableScan) if !ok { return OtherAccessObject("") @@ -407,15 +407,15 @@ func (p *PhysicalTableReader) accessObject(sctx sessionctx.Context) AccessObject if ts.TableAsName != nil && len(ts.TableAsName.O) > 0 { asName = ts.TableAsName.O } - res := getDynamicAccessPartition(sctx, ts.Table, &p.PartitionInfo, asName) + res := getDynamicAccessPartition(sctx, ts.Table, &p.PlanPartInfo, asName) if res == nil { return DynamicPartitionAccessObjects(nil) } return DynamicPartitionAccessObjects{res} } - if len(p.PartitionInfos) == 1 { - ts := p.PartitionInfos[0].tableScan - partInfo := p.PartitionInfos[0].partitionInfo + if len(p.TableScanAndPartitionInfos) == 1 { + ts := p.TableScanAndPartitionInfos[0].tableScan + partInfo := p.TableScanAndPartitionInfos[0].physPlanPartInfo asName := "" if ts.TableAsName != nil && len(ts.TableAsName.O) > 0 { asName = ts.TableAsName.O @@ -428,17 +428,16 @@ func (p *PhysicalTableReader) accessObject(sctx sessionctx.Context) AccessObject } res := make(DynamicPartitionAccessObjects, 0) - for _, info := range p.PartitionInfos { + for _, info := range p.TableScanAndPartitionInfos { if info.tableScan.Table.GetPartitionInfo() == nil { continue } ts := info.tableScan - partInfo := info.partitionInfo asName := "" if ts.TableAsName != nil && len(ts.TableAsName.O) > 0 { asName = ts.TableAsName.O } - accessObj := getDynamicAccessPartition(sctx, ts.Table, &partInfo, asName) + accessObj := getDynamicAccessPartition(sctx, ts.Table, &info.physPlanPartInfo, asName) if accessObj != nil { res = append(res, accessObj) } @@ -458,7 +457,7 @@ func (p *PhysicalIndexReader) accessObject(sctx sessionctx.Context) AccessObject if is.TableAsName != nil && len(is.TableAsName.O) > 0 { asName = is.TableAsName.O } - res := getDynamicAccessPartition(sctx, is.Table, &p.PartitionInfo, asName) + res := getDynamicAccessPartition(sctx, is.Table, &p.PlanPartInfo, asName) if res == nil { return DynamicPartitionAccessObjects(nil) } @@ -474,7 +473,7 @@ func (p *PhysicalIndexLookUpReader) accessObject(sctx sessionctx.Context) Access if ts.TableAsName != nil && len(ts.TableAsName.O) > 0 { asName = ts.TableAsName.O } - res := getDynamicAccessPartition(sctx, ts.Table, &p.PartitionInfo, asName) + res := getDynamicAccessPartition(sctx, ts.Table, &p.PlanPartInfo, asName) if res == nil { return DynamicPartitionAccessObjects(nil) } @@ -490,7 +489,7 @@ func (p *PhysicalIndexMergeReader) accessObject(sctx sessionctx.Context) AccessO if ts.TableAsName != nil && len(ts.TableAsName.O) > 0 { asName = ts.TableAsName.O } - res := getDynamicAccessPartition(sctx, ts.Table, &p.PartitionInfo, asName) + res := getDynamicAccessPartition(sctx, ts.Table, &p.PlanPartInfo, asName) if res == nil { return DynamicPartitionAccessObjects(nil) } diff --git a/pkg/planner/core/exhaust_physical_plans.go b/pkg/planner/core/exhaust_physical_plans.go index 82bc8e20d4e1c..785498491f663 100644 --- a/pkg/planner/core/exhaust_physical_plans.go +++ b/pkg/planner/core/exhaust_physical_plans.go @@ -1108,13 +1108,13 @@ func (p *LogicalJoin) constructInnerTableScanTask( tblColHists: ds.TblColHists, keepOrder: ts.KeepOrder, } - copTask.partitionInfo = PartitionInfo{ + copTask.physPlanPartInfo = PhysPlanPartInfo{ PruningConds: ds.allConds, PartitionNames: ds.partitionNames, Columns: ds.TblCols, ColumnNames: ds.names, } - ts.PartitionInfo = copTask.partitionInfo + ts.PlanPartInfo = copTask.physPlanPartInfo selStats := ts.StatsInfo().Scale(selectivity) ts.addPushedDownSelection(copTask, selStats) t := copTask.convertToRootTask(ds.SCtx()) @@ -1272,7 +1272,7 @@ func (p *LogicalJoin) constructInnerIndexScanTask( tblCols: ds.TblCols, keepOrder: is.KeepOrder, } - cop.partitionInfo = PartitionInfo{ + cop.physPlanPartInfo = PhysPlanPartInfo{ PruningConds: ds.allConds, PartitionNames: ds.partitionNames, Columns: ds.TblCols, diff --git a/pkg/planner/core/find_best_task.go b/pkg/planner/core/find_best_task.go index 8da95ef920fc8..464f18490acca 100644 --- a/pkg/planner/core/find_best_task.go +++ b/pkg/planner/core/find_best_task.go @@ -1346,7 +1346,7 @@ func (ds *DataSource) convertToIndexMergeScan(prop *property.PhysicalProperty, c indexPlanFinished: false, tblColHists: ds.TblColHists, } - cop.partitionInfo = PartitionInfo{ + cop.physPlanPartInfo = PhysPlanPartInfo{ PruningConds: pushDownNot(ds.SCtx(), ds.allConds), PartitionNames: ds.partitionNames, Columns: ds.TblCols, @@ -1757,7 +1757,7 @@ func (ds *DataSource) convertToIndexScan(prop *property.PhysicalProperty, tblCols: ds.TblCols, expectCnt: uint64(prop.ExpectedCnt), } - cop.partitionInfo = PartitionInfo{ + cop.physPlanPartInfo = PhysPlanPartInfo{ PruningConds: pushDownNot(ds.SCtx(), ds.allConds), PartitionNames: ds.partitionNames, Columns: ds.TblCols, @@ -2179,7 +2179,7 @@ func (ds *DataSource) convertToTableScan(prop *property.PhysicalProperty, candid partTp: property.AnyType, tblColHists: ds.TblColHists, } - ts.PartitionInfo = PartitionInfo{ + ts.PlanPartInfo = PhysPlanPartInfo{ PruningConds: pushDownNot(ds.SCtx(), ds.allConds), PartitionNames: ds.partitionNames, Columns: ds.TblCols, @@ -2213,13 +2213,13 @@ func (ds *DataSource) convertToTableScan(prop *property.PhysicalProperty, candid indexPlanFinished: true, tblColHists: ds.TblColHists, } - copTask.partitionInfo = PartitionInfo{ + copTask.physPlanPartInfo = PhysPlanPartInfo{ PruningConds: pushDownNot(ds.SCtx(), ds.allConds), PartitionNames: ds.partitionNames, Columns: ds.TblCols, ColumnNames: ds.names, } - ts.PartitionInfo = copTask.partitionInfo + ts.PlanPartInfo = copTask.physPlanPartInfo task = copTask if candidate.isMatchProp { copTask.keepOrder = true diff --git a/pkg/planner/core/fragment.go b/pkg/planner/core/fragment.go index dca5f03198a12..95eea5bd349ad 100644 --- a/pkg/planner/core/fragment.go +++ b/pkg/planner/core/fragment.go @@ -554,7 +554,7 @@ func (e *mppTaskGenerator) constructMPPTasksImpl(ctx context.Context, ts *Physic tbl := tmp.(table.PartitionedTable) if !tiFlashStaticPrune { var partitions []table.PhysicalTable - partitions, err = partitionPruning(e.ctx, tbl, ts.PartitionInfo.PruningConds, ts.PartitionInfo.PartitionNames, ts.PartitionInfo.Columns, ts.PartitionInfo.ColumnNames) + partitions, err = partitionPruning(e.ctx, tbl, ts.PlanPartInfo.PruningConds, ts.PlanPartInfo.PartitionNames, ts.PlanPartInfo.Columns, ts.PlanPartInfo.ColumnNames) if err != nil { return nil, errors.Trace(err) } diff --git a/pkg/planner/core/physical_plans.go b/pkg/planner/core/physical_plans.go index 4c250cc91cf35..6bf372df63dbe 100644 --- a/pkg/planner/core/physical_plans.go +++ b/pkg/planner/core/physical_plans.go @@ -76,8 +76,8 @@ var ( ) type tableScanAndPartitionInfo struct { - tableScan *PhysicalTableScan - partitionInfo PartitionInfo + tableScan *PhysicalTableScan + physPlanPartInfo PhysPlanPartInfo } // MemoryUsage return the memory usage of tableScanAndPartitionInfo @@ -86,7 +86,7 @@ func (t *tableScanAndPartitionInfo) MemoryUsage() (sum int64) { return } - sum += t.partitionInfo.MemoryUsage() + sum += t.physPlanPartInfo.MemoryUsage() if t.tableScan != nil { sum += t.tableScan.MemoryUsage() } @@ -136,23 +136,23 @@ type PhysicalTableReader struct { IsCommonHandle bool // Used by partition table. - PartitionInfo PartitionInfo + PlanPartInfo PhysPlanPartInfo // Used by MPP, because MPP plan may contain join/union/union all, it is possible that a physical table reader contains more than 1 table scan - PartitionInfos []tableScanAndPartitionInfo + TableScanAndPartitionInfos []tableScanAndPartitionInfo } -// PartitionInfo indicates partition helper info in physical plan. -type PartitionInfo struct { +// PhysPlanPartInfo indicates partition helper info in physical plan. +type PhysPlanPartInfo struct { PruningConds []expression.Expression PartitionNames []model.CIStr Columns []*expression.Column ColumnNames types.NameSlice } -const emptyPartitionInfoSize = int64(unsafe.Sizeof(PartitionInfo{})) +const emptyPartitionInfoSize = int64(unsafe.Sizeof(PhysPlanPartInfo{})) -// MemoryUsage return the memory usage of PartitionInfo -func (pi *PartitionInfo) MemoryUsage() (sum int64) { +// MemoryUsage return the memory usage of PhysPlanPartInfo +func (pi *PhysPlanPartInfo) MemoryUsage() (sum int64) { if pi == nil { return } @@ -210,12 +210,12 @@ func (p *PhysicalTableReader) MemoryUsage() (sum int64) { return } - sum = p.physicalSchemaProducer.MemoryUsage() + size.SizeOfUint8*2 + size.SizeOfBool + p.PartitionInfo.MemoryUsage() + sum = p.physicalSchemaProducer.MemoryUsage() + size.SizeOfUint8*2 + size.SizeOfBool + p.PlanPartInfo.MemoryUsage() if p.tablePlan != nil { sum += p.tablePlan.MemoryUsage() } // since TablePlans is the flats of tablePlan, so we don't count it - for _, pInfo := range p.PartitionInfos { + for _, pInfo := range p.TableScanAndPartitionInfos { sum += pInfo.MemoryUsage() } return @@ -235,7 +235,7 @@ func setMppOrBatchCopForTableScan(curPlan PhysicalPlan) { // GetPhysicalTableReader returns PhysicalTableReader for logical TiKVSingleGather. func (sg *TiKVSingleGather) GetPhysicalTableReader(schema *expression.Schema, stats *property.StatsInfo, props ...*property.PhysicalProperty) *PhysicalTableReader { reader := PhysicalTableReader{}.Init(sg.SCtx(), sg.QueryBlockOffset()) - reader.PartitionInfo = PartitionInfo{ + reader.PlanPartInfo = PhysPlanPartInfo{ PruningConds: sg.Source.allConds, PartitionNames: sg.Source.partitionNames, Columns: sg.Source.TblCols, @@ -315,7 +315,7 @@ type PhysicalIndexReader struct { OutputColumns []*expression.Column // Used by partition table. - PartitionInfo PartitionInfo + PlanPartInfo PhysPlanPartInfo } // Clone implements PhysicalPlan interface. @@ -387,7 +387,7 @@ func (p *PhysicalIndexReader) MemoryUsage() (sum int64) { return } - sum = p.physicalSchemaProducer.MemoryUsage() + p.PartitionInfo.MemoryUsage() + sum = p.physicalSchemaProducer.MemoryUsage() + p.PlanPartInfo.MemoryUsage() if p.indexPlan != nil { p.indexPlan.MemoryUsage() } @@ -444,7 +444,7 @@ type PhysicalIndexLookUpReader struct { CommonHandleCols []*expression.Column // Used by partition table. - PartitionInfo PartitionInfo + PlanPartInfo PhysPlanPartInfo // required by cost calculation expectedCnt uint64 @@ -529,7 +529,7 @@ func (p *PhysicalIndexLookUpReader) MemoryUsage() (sum int64) { return } - sum = p.physicalSchemaProducer.MemoryUsage() + size.SizeOfBool*2 + p.PartitionInfo.MemoryUsage() + size.SizeOfUint64 + sum = p.physicalSchemaProducer.MemoryUsage() + size.SizeOfBool*2 + p.PlanPartInfo.MemoryUsage() + size.SizeOfUint64 if p.indexPlan != nil { sum += p.indexPlan.MemoryUsage() @@ -576,7 +576,7 @@ type PhysicalIndexMergeReader struct { tablePlan PhysicalPlan // Used by partition table. - PartitionInfo PartitionInfo + PlanPartInfo PhysPlanPartInfo KeepOrder bool @@ -632,7 +632,7 @@ func (p *PhysicalIndexMergeReader) MemoryUsage() (sum int64) { return } - sum = p.physicalSchemaProducer.MemoryUsage() + p.PartitionInfo.MemoryUsage() + sum = p.physicalSchemaProducer.MemoryUsage() + p.PlanPartInfo.MemoryUsage() if p.tablePlan != nil { sum += p.tablePlan.MemoryUsage() } @@ -865,7 +865,7 @@ type PhysicalTableScan struct { isChildOfIndexLookUp bool - PartitionInfo PartitionInfo + PlanPartInfo PhysPlanPartInfo SampleInfo *TableSampleInfo @@ -1014,7 +1014,7 @@ func (ts *PhysicalTableScan) MemoryUsage() (sum int64) { } sum = emptyPhysicalTableScanSize + ts.physicalSchemaProducer.MemoryUsage() + ts.DBName.MemoryUsage() + - int64(cap(ts.HandleIdx))*size.SizeOfInt + ts.PartitionInfo.MemoryUsage() + int64(len(ts.rangeInfo)) + int64(cap(ts.HandleIdx))*size.SizeOfInt + ts.PlanPartInfo.MemoryUsage() + int64(len(ts.rangeInfo)) if ts.TableAsName != nil { sum += ts.TableAsName.MemoryUsage() } diff --git a/pkg/planner/core/task.go b/pkg/planner/core/task.go index ce81dc1e91180..8e0cea5b88232 100644 --- a/pkg/planner/core/task.go +++ b/pkg/planner/core/task.go @@ -92,7 +92,7 @@ type copTask struct { rootTaskConds []expression.Expression // For table partition. - partitionInfo PartitionInfo + physPlanPartInfo PhysPlanPartInfo // expectCnt is the expected row count of upper task, 0 for unlimited. // It's used for deciding whether using paging distsql. @@ -191,7 +191,7 @@ func (t *copTask) MemoryUsage() (sum int64) { } sum = size.SizeOfInterface*(2+int64(cap(t.idxMergePartPlans)+cap(t.rootTaskConds))) + size.SizeOfBool*3 + size.SizeOfUint64 + - size.SizeOfPointer*(3+int64(cap(t.commonHandleCols)+cap(t.tblCols))) + size.SizeOfSlice*4 + t.partitionInfo.MemoryUsage() + size.SizeOfPointer*(3+int64(cap(t.commonHandleCols)+cap(t.tblCols))) + size.SizeOfSlice*4 + t.physPlanPartInfo.MemoryUsage() if t.indexPlan != nil { sum += t.indexPlan.MemoryUsage() } @@ -591,7 +591,7 @@ func buildIndexLookUpTask(ctx sessionctx.Context, t *copTask) *rootTask { expectedCnt: t.expectCnt, keepOrder: t.keepOrder, }.Init(ctx, t.tablePlan.QueryBlockOffset()) - p.PartitionInfo = t.partitionInfo + p.PlanPartInfo = t.physPlanPartInfo setTableScanToTableRowIDScan(p.tablePlan) p.SetStats(t.tablePlan.StatsInfo()) // Do not inject the extra Projection even if t.needExtraProj is set, or the schema between the phase-1 agg and @@ -695,7 +695,7 @@ func (t *copTask) convertToRootTaskImpl(ctx sessionctx.Context) *rootTask { AccessMVIndex: t.idxMergeAccessMVIndex, KeepOrder: t.keepOrder, }.Init(ctx, t.idxMergePartPlans[0].QueryBlockOffset()) - p.PartitionInfo = t.partitionInfo + p.PlanPartInfo = t.physPlanPartInfo setTableScanToTableRowIDScan(p.tablePlan) newTask.p = p t.handleRootTaskConds(ctx, newTask) @@ -712,7 +712,7 @@ func (t *copTask) convertToRootTaskImpl(ctx sessionctx.Context) *rootTask { newTask = buildIndexLookUpTask(ctx, t) } else if t.indexPlan != nil { p := PhysicalIndexReader{indexPlan: t.indexPlan}.Init(ctx, t.indexPlan.QueryBlockOffset()) - p.PartitionInfo = t.partitionInfo + p.PlanPartInfo = t.physPlanPartInfo p.SetStats(t.indexPlan.StatsInfo()) newTask.p = p } else { @@ -731,7 +731,7 @@ func (t *copTask) convertToRootTaskImpl(ctx sessionctx.Context) *rootTask { StoreType: ts.StoreType, IsCommonHandle: ts.Table.IsCommonHandle, }.Init(ctx, t.tablePlan.QueryBlockOffset()) - p.PartitionInfo = t.partitionInfo + p.PlanPartInfo = t.physPlanPartInfo p.SetStats(t.tablePlan.StatsInfo()) // If agg was pushed down in attach2Task(), the partial agg was placed on the top of tablePlan, the final agg was @@ -2602,7 +2602,7 @@ func (t *mppTask) MemoryUsage() (sum int64) { func collectPartitionInfosFromMPPPlan(p *PhysicalTableReader, mppPlan PhysicalPlan) { switch x := mppPlan.(type) { case *PhysicalTableScan: - p.PartitionInfos = append(p.PartitionInfos, tableScanAndPartitionInfo{x, x.PartitionInfo}) + p.TableScanAndPartitionInfos = append(p.TableScanAndPartitionInfos, tableScanAndPartitionInfo{x, x.PlanPartInfo}) default: for _, ch := range mppPlan.Children() { collectPartitionInfosFromMPPPlan(p, ch)