1717
1818package org .apache .doris .nereids .rules .expression .rules ;
1919
20- import org .apache .doris .analysis .LiteralExpr ;
2120import org .apache .doris .catalog .ListPartitionItem ;
2221import org .apache .doris .catalog .PartitionInfo ;
2322import org .apache .doris .catalog .PartitionItem ;
24- import org .apache .doris .catalog .PartitionKey ;
2523import org .apache .doris .catalog .RangePartitionItem ;
2624import org .apache .doris .nereids .CascadesContext ;
2725import org .apache .doris .nereids .trees .expressions .Cast ;
@@ -118,12 +116,6 @@ public static List<Long> prune(List<Slot> partitionSlots, Expression partitionPr
118116 PartitionTableType partitionTableType ) {
119117 partitionPredicate = TryEliminateUninterestedPredicates .rewrite (
120118 partitionPredicate , ImmutableSet .copyOf (partitionSlots ), cascadesContext );
121- if (cascadesContext .getConnectContext ().getSessionVariable ().inToMinmaxParitionRewriteThreshold > 0
122- && canRewriteToMinMax (idToPartitions )) {
123- double rangeLength = totalRangeLength (idToPartitions );
124- partitionPredicate = rewritePartitionPredicateForRangePartition (
125- partitionPredicate , rangeLength , cascadesContext );
126- }
127119
128120 List <OnePartitionEvaluator > evaluators = idToPartitions .entrySet ()
129121 .stream ()
@@ -136,85 +128,6 @@ && canRewriteToMinMax(idToPartitions)) {
136128 return partitionPruner .prune ();
137129 }
138130
139- private static boolean isRangePartition (Map <Long , PartitionItem > idToPartitions ) {
140- if (idToPartitions .isEmpty ()) {
141- return false ;
142- }
143- PartitionItem item = idToPartitions .values ().iterator ().next ();
144- return item instanceof RangePartitionItem ;
145- }
146-
147- private static boolean canRewriteToMinMax (Map <Long , PartitionItem > idToPartitions ) {
148- if (isRangePartition (idToPartitions )) {
149- RangePartitionItem item = (RangePartitionItem ) idToPartitions .values ().iterator ().next ();
150- if (item == null ) {
151- return false ;
152- }
153- PartitionKey k1 = item .getItems ().upperEndpoint ();
154- if (k1 .getKeys ().size () != 1 ) {
155- return false ; // multi keys or hive keys
156- }
157- LiteralExpr bound = k1 .getKeys ().get (0 );
158- if (bound instanceof org .apache .doris .analysis .DateLiteral ) {
159- return true ;
160- }
161- }
162- return false ;
163- }
164-
165- private static double getUpperBoundFromRangePartitionItem (RangePartitionItem item ) {
166- org .apache .doris .analysis .DateLiteral d1 =
167- (org .apache .doris .analysis .DateLiteral ) item .getItems ().upperEndpoint ().getKeys ().get (0 );
168- return d1 .getDouble ();
169- }
170-
171- private static double getLowerBoundFromRangePartitionItem (RangePartitionItem item ) {
172- org .apache .doris .analysis .DateLiteral d1 =
173- (org .apache .doris .analysis .DateLiteral ) item .getItems ().lowerEndpoint ().getKeys ().get (0 );
174- return d1 .getDouble ();
175- }
176-
177- // for range partition, total range is from the end of the first partition to the beginning of the last partition
178- private static double totalRangeLength (Map <Long , PartitionItem > idToPartitions ) {
179- if (idToPartitions .size () == 1 ) {
180- Long id = idToPartitions .keySet ().iterator ().next ();
181- RangePartitionItem item = (RangePartitionItem ) idToPartitions .get (id );
182- double d1 = getUpperBoundFromRangePartitionItem (item );
183- double d2 = getLowerBoundFromRangePartitionItem (item );
184- return Math .max (1 , d1 - d2 );
185- }
186-
187- Long id = idToPartitions .keySet ().iterator ().next ();
188- RangePartitionItem firstItem = (RangePartitionItem ) idToPartitions .get (id );
189- RangePartitionItem lastItem = firstItem ;
190- double min = getLowerBoundFromRangePartitionItem (firstItem );
191- double max = getUpperBoundFromRangePartitionItem (lastItem );
192- for (Long pid : idToPartitions .keySet ()) {
193- RangePartitionItem item = (RangePartitionItem ) idToPartitions .get (pid );
194- double lower = getLowerBoundFromRangePartitionItem (item );
195- if (lower < min ) {
196- min = lower ;
197- firstItem = item ;
198- } else {
199- double upper = getUpperBoundFromRangePartitionItem (item );
200- if (upper > max ) {
201- max = upper ;
202- lastItem = item ;
203- }
204- }
205- }
206- double endOfFirstItem = getUpperBoundFromRangePartitionItem (firstItem );
207- double beginOfLastItem = getLowerBoundFromRangePartitionItem (lastItem );
208- return Math .max (1 , beginOfLastItem - endOfFirstItem );
209- }
210-
211- private static Expression rewritePartitionPredicateForRangePartition (Expression partitionPredicate , double range ,
212- CascadesContext ctx ) {
213- partitionPredicate = OrToIn .INSTANCE .rewrite (partitionPredicate , null );
214- RewriteRangePartitionPredicate rewriter = new RewriteRangePartitionPredicate (range );
215- return partitionPredicate .accept (rewriter , ctx );
216- }
217-
218131 /**
219132 * convert partition item to partition evaluator
220133 */
0 commit comments