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.
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;
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;
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: