aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2011-11-26 14:27:05 -0500
committerTom Lane <tgl@sss.pgh.pa.us>2011-11-26 14:27:05 -0500
commit5966bcecf6167f2921e614e66499fa4d2c195c64 (patch)
treefe3a5ec175c39f1284b386069bf5f6559a7d9592
parent6c8768c3861d6690656b74676c44ffa63c0e4ef7 (diff)
downloadpostgresql-5966bcecf6167f2921e614e66499fa4d2c195c64.tar.gz
postgresql-5966bcecf6167f2921e614e66499fa4d2c195c64.zip
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.
-rw-r--r--src/backend/utils/adt/rangetypes_gist.c13
1 files changed, 9 insertions, 4 deletions
diff --git a/src/backend/utils/adt/rangetypes_gist.c b/src/backend/utils/adt/rangetypes_gist.c
index 95f93905a5e..be59a5c4a38 100644
--- a/src/backend/utils/adt/rangetypes_gist.c
+++ b/src/backend/utils/adt/rangetypes_gist.c
@@ -444,13 +444,13 @@ range_gist_consistent_int(FmgrInfo *flinfo, StrategyNumber strategy,
switch (strategy)
{
case RANGESTRAT_BEFORE:
- if (RangeIsEmpty(key))
+ if (RangeIsEmpty(key) || RangeIsEmpty(DatumGetRangeType(query)))
return false;
proc = range_overright;
negate = true;
break;
case RANGESTRAT_OVERLEFT:
- if (RangeIsEmpty(key))
+ if (RangeIsEmpty(key) || RangeIsEmpty(DatumGetRangeType(query)))
return false;
proc = range_after;
negate = true;
@@ -459,13 +459,13 @@ range_gist_consistent_int(FmgrInfo *flinfo, StrategyNumber strategy,
proc = range_overlaps;
break;
case RANGESTRAT_OVERRIGHT:
- if (RangeIsEmpty(key))
+ if (RangeIsEmpty(key) || RangeIsEmpty(DatumGetRangeType(query)))
return false;
proc = range_before;
negate = true;
break;
case RANGESTRAT_AFTER:
- if (RangeIsEmpty(key))
+ if (RangeIsEmpty(key) || RangeIsEmpty(DatumGetRangeType(query)))
return false;
proc = range_overleft;
negate = true;
@@ -483,6 +483,11 @@ range_gist_consistent_int(FmgrInfo *flinfo, StrategyNumber strategy,
proc = range_contains;
break;
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;
break;
case RANGESTRAT_CONTAINS_ELEM: