Use cached comparator in ShardIntervalsOverlap().

By far the most expensive part of ShardIntervalsOverlap() is computing
the function to use to determine overlap. Luckily we already have that
computed and cached.

The plan time for the query in issue #607 goes from 8764 ms to 2889 ms
with this change.
pull/1938/head
Andres Freund 2016-06-16 14:49:00 -07:00
parent 51aca7a80c
commit 1e07a94435
1 changed files with 3 additions and 4 deletions

View File

@ -3601,17 +3601,16 @@ FragmentInterval(RangeTableFragment *fragment)
bool
ShardIntervalsOverlap(ShardInterval *firstInterval, ShardInterval *secondInterval)
{
Oid typeId = InvalidOid;
FmgrInfo *comparisonFunction = NULL;
bool nonOverlap = false;
DistTableCacheEntry *intervalRelation =
DistributedTableCacheEntry(firstInterval->relationId);
FmgrInfo *comparisonFunction = intervalRelation->shardIntervalCompareFunction;
Datum firstMin = 0;
Datum firstMax = 0;
Datum secondMin = 0;
Datum secondMax = 0;
typeId = firstInterval->valueTypeId;
comparisonFunction = GetFunctionInfo(typeId, BTREE_AM_OID, BTORDER_PROC);
firstMin = firstInterval->minValue;
firstMax = firstInterval->maxValue;