@@ -370,9 +370,13 @@ func (w *checkIndexWorker) initSessCtx() (sessionctx.Context, func(), error) {
370
370
sessVars := se .GetSessionVars ()
371
371
originOptUseInvisibleIdx := sessVars .OptimizerUseInvisibleIndexes
372
372
originMemQuotaQuery := sessVars .MemQuotaQuery
373
+ originSkipMissingPartitionStats := sessVars .SkipMissingPartitionStats
373
374
374
375
sessVars .OptimizerUseInvisibleIndexes = true
375
376
sessVars .MemQuotaQuery = w .sctx .GetSessionVars ().MemQuotaQuery
377
+ // Make sure using index scan for global index.
378
+ // See https://github.com/pingcap/tidb/blob/2010151c503c1a0b74d63e52a6019e03afada21d/pkg/planner/core/logical_plan_builder.go#L4506-L4518
379
+ sessVars .SkipMissingPartitionStats = true
376
380
snapshot := w .e .Ctx ().GetSessionVars ().SnapshotTS
377
381
if snapshot != 0 {
378
382
_ , err := se .GetSQLExecutor ().ExecuteInternal (w .e .contextCtx , fmt .Sprintf ("set session tidb_snapshot = %d" , snapshot ))
@@ -384,6 +388,7 @@ func (w *checkIndexWorker) initSessCtx() (sessionctx.Context, func(), error) {
384
388
return se , func () {
385
389
sessVars .OptimizerUseInvisibleIndexes = originOptUseInvisibleIdx
386
390
sessVars .MemQuotaQuery = originMemQuotaQuery
391
+ sessVars .SkipMissingPartitionStats = originSkipMissingPartitionStats
387
392
if snapshot != 0 {
388
393
_ , err := se .GetSQLExecutor ().ExecuteInternal (w .e .contextCtx , "set session tidb_snapshot = 0" )
389
394
if err != nil {
@@ -732,8 +737,7 @@ func (w *checkIndexWorker) handleTask(task checkIndexTask) error {
732
737
733
738
tableQuery = fmt .Sprintf (tableChecksumSQL , groupByKey , whereKey , groupByKey )
734
739
indexQuery = fmt .Sprintf (indexChecksumSQL , groupByKey , whereKey , groupByKey )
735
- verifyCheckQuery (ctx , se , tableQuery , true )
736
- verifyCheckQuery (ctx , se , indexQuery , false )
740
+ verifyIndexSideQuery (ctx , se , indexQuery )
737
741
738
742
logutil .BgLogger ().Info (
739
743
"fast check table by group" ,
@@ -813,8 +817,7 @@ func (w *checkIndexWorker) handleTask(task checkIndexTask) error {
813
817
groupByKey := fmt .Sprintf ("((CAST(%s AS SIGNED) - %d) MOD %d)" , md5Handle , offset , mod )
814
818
tableQuery = fmt .Sprintf (tableCheckSQL , groupByKey )
815
819
indexQuery = fmt .Sprintf (indexCheckSQL , groupByKey )
816
- verifyCheckQuery (ctx , se , tableQuery , true )
817
- verifyCheckQuery (ctx , se , indexQuery , false )
820
+ verifyIndexSideQuery (ctx , se , indexQuery )
818
821
819
822
var (
820
823
lastTableRecord * recordWithChecksum
@@ -901,7 +904,7 @@ type recordWithChecksum struct {
901
904
checksum uint64
902
905
}
903
906
904
- func verifyCheckQuery (ctx context.Context , se sessionctx.Context , sql string , useTableScan bool ) {
907
+ func verifyIndexSideQuery (ctx context.Context , se sessionctx.Context , sql string ) {
905
908
rows , err := queryToRow (ctx , se , "explain " + sql )
906
909
if err != nil {
907
910
panic (err )
@@ -918,7 +921,7 @@ func verifyCheckQuery(ctx context.Context, se sessionctx.Context, sql string, us
918
921
}
919
922
}
920
923
921
- if ( useTableScan && ! isTableScan ) || ( ! useTableScan && ! isIndexScan ) {
924
+ if isTableScan || ! isIndexScan {
922
925
panic (fmt .Sprintf ("check query %s error, table scan: %t, index scan: %t" ,
923
926
sql , isTableScan , isIndexScan ))
924
927
}
0 commit comments