@@ -825,26 +825,26 @@ func intersectionRange(start, end, newStart, newEnd int) (int, int) {
825
825
}
826
826
827
827
func (s * partitionProcessor ) pruneRangePartition (ctx sessionctx.Context , pi * model.PartitionInfo , tbl table.PartitionedTable , conds []expression.Expression ,
828
- columns []* expression.Column , names types.NameSlice , condsToBePruned * []expression. Expression ) (partitionRangeOR , []expression. Expression , error ) {
828
+ columns []* expression.Column , names types.NameSlice ) (partitionRangeOR , error ) {
829
829
partExpr , err := tbl .(partitionTable ).PartitionExpr ()
830
830
if err != nil {
831
- return nil , nil , err
831
+ return nil , err
832
832
}
833
833
834
834
// Partition by range columns.
835
835
if len (pi .Columns ) > 0 {
836
836
result , err := s .pruneRangeColumnsPartition (ctx , conds , pi , partExpr , columns , names )
837
- return result , nil , err
837
+ return result , err
838
838
}
839
839
840
840
// Partition by range.
841
841
col , fn , mono , err := makePartitionByFnCol (ctx , columns , names , pi .Expr )
842
842
if err != nil {
843
- return nil , nil , err
843
+ return nil , err
844
844
}
845
845
result := fullRange (len (pi .Definitions ))
846
846
if col == nil {
847
- return result , nil , nil
847
+ return result , nil
848
848
}
849
849
850
850
// Extract the partition column, if the column is not null, it's possible to prune.
@@ -859,41 +859,14 @@ func (s *partitionProcessor) pruneRangePartition(ctx sessionctx.Context, pi *mod
859
859
}
860
860
result = partitionRangeForCNFExpr (ctx , conds , & pruner , result )
861
861
862
- if condsToBePruned == nil {
863
- return result , nil , nil
864
- }
865
- // remove useless predicates after pruning
866
- newConds := make ([]expression.Expression , 0 , len (* condsToBePruned ))
867
- for _ , cond := range * condsToBePruned {
868
- if dataForPrune , ok := pruner .extractDataForPrune (ctx , cond ); ok {
869
- switch dataForPrune .op {
870
- case ast .EQ :
871
- unsigned := mysql .HasUnsignedFlag (pruner .col .RetType .GetFlag ())
872
- start , _ := pruneUseBinarySearch (pruner .lessThan , dataForPrune , unsigned )
873
- // if the type of partition key is Int
874
- if pk , ok := partExpr .Expr .(* expression.Column ); ok && pk .RetType .EvalType () == types .ETInt {
875
- // see if can be removed
876
- // see issue #22079: https://github.com/pingcap/tidb/issues/22079 for details
877
- if start > 0 && pruner .lessThan .data [start - 1 ] == dataForPrune .c && (pruner .lessThan .data [start ]- 1 ) == dataForPrune .c {
878
- continue
879
- }
880
- }
881
- }
882
- }
883
- newConds = append (newConds , cond )
884
- }
885
-
886
- return result , newConds , nil
862
+ return result , nil
887
863
}
888
864
889
865
func (s * partitionProcessor ) processRangePartition (ds * DataSource , pi * model.PartitionInfo , opt * logicalOptimizeOp ) (LogicalPlan , error ) {
890
- used , prunedConds , err := s .pruneRangePartition (ds .ctx , pi , ds .table .(table.PartitionedTable ), ds .allConds , ds .TblCols , ds .names , & ds . pushedDownConds )
866
+ used , err := s .pruneRangePartition (ds .ctx , pi , ds .table .(table.PartitionedTable ), ds .allConds , ds .TblCols , ds .names )
891
867
if err != nil {
892
868
return nil , err
893
869
}
894
- if prunedConds != nil {
895
- ds .pushedDownConds = prunedConds
896
- }
897
870
return s .makeUnionAllChildren (ds , pi , used , opt )
898
871
}
899
872
@@ -1280,11 +1253,13 @@ func relaxOP(op string) string {
1280
1253
return op
1281
1254
}
1282
1255
1256
+ // pruneUseBinarySearch returns the start and end of which partitions will match.
1257
+ // If no match (i.e. value > last partition) the start partition will be the number of partition, not the first partition!
1283
1258
func pruneUseBinarySearch (lessThan lessThanDataInt , data dataForPrune , unsigned bool ) (start int , end int ) {
1284
1259
length := lessThan .length ()
1285
1260
switch data .op {
1286
1261
case ast .EQ :
1287
- // col = 66, lessThan = [4 7 11 14 17] => [5, 6 )
1262
+ // col = 66, lessThan = [4 7 11 14 17] => [5, 5 )
1288
1263
// col = 14, lessThan = [4 7 11 14 17] => [4, 5)
1289
1264
// col = 10, lessThan = [4 7 11 14 17] => [2, 3)
1290
1265
// col = 3, lessThan = [4 7 11 14 17] => [0, 1)
@@ -1590,6 +1565,8 @@ func (p *rangeColumnsPruner) partitionRangeForExpr(sctx sessionctx.Context, expr
1590
1565
return start , end , true
1591
1566
}
1592
1567
1568
+ // pruneUseBinarySearch returns the start and end of which partitions will match.
1569
+ // If no match (i.e. value > last partition) the start partition will be the number of partition, not the first partition!
1593
1570
func (p * rangeColumnsPruner ) pruneUseBinarySearch (sctx sessionctx.Context , op string , data * expression.Constant ) (start int , end int ) {
1594
1571
var err error
1595
1572
var isNull bool
0 commit comments