From 211a9721a9618f70f5c94cde297f8a773e38d55e Mon Sep 17 00:00:00 2001 From: Andres Freund Date: Thu, 16 Jun 2016 14:49:00 -0700 Subject: [PATCH] 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. --- src/backend/distributed/planner/multi_physical_planner.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/backend/distributed/planner/multi_physical_planner.c b/src/backend/distributed/planner/multi_physical_planner.c index f714aa3c3..3b800f09f 100644 --- a/src/backend/distributed/planner/multi_physical_planner.c +++ b/src/backend/distributed/planner/multi_physical_planner.c @@ -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;