@@ -455,41 +455,43 @@ select_range_partitions(const Datum value,
455455const int strategy ,
456456WrapperNode * result )
457457{
458- const RangeEntry * current_re ;
459- bool lossy = false,
460- is_less ,
461- is_greater ;
458+ bool lossy = false,
459+ is_less ,
460+ is_greater ;
462461
463462#ifdef USE_ASSERT_CHECKING
464- bool found = false;
465- int counter = 0 ;
463+ bool found = false;
464+ int counter = 0 ;
466465#endif
467466
468- int i ,
469- startidx = 0 ,
470- endidx = nranges - 1 ,
471- cmp_min ,
472- cmp_max ;
467+ int startidx = 0 ,
468+ endidx = nranges - 1 ,
469+ cmp_min ,
470+ cmp_max ,
471+ i ;
472+
473+ Bound value_bound = MakeBound (value );/* convert value to Bound */
474+
473475
474476/* Initial value (no missing partitions found) */
475477result -> found_gap = false;
476478
477- /* Checkboundaries */
479+ /* Check'ranges' array */
478480if (nranges == 0 )
479481{
480482result -> rangeset = NIL ;
481483return ;
482484}
485+
486+ /* Check corner cases */
483487else
484488{
485489Assert (ranges );
486490Assert (cmp_func );
487491
488- /* Corner cases */
489- cmp_min = IsInfinite (& ranges [startidx ].min ) ?
490- 1 :DatumGetInt32 (FunctionCall2 (cmp_func ,value ,BoundGetValue (& ranges [startidx ].min )));
491- cmp_max = IsInfinite (& ranges [endidx ].max ) ?
492- -1 :DatumGetInt32 (FunctionCall2 (cmp_func ,value ,BoundGetValue (& ranges [endidx ].max )));
492+ /* Compare 'value' to absolute MIN and MAX bounds */
493+ cmp_min = cmp_bounds (cmp_func ,& value_bound ,& ranges [startidx ].min );
494+ cmp_max = cmp_bounds (cmp_func ,& value_bound ,& ranges [endidx ].max );
493495
494496if ((cmp_min <=0 && strategy == BTLessStrategyNumber )||
495497(cmp_min < 0 && (strategy == BTLessEqualStrategyNumber ||
@@ -529,21 +531,16 @@ select_range_partitions(const Datum value,
529531/* Binary search */
530532while (true)
531533{
534+ Assert (ranges );
532535Assert (cmp_func );
533536
537+ /* Calculate new pivot */
534538i = startidx + (endidx - startidx ) /2 ;
535539Assert (i >=0 && i < nranges );
536540
537- current_re = & ranges [i ];
538-
539- cmp_min = IsInfinite (& current_re -> min ) ?
540- 1 :
541- FunctionCall2 (cmp_func ,value ,
542- BoundGetValue (& current_re -> min ));
543- cmp_max = IsInfinite (& current_re -> max ) ?
544- -1 :
545- FunctionCall2 (cmp_func ,value ,
546- BoundGetValue (& current_re -> max ));
541+ /* Compare 'value' to current MIN and MAX bounds */
542+ cmp_min = cmp_bounds (cmp_func ,& value_bound ,& ranges [i ].min );
543+ cmp_max = cmp_bounds (cmp_func ,& value_bound ,& ranges [i ].max );
547544
548545is_less = (cmp_min < 0 || (cmp_min == 0 && strategy == BTLessStrategyNumber ));
549546is_greater = (cmp_max > 0 || (cmp_max >=0 && strategy != BTLessStrategyNumber ));
@@ -556,13 +553,14 @@ select_range_partitions(const Datum value,
556553lossy = false;
557554else
558555lossy = true;
556+
559557#ifdef USE_ASSERT_CHECKING
560558found = true;
561559#endif
562560break ;
563561}
564562
565- /*If we still haven't found partition then it doesn't exist */
563+ /*Indices have met, looks like there's no partition */
566564if (startidx >=endidx )
567565{
568566result -> rangeset = NIL ;
@@ -579,6 +577,7 @@ select_range_partitions(const Datum value,
579577Assert (++ counter < 100 );
580578}
581579
580+ /* Should've been found by now */
582581Assert (found );
583582
584583/* Filter partitions */
@@ -638,8 +637,8 @@ wrapper_make_expression(WrapperNode *wrap, int index, bool *alwaysTrue)
638637
639638* alwaysTrue = false;
640639/*
641- * TODO: use faster algorithm using knowledge that we enumerate indexes
642- * sequntially.
640+ * TODO: use faster algorithm using knowledge
641+ *that we enumerate indexes sequntially.
643642 */
644643found = irange_list_find (wrap -> rangeset ,index ,& lossy );
645644
@@ -670,16 +669,19 @@ wrapper_make_expression(WrapperNode *wrap, int index, bool *alwaysTrue)
670669
671670arg = wrapper_make_expression ((WrapperNode * )lfirst (lc ),
672671index ,& childAlwaysTrue );
672+
673673#ifdef USE_ASSERT_CHECKING
674674/*
675- * We shouldn't get there for always true clause under OR and
676- * always false clause under AND.
675+ * We shouldn't get there for always true clause
676+ *under OR and always false clause under AND.
677677 */
678678if (expr -> boolop == OR_EXPR )
679679Assert (!childAlwaysTrue );
680+
680681if (expr -> boolop == AND_EXPR )
681682Assert (arg || childAlwaysTrue );
682683#endif
684+
683685if (arg )
684686args = lappend (args ,arg );
685687}