Skip to content
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions src/hypertable_restrict_info.c
Original file line number Diff line number Diff line change
Expand Up @@ -727,6 +727,46 @@ gather_restriction_dimension_vectors(const HypertableRestrictInfo *hri)
{
const DimensionRestrictInfoOpen *open = (const DimensionRestrictInfoOpen *) dri;

/*
* Filter out contradictory dimension restrictions. If
* lower_bound > upper_bound, no row can match, but some slices
* still can, because we're checking the slice ends separately:
* slice_start <= upper_bound <= lower_bound <= slice_end
* The chunk will pass our hypertable expansion and will later
* be excluded by the Postgres constraint exclusion that handles
* contradictory clauses. This is extra work that we can easily
* avoid now. Return early when the search intervals for slice
* start and slice end do not overlap. These are given by the
* upper/lower bound/strategy in the dimension restriction.
*/
if (open->upper_strategy != InvalidStrategy &&
open->lower_strategy != InvalidStrategy)
{
Assert(open->upper_strategy == BTLessEqualStrategyNumber ||
open->upper_strategy == BTLessStrategyNumber);
Assert(open->lower_strategy == BTGreaterEqualStrategyNumber ||
open->lower_strategy == BTGreaterStrategyNumber);

if (open->lower_bound > open->upper_bound)
{
/* No overlap. */
break;
}
else if (open->lower_bound == open->upper_bound)
{
/* Overlap if both intervals are inclusive. */
if (open->upper_strategy != BTLessEqualStrategyNumber ||
open->lower_strategy != BTGreaterEqualStrategyNumber)
{
break;
}
}
/* Overlap, proceed with finding the actual matching slices. */
}

/*
* Find the slices matching the dimension restriction.
*/
ts_dimension_slice_scan_iterator_set_range(&it,
open->base.dimension->fd.id,
open->upper_strategy,
Expand Down
Loading