@@ -28,7 +28,6 @@ import (
28
28
"github.com/pingcap/tidb/parser/mysql"
29
29
"github.com/pingcap/tidb/sessionctx/stmtctx"
30
30
"github.com/pingcap/tidb/sessionctx/variable"
31
- "github.com/pingcap/tidb/statistics"
32
31
"github.com/pingcap/tidb/tablecodec"
33
32
"github.com/pingcap/tidb/types"
34
33
"github.com/pingcap/tidb/util/codec"
@@ -86,9 +85,9 @@ func (builder *RequestBuilder) SetMemTracker(tracker *memory.Tracker) *RequestBu
86
85
// to "KeyRanges" firstly.
87
86
// Note this function should be deleted or at least not exported, but currently
88
87
// br refers it, so have to keep it.
89
- func (builder * RequestBuilder ) SetTableRanges (tid int64 , tableRanges []* ranger.Range , fb * statistics. QueryFeedback ) * RequestBuilder {
88
+ func (builder * RequestBuilder ) SetTableRanges (tid int64 , tableRanges []* ranger.Range ) * RequestBuilder {
90
89
if builder .err == nil {
91
- builder .Request .KeyRanges = kv .NewNonParitionedKeyRanges (TableRangesToKVRanges (tid , tableRanges , fb ))
90
+ builder .Request .KeyRanges = kv .NewNonParitionedKeyRanges (TableRangesToKVRanges (tid , tableRanges ))
92
91
}
93
92
return builder
94
93
}
@@ -97,7 +96,7 @@ func (builder *RequestBuilder) SetTableRanges(tid int64, tableRanges []*ranger.R
97
96
// "ranges" to "KeyRanges" firstly.
98
97
func (builder * RequestBuilder ) SetIndexRanges (sc * stmtctx.StatementContext , tid , idxID int64 , ranges []* ranger.Range ) * RequestBuilder {
99
98
if builder .err == nil {
100
- builder .Request .KeyRanges , builder .err = IndexRangesToKVRanges (sc , tid , idxID , ranges , nil )
99
+ builder .Request .KeyRanges , builder .err = IndexRangesToKVRanges (sc , tid , idxID , ranges )
101
100
}
102
101
return builder
103
102
}
@@ -106,24 +105,24 @@ func (builder *RequestBuilder) SetIndexRanges(sc *stmtctx.StatementContext, tid,
106
105
// "ranges" to "KeyRanges" firstly.
107
106
func (builder * RequestBuilder ) SetIndexRangesForTables (sc * stmtctx.StatementContext , tids []int64 , idxID int64 , ranges []* ranger.Range ) * RequestBuilder {
108
107
if builder .err == nil {
109
- builder .Request .KeyRanges , builder .err = IndexRangesToKVRangesForTables (sc , tids , idxID , ranges , nil )
108
+ builder .Request .KeyRanges , builder .err = IndexRangesToKVRangesForTables (sc , tids , idxID , ranges )
110
109
}
111
110
return builder
112
111
}
113
112
114
113
// SetHandleRanges sets "KeyRanges" for "kv.Request" by converting table handle range
115
114
// "ranges" to "KeyRanges" firstly.
116
- func (builder * RequestBuilder ) SetHandleRanges (sc * stmtctx.StatementContext , tid int64 , isCommonHandle bool , ranges []* ranger.Range , fb * statistics. QueryFeedback ) * RequestBuilder {
117
- builder = builder .SetHandleRangesForTables (sc , []int64 {tid }, isCommonHandle , ranges , fb )
115
+ func (builder * RequestBuilder ) SetHandleRanges (sc * stmtctx.StatementContext , tid int64 , isCommonHandle bool , ranges []* ranger.Range ) * RequestBuilder {
116
+ builder = builder .SetHandleRangesForTables (sc , []int64 {tid }, isCommonHandle , ranges )
118
117
builder .err = builder .Request .KeyRanges .SetToNonPartitioned ()
119
118
return builder
120
119
}
121
120
122
121
// SetHandleRangesForTables sets "KeyRanges" for "kv.Request" by converting table handle range
123
122
// "ranges" to "KeyRanges" firstly for multiple tables.
124
- func (builder * RequestBuilder ) SetHandleRangesForTables (sc * stmtctx.StatementContext , tid []int64 , isCommonHandle bool , ranges []* ranger.Range , fb * statistics. QueryFeedback ) * RequestBuilder {
123
+ func (builder * RequestBuilder ) SetHandleRangesForTables (sc * stmtctx.StatementContext , tid []int64 , isCommonHandle bool , ranges []* ranger.Range ) * RequestBuilder {
125
124
if builder .err == nil {
126
- builder .Request .KeyRanges , builder .err = TableHandleRangesToKVRanges (sc , tid , isCommonHandle , ranges , fb )
125
+ builder .Request .KeyRanges , builder .err = TableHandleRangesToKVRanges (sc , tid , isCommonHandle , ranges )
127
126
}
128
127
return builder
129
128
}
@@ -435,55 +434,26 @@ func (builder *RequestBuilder) SetConnID(connID uint64) *RequestBuilder {
435
434
}
436
435
437
436
// TableHandleRangesToKVRanges convert table handle ranges to "KeyRanges" for multiple tables.
438
- func TableHandleRangesToKVRanges (sc * stmtctx.StatementContext , tid []int64 , isCommonHandle bool , ranges []* ranger.Range , fb * statistics. QueryFeedback ) (* kv.KeyRanges , error ) {
437
+ func TableHandleRangesToKVRanges (sc * stmtctx.StatementContext , tid []int64 , isCommonHandle bool , ranges []* ranger.Range ) (* kv.KeyRanges , error ) {
439
438
if ! isCommonHandle {
440
- return tablesRangesToKVRanges (tid , ranges , fb ), nil
439
+ return tablesRangesToKVRanges (tid , ranges ), nil
441
440
}
442
441
return CommonHandleRangesToKVRanges (sc , tid , ranges )
443
442
}
444
443
445
444
// TableRangesToKVRanges converts table ranges to "KeyRange".
446
445
// Note this function should not be exported, but currently
447
446
// br refers to it, so have to keep it.
448
- func TableRangesToKVRanges (tid int64 , ranges []* ranger.Range , fb * statistics. QueryFeedback ) []kv.KeyRange {
447
+ func TableRangesToKVRanges (tid int64 , ranges []* ranger.Range ) []kv.KeyRange {
449
448
if len (ranges ) == 0 {
450
449
return []kv.KeyRange {}
451
450
}
452
- return tablesRangesToKVRanges ([]int64 {tid }, ranges , fb ).FirstPartitionRange ()
451
+ return tablesRangesToKVRanges ([]int64 {tid }, ranges ).FirstPartitionRange ()
453
452
}
454
453
455
454
// tablesRangesToKVRanges converts table ranges to "KeyRange".
456
- func tablesRangesToKVRanges (tids []int64 , ranges []* ranger.Range , fb * statistics.QueryFeedback ) * kv.KeyRanges {
457
- if fb == nil || fb .Hist == nil {
458
- return tableRangesToKVRangesWithoutSplit (tids , ranges )
459
- }
460
- // The following codes are deprecated since the feedback is deprecated.
461
- krs := make ([]kv.KeyRange , 0 , len (ranges ))
462
- feedbackRanges := make ([]* ranger.Range , 0 , len (ranges ))
463
- for _ , ran := range ranges {
464
- low := codec .EncodeInt (nil , ran .LowVal [0 ].GetInt64 ())
465
- high := codec .EncodeInt (nil , ran .HighVal [0 ].GetInt64 ())
466
- if ran .LowExclude {
467
- low = kv .Key (low ).PrefixNext ()
468
- }
469
- // If this range is split by histogram, then the high val will equal to one bucket's upper bound,
470
- // since we need to guarantee each range falls inside the exactly one bucket, `PrefixNext` will make the
471
- // high value greater than upper bound, so we store the range here.
472
- r := & ranger.Range {LowVal : []types.Datum {types .NewBytesDatum (low )},
473
- HighVal : []types.Datum {types .NewBytesDatum (high )}, Collators : collate .GetBinaryCollatorSlice (1 )}
474
- feedbackRanges = append (feedbackRanges , r )
475
-
476
- if ! ran .HighExclude {
477
- high = kv .Key (high ).PrefixNext ()
478
- }
479
- for _ , tid := range tids {
480
- startKey := tablecodec .EncodeRowKey (tid , low )
481
- endKey := tablecodec .EncodeRowKey (tid , high )
482
- krs = append (krs , kv.KeyRange {StartKey : startKey , EndKey : endKey })
483
- }
484
- }
485
- fb .StoreRanges (feedbackRanges )
486
- return kv .NewNonParitionedKeyRanges (krs )
455
+ func tablesRangesToKVRanges (tids []int64 , ranges []* ranger.Range ) * kv.KeyRanges {
456
+ return tableRangesToKVRangesWithoutSplit (tids , ranges )
487
457
}
488
458
489
459
func tableRangesToKVRangesWithoutSplit (tids []int64 , ranges []* ranger.Range ) * kv.KeyRanges {
@@ -656,14 +626,14 @@ func PartitionHandlesToKVRanges(handles []kv.Handle) ([]kv.KeyRange, []int) {
656
626
}
657
627
658
628
// IndexRangesToKVRanges converts index ranges to "KeyRange".
659
- func IndexRangesToKVRanges (sc * stmtctx.StatementContext , tid , idxID int64 , ranges []* ranger.Range , fb * statistics. QueryFeedback ) (* kv.KeyRanges , error ) {
660
- return IndexRangesToKVRangesWithInterruptSignal (sc , tid , idxID , ranges , fb , nil , nil )
629
+ func IndexRangesToKVRanges (sc * stmtctx.StatementContext , tid , idxID int64 , ranges []* ranger.Range ) (* kv.KeyRanges , error ) {
630
+ return IndexRangesToKVRangesWithInterruptSignal (sc , tid , idxID , ranges , nil , nil )
661
631
}
662
632
663
633
// IndexRangesToKVRangesWithInterruptSignal converts index ranges to "KeyRange".
664
634
// The process can be interrupted by set `interruptSignal` to true.
665
- func IndexRangesToKVRangesWithInterruptSignal (sc * stmtctx.StatementContext , tid , idxID int64 , ranges []* ranger.Range , fb * statistics. QueryFeedback , memTracker * memory.Tracker , interruptSignal * atomic.Value ) (* kv.KeyRanges , error ) {
666
- keyRanges , err := indexRangesToKVRangesForTablesWithInterruptSignal (sc , []int64 {tid }, idxID , ranges , fb , memTracker , interruptSignal )
635
+ func IndexRangesToKVRangesWithInterruptSignal (sc * stmtctx.StatementContext , tid , idxID int64 , ranges []* ranger.Range , memTracker * memory.Tracker , interruptSignal * atomic.Value ) (* kv.KeyRanges , error ) {
636
+ keyRanges , err := indexRangesToKVRangesForTablesWithInterruptSignal (sc , []int64 {tid }, idxID , ranges , memTracker , interruptSignal )
667
637
if err != nil {
668
638
return nil , err
669
639
}
@@ -672,52 +642,14 @@ func IndexRangesToKVRangesWithInterruptSignal(sc *stmtctx.StatementContext, tid,
672
642
}
673
643
674
644
// IndexRangesToKVRangesForTables converts indexes ranges to "KeyRange".
675
- func IndexRangesToKVRangesForTables (sc * stmtctx.StatementContext , tids []int64 , idxID int64 , ranges []* ranger.Range , fb * statistics. QueryFeedback ) (* kv.KeyRanges , error ) {
676
- return indexRangesToKVRangesForTablesWithInterruptSignal (sc , tids , idxID , ranges , fb , nil , nil )
645
+ func IndexRangesToKVRangesForTables (sc * stmtctx.StatementContext , tids []int64 , idxID int64 , ranges []* ranger.Range ) (* kv.KeyRanges , error ) {
646
+ return indexRangesToKVRangesForTablesWithInterruptSignal (sc , tids , idxID , ranges , nil , nil )
677
647
}
678
648
679
649
// IndexRangesToKVRangesForTablesWithInterruptSignal converts indexes ranges to "KeyRange".
680
650
// The process can be interrupted by set `interruptSignal` to true.
681
- func indexRangesToKVRangesForTablesWithInterruptSignal (sc * stmtctx.StatementContext , tids []int64 , idxID int64 , ranges []* ranger.Range , fb * statistics.QueryFeedback , memTracker * memory.Tracker , interruptSignal * atomic.Value ) (* kv.KeyRanges , error ) {
682
- if fb == nil || fb .Hist == nil {
683
- return indexRangesToKVWithoutSplit (sc , tids , idxID , ranges , memTracker , interruptSignal )
684
- }
685
- // The following code is non maintained since the feedback deprecated.
686
- feedbackRanges := make ([]* ranger.Range , 0 , len (ranges ))
687
- for _ , ran := range ranges {
688
- low , high , err := EncodeIndexKey (sc , ran )
689
- if err != nil {
690
- return nil , err
691
- }
692
- feedbackRanges = append (feedbackRanges , & ranger.Range {LowVal : []types.Datum {types .NewBytesDatum (low )},
693
- HighVal : []types.Datum {types .NewBytesDatum (high )}, LowExclude : false , HighExclude : true , Collators : collate .GetBinaryCollatorSlice (1 )})
694
- }
695
- feedbackRanges , ok := fb .Hist .SplitRange (sc , feedbackRanges , true )
696
- if ! ok {
697
- fb .Invalidate ()
698
- }
699
- krs := make ([]kv.KeyRange , 0 , len (feedbackRanges ))
700
- for _ , ran := range feedbackRanges {
701
- low , high := ran .LowVal [0 ].GetBytes (), ran .HighVal [0 ].GetBytes ()
702
- if ran .LowExclude {
703
- low = kv .Key (low ).PrefixNext ()
704
- }
705
- ran .LowVal [0 ].SetBytes (low )
706
- // If this range is split by histogram, then the high val will equal to one bucket's upper bound,
707
- // since we need to guarantee each range falls inside the exactly one bucket, `PrefixNext` will make the
708
- // high value greater than upper bound, so we store the high value here.
709
- ran .HighVal [0 ].SetBytes (high )
710
- if ! ran .HighExclude {
711
- high = kv .Key (high ).PrefixNext ()
712
- }
713
- for _ , tid := range tids {
714
- startKey := tablecodec .EncodeIndexSeekKey (tid , idxID , low )
715
- endKey := tablecodec .EncodeIndexSeekKey (tid , idxID , high )
716
- krs = append (krs , kv.KeyRange {StartKey : startKey , EndKey : endKey })
717
- }
718
- }
719
- fb .StoreRanges (feedbackRanges )
720
- return kv .NewNonParitionedKeyRanges (krs ), nil
651
+ func indexRangesToKVRangesForTablesWithInterruptSignal (sc * stmtctx.StatementContext , tids []int64 , idxID int64 , ranges []* ranger.Range , memTracker * memory.Tracker , interruptSignal * atomic.Value ) (* kv.KeyRanges , error ) {
652
+ return indexRangesToKVWithoutSplit (sc , tids , idxID , ranges , memTracker , interruptSignal )
721
653
}
722
654
723
655
// CommonHandleRangesToKVRanges converts common handle ranges to "KeyRange".
0 commit comments