From 82ed64ad53e42f7556b62bb1c34a50db558c2933 Mon Sep 17 00:00:00 2001 From: Mattias Jonsson Date: Fri, 27 Sep 2024 13:40:50 +0200 Subject: [PATCH 1/8] *: Allow Point_Get during DDL with Global Index --- pkg/ddl/partition.go | 39 +++++++---- pkg/ddl/tests/partition/db_partition_test.go | 6 +- pkg/executor/point_get.go | 8 ++- pkg/meta/model/table.go | 68 +++++++++++++++++++- pkg/planner/core/find_best_task.go | 39 +++++------ 5 files changed, 119 insertions(+), 41 deletions(-) diff --git a/pkg/ddl/partition.go b/pkg/ddl/partition.go index d2011a22eb1f5..7e99194a1f558 100644 --- a/pkg/ddl/partition.go +++ b/pkg/ddl/partition.go @@ -136,6 +136,8 @@ func (w *worker) onAddTablePartition(jobCtx *jobContext, t *meta.Meta, job *mode // move the adding definition into tableInfo. updateAddingPartitionInfo(partInfo, tblInfo) + tblInfo.Partition.DDLState = model.StateReplicaOnly + tblInfo.Partition.DDLAction = job.Type ver, err = updateVersionAndTableInfoWithCheck(jobCtx, t, job, tblInfo, true) if err != nil { return ver, errors.Trace(err) @@ -222,6 +224,8 @@ func (w *worker) onAddTablePartition(jobCtx *jobContext, t *meta.Meta, job *mode preSplitAndScatter(w.sess.Context, jobCtx.store, tblInfo, addingDefinitions) + tblInfo.Partition.DDLState = model.StateNone + tblInfo.Partition.DDLAction = model.ActionNone ver, err = updateVersionAndTableInfo(jobCtx, t, job, tblInfo, true) if err != nil { return ver, errors.Trace(err) @@ -2215,9 +2219,6 @@ func (w *worker) onDropTablePartition(jobCtx *jobContext, t *meta.Meta, job *mod } var physicalTableIDs []int64 - // In order to skip maintaining the state check in partitionDefinition, TiDB use droppingDefinition instead of state field. - // So here using `job.SchemaState` to judge what the stage of this job is. - originalState := job.SchemaState switch job.SchemaState { case model.StatePublic: // If an error occurs, it returns that it cannot delete all partitions or that the partition doesn't exist. @@ -2265,13 +2266,16 @@ func (w *worker) onDropTablePartition(jobCtx *jobContext, t *meta.Meta, job *mod } job.SchemaState = model.StateDeleteOnly - ver, err = updateVersionAndTableInfo(jobCtx, t, job, tblInfo, originalState != job.SchemaState) + tblInfo.Partition.DDLState = job.SchemaState + tblInfo.Partition.DDLAction = job.Type + ver, err = updateVersionAndTableInfo(jobCtx, t, job, tblInfo, true) case model.StateDeleteOnly: // This state is not a real 'DeleteOnly' state, because tidb does not maintaining the state check in partitionDefinition. // Insert this state to confirm all servers can not see the old partitions when reorg is running, // so that no new data will be inserted into old partitions when reorganizing. job.SchemaState = model.StateDeleteReorganization - ver, err = updateVersionAndTableInfo(jobCtx, t, job, tblInfo, originalState != job.SchemaState) + tblInfo.Partition.DDLState = job.SchemaState + ver, err = updateVersionAndTableInfo(jobCtx, t, job, tblInfo, true) case model.StateDeleteReorganization: oldTblInfo := getTableInfoWithDroppingPartitions(tblInfo) physicalTableIDs = getPartitionIDsFromDefinitions(tblInfo.Partition.DroppingDefinitions) @@ -2336,6 +2340,7 @@ func (w *worker) onDropTablePartition(jobCtx *jobContext, t *meta.Meta, job *mod return ver, errors.Trace(err) } job.SchemaState = model.StateNone + tblInfo.Partition.DDLState = job.SchemaState job.FinishTableJob(model.JobStateDone, model.StateNone, ver, tblInfo) dropPartitionEvent := notifier.NewDropPartitionEvent( tblInfo, @@ -2463,12 +2468,15 @@ func (w *worker) onTruncateTablePartition(jobCtx *jobContext, t *meta.Meta, job pi.NewPartitionIDs = newIDs[:] job.SchemaState = model.StateDeleteOnly + pi.DDLState = job.SchemaState + pi.DDLAction = job.Type ver, err = updateVersionAndTableInfo(jobCtx, t, job, tblInfo, true) case model.StateDeleteOnly: // This state is not a real 'DeleteOnly' state, because tidb does not maintaining the state check in partitionDefinition. // Insert this state to confirm all servers can not see the old partitions when reorg is running, // so that no new data will be inserted into old partitions when reorganizing. job.SchemaState = model.StateDeleteReorganization + pi.DDLState = job.SchemaState ver, err = updateVersionAndTableInfo(jobCtx, t, job, tblInfo, true) case model.StateDeleteReorganization: // Step2: clear global index rows. @@ -2559,6 +2567,8 @@ func (w *worker) onTruncateTablePartition(jobCtx *jobContext, t *meta.Meta, job // Step4: clear DroppingDefinitions and finish job. tblInfo.Partition.DroppingDefinitions = nil tblInfo.Partition.NewPartitionIDs = nil + tblInfo.Partition.DDLAction = model.ActionNone + tblInfo.Partition.DDLState = model.StateNone preSplitAndScatter(w.sess.Context, jobCtx.store, tblInfo, newPartitions) @@ -2765,6 +2775,8 @@ func (w *worker) onExchangeTablePartition(jobCtx *jobContext, t *meta.Meta, job // into the table using the schema version // before the exchange is made. job.SchemaState = model.StateWriteOnly + pt.Partition.DDLState = job.SchemaState + pt.Partition.DDLAction = job.Type return updateVersionAndTableInfoWithCheck(jobCtx, t, job, nt, true, ptInfo...) } // From now on, nt (the non-partitioned table) has @@ -2839,6 +2851,8 @@ func (w *worker) onExchangeTablePartition(jobCtx *jobContext, t *meta.Meta, job originalPartitionDef := partDef.Clone() originalNt := nt.Clone() partDef.ID, nt.ID = nt.ID, partDef.ID + pt.Partition.DDLState = model.StateNone + pt.Partition.DDLAction = model.ActionNone err = t.UpdateTable(ptSchemaID, pt) if err != nil { @@ -3272,7 +3286,8 @@ func (w *worker) onReorganizePartition(jobCtx *jobContext, t *meta.Meta, job *mo // Assume we cannot have more than MaxUint64 rows, set the progress to 1/10 of that. metrics.GetBackfillProgressByLabel(metrics.LblReorgPartition, job.SchemaName, tblInfo.Name.String()).Set(0.1 / float64(math.MaxUint64)) job.SchemaState = model.StateDeleteOnly - tblInfo.Partition.DDLState = model.StateDeleteOnly + tblInfo.Partition.DDLState = job.SchemaState + tblInfo.Partition.DDLAction = job.Type ver, err = updateVersionAndTableInfoWithCheck(jobCtx, t, job, tblInfo, true) if err != nil { return ver, errors.Trace(err) @@ -3341,8 +3356,9 @@ func (w *worker) onReorganizePartition(jobCtx *jobContext, t *meta.Meta, job *mo failpoint.Return(rollbackReorganizePartitionWithErr(jobCtx, t, job, err)) } }) - ver, err = updateVersionAndTableInfo(jobCtx, t, job, tblInfo, true) job.SchemaState = model.StateWriteOnly + tblInfo.Partition.DDLState = job.SchemaState + ver, err = updateVersionAndTableInfo(jobCtx, t, job, tblInfo, true) case model.StateWriteOnly: // Insert this state to confirm all servers can see the new partitions when reorg is running, // so that new data will be updated in both old and new partitions when reorganizing. @@ -3352,10 +3368,10 @@ func (w *worker) onReorganizePartition(jobCtx *jobContext, t *meta.Meta, job *mo tblInfo.Indices[i].State = model.StateWriteReorganization } } - tblInfo.Partition.DDLState = model.StateWriteReorganization + job.SchemaState = model.StateWriteReorganization + tblInfo.Partition.DDLState = job.SchemaState metrics.GetBackfillProgressByLabel(metrics.LblReorgPartition, job.SchemaName, tblInfo.Name.String()).Set(0.3 / float64(math.MaxUint64)) ver, err = updateVersionAndTableInfo(jobCtx, t, job, tblInfo, true) - job.SchemaState = model.StateWriteReorganization case model.StateWriteReorganization: physicalTableIDs := getPartitionIDsFromDefinitions(tblInfo.Partition.DroppingDefinitions) tbl, err2 := getTable(jobCtx.getAutoIDRequirement(), job.SchemaID, tblInfo) @@ -3440,9 +3456,9 @@ func (w *worker) onReorganizePartition(jobCtx *jobContext, t *meta.Meta, job *mo // Now all the data copying is done, but we cannot simply remove the droppingDefinitions // since they are a part of the normal Definitions that other nodes with // the current schema version. So we need to double write for one more schema version - tblInfo.Partition.DDLState = model.StateDeleteReorganization - ver, err = updateVersionAndTableInfo(jobCtx, t, job, tblInfo, true) job.SchemaState = model.StateDeleteReorganization + tblInfo.Partition.DDLState = job.SchemaState + ver, err = updateVersionAndTableInfo(jobCtx, t, job, tblInfo, true) case model.StateDeleteReorganization: // Drop the droppingDefinitions and finish the DDL @@ -3464,6 +3480,7 @@ func (w *worker) onReorganizePartition(jobCtx *jobContext, t *meta.Meta, job *mo tblInfo.Partition.DroppingDefinitions = nil tblInfo.Partition.AddingDefinitions = nil tblInfo.Partition.DDLState = model.StateNone + tblInfo.Partition.DDLAction = model.ActionNone tblInfo.Partition.OriginalPartitionIDsOrder = nil var dropIndices []*model.IndexInfo diff --git a/pkg/ddl/tests/partition/db_partition_test.go b/pkg/ddl/tests/partition/db_partition_test.go index 5499aadb87d46..84fc1a531e050 100644 --- a/pkg/ddl/tests/partition/db_partition_test.go +++ b/pkg/ddl/tests/partition/db_partition_test.go @@ -1433,10 +1433,8 @@ func TestTruncatePartitionWithGlobalIndex(t *testing.T) { tk3 := testkit.NewTestKit(t, store) tk3.MustExec(`begin`) tk3.MustExec(`use test`) - tk3.MustQuery(`explain format='brief' select b from test_global use index(idx_b) where b = 15`).CheckContain("IndexRangeScan") - tk3.MustQuery(`explain format='brief' select b from test_global use index(idx_b) where b = 15`).CheckContain("Selection") - tk3.MustQuery(`explain format='brief' select c from test_global use index(idx_c) where c = 15`).CheckContain("IndexRangeScan") - tk3.MustQuery(`explain format='brief' select c from test_global use index(idx_c) where c = 15`).CheckContain("Selection") + tk3.MustQuery(`explain format='brief' select b from test_global use index(idx_b) where b = 15`).CheckContain("Point_Get") + tk3.MustQuery(`explain format='brief' select c from test_global use index(idx_c) where c = 15`).CheckContain("Point_Get") tk3.MustQuery(`select b from test_global use index(idx_b) where b = 15`).Check(testkit.Rows()) tk3.MustQuery(`select c from test_global use index(idx_c) where c = 15`).Check(testkit.Rows()) // Here it will fail with diff --git a/pkg/executor/point_get.go b/pkg/executor/point_get.go index cdee9fd033014..cea86884a841e 100644 --- a/pkg/executor/point_get.go +++ b/pkg/executor/point_get.go @@ -371,9 +371,15 @@ func (e *PointGetExecutor) Next(ctx context.Context, req *chunk.Chunk) error { return err } tblID = pid - if !matchPartitionNames(tblID, e.partitionNames, e.tblInfo.GetPartitionInfo()) { + pi := e.tblInfo.GetPartitionInfo() + if !matchPartitionNames(tblID, e.partitionNames, pi) { return nil } + for _, id := range pi.IDsInDDLToIgnore() { + if id == pid { + return nil + } + } } } } diff --git a/pkg/meta/model/table.go b/pkg/meta/model/table.go index 970a03e4d5164..0413dcb20298d 100644 --- a/pkg/meta/model/table.go +++ b/pkg/meta/model/table.go @@ -730,6 +730,9 @@ type PartitionInfo struct { DDLColumns []model.CIStr `json:"ddl_columns"` // For ActionAlterTablePartitioning, UPDATE INDEXES DDLUpdateIndexes []UpdateIndexInfo `json:"ddl_update_indexes"` + // To know which DDL is ongoing. Together with DDLState one can know + // how to handle Global Index visible entries + DDLAction ActionType `json:"ddl_action"` } // Clone clones itself. @@ -832,6 +835,8 @@ func (pi *PartitionInfo) ClearReorgIntermediateInfo() { pi.DDLExpr = "" pi.DDLColumns = nil pi.NewTableID = 0 + pi.DDLState = StateNone + pi.DDLAction = ActionNone } // FindPartitionDefinitionByName finds PartitionDefinition by name. @@ -867,6 +872,67 @@ func (pi *PartitionInfo) SetOriginalPartitionIDs() { pi.OriginalPartitionIDsOrder = ids } +// IDsInDDLToIgnore returns a list of IDs that the current +// session should not see (may be duplicate errors on insert/update though) +// For example during truncate or drop partition. +func (pi *PartitionInfo) IDsInDDLToIgnore() []int64 { + // TODO: + // Truncate partition: + // write only => should not see NewPartitionIDs + // delete only => should not see DroppingPartitions + // Drop partition: + // TODO: Make similar changes as in Truncate Partition: + // Add a state blocking read and write in the partitions to be dropped, + // to avoid situations like https://github.com/pingcap/tidb/issues/55888 + // Add partition: + // TODO: Add tests! + // Exchange Partition: + // Currently blocked for GlobalIndex + // Reorganize Partition: + // Nothing, since it will create a new copy of the global index. + // This is due to the global index needs to have two partitions for the same index key + // TODO: Should we extend the GlobalIndex to have multiple partitions? + // Maybe from PK/_tidb_rowid + Partition ID + // to PK/_tidb_rowid + Partition ID + Valid from Schema Version, + // with support for two entries? + // If so, could we then replace this? + switch pi.DDLAction { + case ActionTruncateTablePartition: + switch pi.DDLState { + case StateWriteOnly: + return pi.NewPartitionIDs + case StateDeleteOnly, StateDeleteReorganization: + if len(pi.DroppingDefinitions) == 0 { + return nil + } + ids := make([]int64, 0, len(pi.DroppingDefinitions)) + for _, definition := range pi.DroppingDefinitions { + ids = append(ids, definition.ID) + } + return ids + } + case ActionDropTablePartition: + if len(pi.DroppingDefinitions) > 0 && pi.DDLState == StateDeleteOnly { + ids := make([]int64, 0, len(pi.DroppingDefinitions)) + for _, def := range pi.DroppingDefinitions { + ids = append(ids, def.ID) + } + return ids + } + case ActionAddTablePartition: + // TODO: Add tests for ADD PARTITION multi-domain with Global Index! + if len(pi.AddingDefinitions) > 0 { + ids := make([]int64, 0, len(pi.DroppingDefinitions)) + for _, def := range pi.AddingDefinitions { + ids = append(ids, def.ID) + } + return ids + } + // Not supporting Global Indexes: case ActionExchangeTablePartition + } + return nil +} + // PartitionState is the state of the partition. type PartitionState struct { ID int64 `json:"id"` @@ -883,7 +949,7 @@ type PartitionDefinition struct { Comment string `json:"comment,omitempty"` } -// Clone clones ConstraintInfo. +// Clone clones PartitionDefinition. func (ci *PartitionDefinition) Clone() PartitionDefinition { nci := *ci nci.LessThan = make([]string, len(ci.LessThan)) diff --git a/pkg/planner/core/find_best_task.go b/pkg/planner/core/find_best_task.go index 05482eac86c2f..a8faba054d96e 100644 --- a/pkg/planner/core/find_best_task.go +++ b/pkg/planner/core/find_best_task.go @@ -1466,16 +1466,6 @@ func findBestTask4LogicalDataSource(lp base.LogicalPlan, prop *property.Physical if canConvertPointGet && path.IsIntHandlePath && !ds.Table.Meta().PKIsHandle && len(ds.PartitionNames) != 1 { canConvertPointGet = false } - if canConvertPointGet { - if path != nil && path.Index != nil && path.Index.Global { - // Don't convert to point get during ddl - // TODO: Revisit truncate partition and global index - if len(ds.TableInfo.GetPartitionInfo().DroppingDefinitions) > 0 || - len(ds.TableInfo.GetPartitionInfo().AddingDefinitions) > 0 { - canConvertPointGet = false - } - } - } } if canConvertPointGet { allRangeIsPoint := true @@ -2264,26 +2254,27 @@ func (is *PhysicalIndexScan) addSelectionConditionForGlobalIndex(p *logicalop.Da needNot := false pInfo := p.TableInfo.GetPartitionInfo() if len(idxArr) == 1 && idxArr[0] == FullRange { - // Only filter adding and dropping partitions. - if len(pInfo.AddingDefinitions) == 0 && len(pInfo.DroppingDefinitions) == 0 { - return conditions, nil - } + // Filter away partitions that may exists in Global Index, + // but should not be seen. needNot = true - for _, p := range pInfo.AddingDefinitions { - args = append(args, expression.NewInt64Const(p.ID)) - } - for _, p := range pInfo.DroppingDefinitions { - args = append(args, expression.NewInt64Const(p.ID)) + for _, id := range pInfo.IDsInDDLToIgnore() { + args = append(args, expression.NewInt64Const(id)) } - } else if len(idxArr) == 0 { - // add an invalid pid as param for `IN` function - args = append(args, expression.NewInt64Const(-1)) } else { - // `PartitionPruning`` func does not return adding and dropping partitions + ignoreMap := make(map[int64]struct{}) + for _, id := range pInfo.IDsInDDLToIgnore() { + ignoreMap[id] = struct{}{} + } for _, idx := range idxArr { - args = append(args, expression.NewInt64Const(pInfo.Definitions[idx].ID)) + id := pInfo.Definitions[idx].ID + if _, ok := ignoreMap[id]; !ok { + args = append(args, expression.NewInt64Const(id)) + } } } + if len(args) == 1 { + return conditions, nil + } condition, err := expression.NewFunction(p.SCtx().GetExprCtx(), ast.In, types.NewFieldType(mysql.TypeLonglong), args...) if err != nil { return nil, err From ace4c13b54887cec8b9e9fc1d6f747757f48ba26 Mon Sep 17 00:00:00 2001 From: Mattias Jonsson Date: Fri, 27 Sep 2024 14:37:10 +0200 Subject: [PATCH 2/8] Added comment --- pkg/meta/model/table.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pkg/meta/model/table.go b/pkg/meta/model/table.go index 0413dcb20298d..5b70624729f33 100644 --- a/pkg/meta/model/table.go +++ b/pkg/meta/model/table.go @@ -895,6 +895,8 @@ func (pi *PartitionInfo) IDsInDDLToIgnore() []int64 { // Maybe from PK/_tidb_rowid + Partition ID // to PK/_tidb_rowid + Partition ID + Valid from Schema Version, // with support for two entries? + // Then we could avoid having two copies of the same Global Index + // just for handling a single SchemaState. // If so, could we then replace this? switch pi.DDLAction { case ActionTruncateTablePartition: From 25d56a7a7f82bb4391639cd4c47d0e56ade0e752 Mon Sep 17 00:00:00 2001 From: Mattias Jonsson Date: Fri, 27 Sep 2024 17:03:56 +0200 Subject: [PATCH 3/8] Added back check for empty set of partitions after pruning --- pkg/planner/core/find_best_task.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/pkg/planner/core/find_best_task.go b/pkg/planner/core/find_best_task.go index a8faba054d96e..7235fe2da9011 100644 --- a/pkg/planner/core/find_best_task.go +++ b/pkg/planner/core/find_best_task.go @@ -2253,7 +2253,11 @@ func (is *PhysicalIndexScan) addSelectionConditionForGlobalIndex(p *logicalop.Da } needNot := false pInfo := p.TableInfo.GetPartitionInfo() - if len(idxArr) == 1 && idxArr[0] == FullRange { + if len(idxArr) == 0 { + // TODO: Can we change to Table Dual somehow? + // Add an invalid pid as param for `IN` function + args = append(args, expression.NewInt64Const(-1)) + } else if len(idxArr) == 1 && idxArr[0] == FullRange { // Filter away partitions that may exists in Global Index, // but should not be seen. needNot = true From e9424d8d148b71b5e4fca14ac74e343e961b3a65 Mon Sep 17 00:00:00 2001 From: Mattias Jonsson Date: Fri, 27 Sep 2024 17:06:48 +0200 Subject: [PATCH 4/8] reshuffled code --- pkg/planner/core/find_best_task.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/pkg/planner/core/find_best_task.go b/pkg/planner/core/find_best_task.go index 7235fe2da9011..cfa12ceb58c75 100644 --- a/pkg/planner/core/find_best_task.go +++ b/pkg/planner/core/find_best_task.go @@ -2253,17 +2253,17 @@ func (is *PhysicalIndexScan) addSelectionConditionForGlobalIndex(p *logicalop.Da } needNot := false pInfo := p.TableInfo.GetPartitionInfo() - if len(idxArr) == 0 { - // TODO: Can we change to Table Dual somehow? - // Add an invalid pid as param for `IN` function - args = append(args, expression.NewInt64Const(-1)) - } else if len(idxArr) == 1 && idxArr[0] == FullRange { + if len(idxArr) == 1 && idxArr[0] == FullRange { // Filter away partitions that may exists in Global Index, // but should not be seen. needNot = true for _, id := range pInfo.IDsInDDLToIgnore() { args = append(args, expression.NewInt64Const(id)) } + } else if len(idxArr) == 0 { + // TODO: Can we change to Table Dual somehow? + // Add an invalid pid as param for `IN` function + args = append(args, expression.NewInt64Const(-1)) } else { ignoreMap := make(map[int64]struct{}) for _, id := range pInfo.IDsInDDLToIgnore() { From c4f0a130968c22419d422202527c400fee051be1 Mon Sep 17 00:00:00 2001 From: Mattias Jonsson Date: Fri, 27 Sep 2024 17:09:43 +0200 Subject: [PATCH 5/8] Added todo comment --- pkg/planner/core/find_best_task.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pkg/planner/core/find_best_task.go b/pkg/planner/core/find_best_task.go index cfa12ceb58c75..ddba95e33b712 100644 --- a/pkg/planner/core/find_best_task.go +++ b/pkg/planner/core/find_best_task.go @@ -2265,6 +2265,8 @@ func (is *PhysicalIndexScan) addSelectionConditionForGlobalIndex(p *logicalop.Da // Add an invalid pid as param for `IN` function args = append(args, expression.NewInt64Const(-1)) } else { + // TODO: When PartitionPruning is guaranteed to not + // return old/blocked partition ids then this can be removed. ignoreMap := make(map[int64]struct{}) for _, id := range pInfo.IDsInDDLToIgnore() { ignoreMap[id] = struct{}{} From 3a1271a5e807dfbfdd344b9a3ea9a26a7db6ecf8 Mon Sep 17 00:00:00 2001 From: Mattias Jonsson Date: Fri, 27 Sep 2024 17:13:20 +0200 Subject: [PATCH 6/8] Clarified comment --- pkg/planner/core/find_best_task.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/planner/core/find_best_task.go b/pkg/planner/core/find_best_task.go index ddba95e33b712..9f53e561a586e 100644 --- a/pkg/planner/core/find_best_task.go +++ b/pkg/planner/core/find_best_task.go @@ -2266,7 +2266,7 @@ func (is *PhysicalIndexScan) addSelectionConditionForGlobalIndex(p *logicalop.Da args = append(args, expression.NewInt64Const(-1)) } else { // TODO: When PartitionPruning is guaranteed to not - // return old/blocked partition ids then this can be removed. + // return old/blocked partition ids then ignoreMap can be removed. ignoreMap := make(map[int64]struct{}) for _, id := range pInfo.IDsInDDLToIgnore() { ignoreMap[id] = struct{}{} From 5d0903e137bc5c1a729d2fc430671e6131d1cfaa Mon Sep 17 00:00:00 2001 From: Mattias Jonsson Date: Fri, 4 Oct 2024 13:10:43 +0200 Subject: [PATCH 7/8] Added intest assertion --- pkg/planner/core/find_best_task.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/pkg/planner/core/find_best_task.go b/pkg/planner/core/find_best_task.go index 9f53e561a586e..59d59e76ed4c7 100644 --- a/pkg/planner/core/find_best_task.go +++ b/pkg/planner/core/find_best_task.go @@ -17,6 +17,7 @@ package core import ( "cmp" "fmt" + "github.com/pingcap/tidb/pkg/util/intest" "math" "slices" "strings" @@ -2275,6 +2276,8 @@ func (is *PhysicalIndexScan) addSelectionConditionForGlobalIndex(p *logicalop.Da id := pInfo.Definitions[idx].ID if _, ok := ignoreMap[id]; !ok { args = append(args, expression.NewInt64Const(id)) + } else if intest.InTest { + panic("PartitionPruning returns partitions which should be ignored!") } } } From d4b94fc142aca44719fbe9402e925184a02db072 Mon Sep 17 00:00:00 2001 From: Mattias Jonsson Date: Fri, 4 Oct 2024 23:33:46 +0200 Subject: [PATCH 8/8] Linting --- pkg/planner/core/find_best_task.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/planner/core/find_best_task.go b/pkg/planner/core/find_best_task.go index 035ab7c98793f..e4c531633fc35 100644 --- a/pkg/planner/core/find_best_task.go +++ b/pkg/planner/core/find_best_task.go @@ -17,7 +17,6 @@ package core import ( "cmp" "fmt" - "github.com/pingcap/tidb/pkg/util/intest" "math" "slices" "strings" @@ -44,6 +43,7 @@ import ( "github.com/pingcap/tidb/pkg/util/chunk" "github.com/pingcap/tidb/pkg/util/collate" h "github.com/pingcap/tidb/pkg/util/hint" + "github.com/pingcap/tidb/pkg/util/intest" "github.com/pingcap/tidb/pkg/util/logutil" "github.com/pingcap/tidb/pkg/util/ranger" "github.com/pingcap/tidb/pkg/util/tracing"