From 1c6856b20e51c91eed0d2fd4e040d1df2ca2d21d Mon Sep 17 00:00:00 2001 From: amit Date: Fri, 10 May 2019 13:52:59 +0900 Subject: [PATCH 2/2] Bug fix --- src/backend/partitioning/partprune.c | 28 ++++++++++++++++++++++----- src/test/regress/expected/partition_prune.out | 4 +++- 2 files changed, 26 insertions(+), 6 deletions(-) diff --git a/src/backend/partitioning/partprune.c b/src/backend/partitioning/partprune.c index b5c1c7d4dd..f6da2a8b2c 100644 --- a/src/backend/partitioning/partprune.c +++ b/src/backend/partitioning/partprune.c @@ -3103,11 +3103,29 @@ perform_pruning_base_step(PartitionPruneContext *context, opstep->nullkeys); case PARTITION_STRATEGY_RANGE: - return get_matching_range_bounds(context, - opstep->opstrategy, - values, nvalues, - partsupfunc, - opstep->nullkeys); + { + int opstrategy = opstep->opstrategy; + + /* + * If we got values for only a subset (prefix) of the + * expressions in opstep->exprs, adjust the strategy to + * be used for pruning. Originally, it would be the strategy + * of the operator comparing the *last* expression against the + * corresponding partition key, but it would be wrong to use + * the same strategy now that we'll be comparing the values of + * only a prefix of expressions against the partition bounds. + * Use equality strategy, because all expressions in the + * prefix must have been extracted from clauses containing + * equality (=) or inclusive operators (<=, >=) anyway. + */ + if (nvalues < list_length(opstep->exprs)) + opstrategy = BTEqualStrategyNumber; + return get_matching_range_bounds(context, + opstrategy, + values, nvalues, + partsupfunc, + opstep->nullkeys); + } default: elog(ERROR, "unexpected partition strategy: %d", diff --git a/src/test/regress/expected/partition_prune.out b/src/test/regress/expected/partition_prune.out index c8cd6a23f1..c26a86472a 100644 --- a/src/test/regress/expected/partition_prune.out +++ b/src/test/regress/expected/partition_prune.out @@ -951,9 +951,11 @@ explain (costs off) select * from mc3p where a = 1 and abs(b) < (select 2); -> Result -> Seq Scan on mc3p0 Filter: ((a = 1) AND (abs(b) < $0)) + -> Seq Scan on mc3p1 + Filter: ((a = 1) AND (abs(b) < $0)) -> Seq Scan on mc3p_default Filter: ((a = 1) AND (abs(b) < $0)) -(7 rows) +(9 rows) -- a simpler multi-column keys case create table mc2p (a int, b int) partition by range (a, b); -- 2.11.0