@@ -1423,15 +1423,6 @@ func (ds *DataSource) FindBestTask(prop *property.PhysicalProperty, planCounter
1423
1423
}
1424
1424
}
1425
1425
if canConvertPointGet {
1426
- // If the schema contains ExtraPidColID, do not convert to point get.
1427
- // Because the point get executor can not handle the extra partition ID column now.
1428
- // I.e. Global Index is used
1429
- for _ , col := range ds .schema .Columns {
1430
- if col .ID == model .ExtraPidColID {
1431
- canConvertPointGet = false
1432
- break
1433
- }
1434
- }
1435
1426
if path != nil && path .Index != nil && path .Index .Global {
1436
1427
// Don't convert to point get during ddl
1437
1428
// TODO: Revisit truncate partition and global index
@@ -2148,6 +2139,15 @@ func (is *PhysicalIndexScan) initSchema(idxExprCols []*expression.Column, isDoub
2148
2139
}
2149
2140
}
2150
2141
2142
+ var extraPhysTblCol * expression.Column
2143
+ // If `dataSouceSchema` contains `model.ExtraPhysTblID`, we should add it into `indexScan.schema`
2144
+ for _ , col := range is .dataSourceSchema .Columns {
2145
+ if col .ID == model .ExtraPhysTblID {
2146
+ extraPhysTblCol = col .Clone ().(* expression.Column )
2147
+ break
2148
+ }
2149
+ }
2150
+
2151
2151
if isDoubleRead || is .Index .Global {
2152
2152
// If it's double read case, the first index must return handle. So we should add extra handle column
2153
2153
// if there isn't a handle column.
@@ -2161,23 +2161,19 @@ func (is *PhysicalIndexScan) initSchema(idxExprCols []*expression.Column, isDoub
2161
2161
})
2162
2162
}
2163
2163
}
2164
- // If it's global index, handle and PidColID columns has to be added, so that needed pids can be filtered.
2165
- if is .Index .Global {
2164
+ // If it's global index, handle and PhysTblID columns has to be added, so that needed pids can be filtered.
2165
+ if is .Index .Global && extraPhysTblCol == nil {
2166
2166
indexCols = append (indexCols , & expression.Column {
2167
2167
RetType : types .NewFieldType (mysql .TypeLonglong ),
2168
- ID : model .ExtraPidColID ,
2168
+ ID : model .ExtraPhysTblID ,
2169
2169
UniqueID : is .SCtx ().GetSessionVars ().AllocPlanColumnID (),
2170
- OrigName : model .ExtraPartitionIdName .O ,
2170
+ OrigName : model .ExtraPhysTblIdName .O ,
2171
2171
})
2172
2172
}
2173
2173
}
2174
2174
2175
- // If `dataSouceSchema` contains `model.ExtraPhysTblID`, we should add it into `indexScan.schema`
2176
- for _ , col := range is .dataSourceSchema .Columns {
2177
- if col .ID == model .ExtraPhysTblID {
2178
- indexCols = append (indexCols , col .Clone ().(* expression.Column ))
2179
- break
2180
- }
2175
+ if extraPhysTblCol != nil {
2176
+ indexCols = append (indexCols , extraPhysTblCol )
2181
2177
}
2182
2178
2183
2179
is .SetSchema (expression .NewSchema (indexCols ... ))
@@ -2189,14 +2185,14 @@ func (is *PhysicalIndexScan) addSelectionConditionForGlobalIndex(p *DataSource,
2189
2185
}
2190
2186
args := make ([]expression.Expression , 0 , len (p .partitionNames )+ 1 )
2191
2187
for _ , col := range is .schema .Columns {
2192
- if col .ID == model .ExtraPidColID {
2188
+ if col .ID == model .ExtraPhysTblID {
2193
2189
args = append (args , col .Clone ())
2194
2190
break
2195
2191
}
2196
2192
}
2197
2193
2198
2194
if len (args ) != 1 {
2199
- return nil , errors .Errorf ("Can't find column %s in schema %s" , model .ExtraPartitionIdName .O , is .schema )
2195
+ return nil , errors .Errorf ("Can't find column %s in schema %s" , model .ExtraPhysTblIdName .O , is .schema )
2200
2196
}
2201
2197
2202
2198
// For SQL like 'select x from t partition(p0, p1) use index(idx)',
0 commit comments