@@ -664,15 +664,18 @@ handle_binary_opexpr(const PartRelationInfo *prel, WrapperNode *result,
664
664
cmp_min = FunctionCall2 (cmp_func ,value ,ranges [0 ].min ),
665
665
cmp_max = FunctionCall2 (cmp_func ,value ,ranges [rangerel -> ranges .length - 1 ].max );
666
666
667
- if ((cmp_min < 0 && strategy == BTLessEqualStrategyNumber )||
667
+ if ((cmp_min < 0 &&
668
+ (strategy == BTLessEqualStrategyNumber ||
669
+ strategy == BTEqualStrategyNumber ))||
668
670
(cmp_min <=0 && strategy == BTLessStrategyNumber ))
669
671
{
670
672
result -> rangeset = NIL ;
671
673
return ;
672
674
}
673
675
674
676
if (cmp_max >=0 && (strategy == BTGreaterEqualStrategyNumber ||
675
- strategy == BTGreaterStrategyNumber ))
677
+ strategy == BTGreaterStrategyNumber ||
678
+ strategy == BTEqualStrategyNumber ))
676
679
{
677
680
result -> rangeset = NIL ;
678
681
return ;
@@ -800,12 +803,21 @@ range_binary_search(const RangeRelation *rangerel, FmgrInfo *cmp_func, Datum val
800
803
RangeEntry * re ;
801
804
int cmp_min ,
802
805
cmp_max ,
803
- i ,
806
+ i = 0 ,
804
807
startidx = 0 ,
805
808
endidx = rangerel -> ranges .length - 1 ,
806
809
counter = 0 ;
807
810
808
811
* foundPtr = false;
812
+
813
+ /* Check boundaries */
814
+ cmp_min = FunctionCall2 (cmp_func ,value ,ranges [0 ].min ),
815
+ cmp_max = FunctionCall2 (cmp_func ,value ,ranges [rangerel -> ranges .length - 1 ].max );
816
+ if (cmp_min < 0 || cmp_max > 0 )
817
+ {
818
+ return i ;
819
+ }
820
+
809
821
while (true)
810
822
{
811
823
i = startidx + (endidx - startidx ) /2 ;