Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 5966bce

Browse files
committed
Make GiST index searches smarter about queries against empty ranges.
In the cases where the result of the called proc is negated, we should explicitly test both inputs for empty, to ensure we'll never return "true" for an unsatisfiable query. In other cases we can rely on the called proc to say the right thing.
1 parent 6c8768c commit 5966bce

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

src/backend/utils/adt/rangetypes_gist.c

+9-4
Original file line numberDiff line numberDiff line change
@@ -444,13 +444,13 @@ range_gist_consistent_int(FmgrInfo *flinfo, StrategyNumber strategy,
444444
switch (strategy)
445445
{
446446
case RANGESTRAT_BEFORE:
447-
if (RangeIsEmpty(key))
447+
if (RangeIsEmpty(key) || RangeIsEmpty(DatumGetRangeType(query)))
448448
return false;
449449
proc = range_overright;
450450
negate = true;
451451
break;
452452
case RANGESTRAT_OVERLEFT:
453-
if (RangeIsEmpty(key))
453+
if (RangeIsEmpty(key) || RangeIsEmpty(DatumGetRangeType(query)))
454454
return false;
455455
proc = range_after;
456456
negate = true;
@@ -459,13 +459,13 @@ range_gist_consistent_int(FmgrInfo *flinfo, StrategyNumber strategy,
459459
proc = range_overlaps;
460460
break;
461461
case RANGESTRAT_OVERRIGHT:
462-
if (RangeIsEmpty(key))
462+
if (RangeIsEmpty(key) || RangeIsEmpty(DatumGetRangeType(query)))
463463
return false;
464464
proc = range_before;
465465
negate = true;
466466
break;
467467
case RANGESTRAT_AFTER:
468-
if (RangeIsEmpty(key))
468+
if (RangeIsEmpty(key) || RangeIsEmpty(DatumGetRangeType(query)))
469469
return false;
470470
proc = range_overleft;
471471
negate = true;
@@ -483,6 +483,11 @@ range_gist_consistent_int(FmgrInfo *flinfo, StrategyNumber strategy,
483483
proc = range_contains;
484484
break;
485485
case RANGESTRAT_CONTAINED_BY:
486+
/*
487+
* Ideally we'd apply range_overlaps here, but at present it
488+
* might fail to find empty ranges in the index, which should
489+
* be reported as being contained by anything. This needs work.
490+
*/
486491
return true;
487492
break;
488493
case RANGESTRAT_CONTAINS_ELEM:

0 commit comments

Comments
 (0)