mirror of
https://github.com/postgres/postgres.git
synced 2025-08-06 18:42:54 +03:00
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.
This commit is contained in:
@@ -444,13 +444,13 @@ range_gist_consistent_int(FmgrInfo *flinfo, StrategyNumber strategy,
|
|||||||
switch (strategy)
|
switch (strategy)
|
||||||
{
|
{
|
||||||
case RANGESTRAT_BEFORE:
|
case RANGESTRAT_BEFORE:
|
||||||
if (RangeIsEmpty(key))
|
if (RangeIsEmpty(key) || RangeIsEmpty(DatumGetRangeType(query)))
|
||||||
return false;
|
return false;
|
||||||
proc = range_overright;
|
proc = range_overright;
|
||||||
negate = true;
|
negate = true;
|
||||||
break;
|
break;
|
||||||
case RANGESTRAT_OVERLEFT:
|
case RANGESTRAT_OVERLEFT:
|
||||||
if (RangeIsEmpty(key))
|
if (RangeIsEmpty(key) || RangeIsEmpty(DatumGetRangeType(query)))
|
||||||
return false;
|
return false;
|
||||||
proc = range_after;
|
proc = range_after;
|
||||||
negate = true;
|
negate = true;
|
||||||
@@ -459,13 +459,13 @@ range_gist_consistent_int(FmgrInfo *flinfo, StrategyNumber strategy,
|
|||||||
proc = range_overlaps;
|
proc = range_overlaps;
|
||||||
break;
|
break;
|
||||||
case RANGESTRAT_OVERRIGHT:
|
case RANGESTRAT_OVERRIGHT:
|
||||||
if (RangeIsEmpty(key))
|
if (RangeIsEmpty(key) || RangeIsEmpty(DatumGetRangeType(query)))
|
||||||
return false;
|
return false;
|
||||||
proc = range_before;
|
proc = range_before;
|
||||||
negate = true;
|
negate = true;
|
||||||
break;
|
break;
|
||||||
case RANGESTRAT_AFTER:
|
case RANGESTRAT_AFTER:
|
||||||
if (RangeIsEmpty(key))
|
if (RangeIsEmpty(key) || RangeIsEmpty(DatumGetRangeType(query)))
|
||||||
return false;
|
return false;
|
||||||
proc = range_overleft;
|
proc = range_overleft;
|
||||||
negate = true;
|
negate = true;
|
||||||
@@ -483,6 +483,11 @@ range_gist_consistent_int(FmgrInfo *flinfo, StrategyNumber strategy,
|
|||||||
proc = range_contains;
|
proc = range_contains;
|
||||||
break;
|
break;
|
||||||
case RANGESTRAT_CONTAINED_BY:
|
case RANGESTRAT_CONTAINED_BY:
|
||||||
|
/*
|
||||||
|
* Ideally we'd apply range_overlaps here, but at present it
|
||||||
|
* might fail to find empty ranges in the index, which should
|
||||||
|
* be reported as being contained by anything. This needs work.
|
||||||
|
*/
|
||||||
return true;
|
return true;
|
||||||
break;
|
break;
|
||||||
case RANGESTRAT_CONTAINS_ELEM:
|
case RANGESTRAT_CONTAINS_ELEM:
|
||||||
|
Reference in New Issue
Block a user