Use stricter qual for pruning if both >/< and >=/<= are present.

Previously, if both =< and < (>= and < respectively) were specified,
we always used the latter restriction.  Instead use the stricter one.
support-6.1-faster-pruning
Andres Freund 2017-04-28 17:16:42 -07:00 committed by Jason Petersen
parent bb456d4002
commit 7a0f02f186
No known key found for this signature in database
GPG Key ID: 9F1D3510D110ABA9
1 changed files with 26 additions and 6 deletions

View File

@ -1157,11 +1157,21 @@ PruneWithBoundaries(DistTableCacheEntry *cacheEntry, ClauseWalkerContext *contex
hasLowerBound = true; hasLowerBound = true;
} }
if (prune->greaterConsts) if (prune->greaterConsts)
{
/*
* Use the more restrictive one, if both greater and greaterEqual
* constraints are specified.
*/
if (!hasLowerBound ||
PerformValueCompare(compareFunctionCall,
prune->greaterConsts->constvalue,
lowerBound) >= 0)
{ {
lowerBound = prune->greaterConsts->constvalue; lowerBound = prune->greaterConsts->constvalue;
lowerBoundInclusive = false; lowerBoundInclusive = false;
hasLowerBound = true; hasLowerBound = true;
} }
}
if (prune->lessEqualConsts) if (prune->lessEqualConsts)
{ {
upperBound = prune->lessEqualConsts->constvalue; upperBound = prune->lessEqualConsts->constvalue;
@ -1169,11 +1179,21 @@ PruneWithBoundaries(DistTableCacheEntry *cacheEntry, ClauseWalkerContext *contex
hasUpperBound = true; hasUpperBound = true;
} }
if (prune->lessConsts) if (prune->lessConsts)
{
/*
* Use the more restrictive one, if both less and lessEqual
* constraints are specified.
*/
if (!hasUpperBound ||
PerformValueCompare(compareFunctionCall,
prune->lessConsts->constvalue,
upperBound) <= 0)
{ {
upperBound = prune->lessConsts->constvalue; upperBound = prune->lessConsts->constvalue;
upperBoundInclusive = false; upperBoundInclusive = false;
hasUpperBound = true; hasUpperBound = true;
} }
}
Assert(hasLowerBound || hasUpperBound); Assert(hasLowerBound || hasUpperBound);