Skip to content

Commit 1b68010

Browse files
committed
Change bms_add_range to be a no-op for empty ranges
In commit 8494064, bms_add_range was added with an API to fail with an error if an empty range was specified. This seems arbitrary and unhelpful, so turn that case into a no-op instead. Callers that require further verification on the arguments or result can apply them by themselves. This fixes the bug that partition pruning throws an API error for a case involving the default partition of a default partition, as in the included test case. Reported-by: Rajkumar Raghuwanshi <rajkumar.raghuwanshi@enterprisedb.com> Diagnosed-by: Tom Lane <tgl@sss.pgh.pa.us> Discussion: https://postgr.es/m/16590.1532622503@sss.pgh.pa.us
1 parent 7dc5a96 commit 1b68010

File tree

3 files changed

+27
-2
lines changed

3 files changed

+27
-2
lines changed

src/backend/nodes/bitmapset.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -867,6 +867,10 @@ bms_add_range(Bitmapset *a, int lower, int upper)
867867
ushiftbits,
868868
wordnum;
869869

870+
/* do nothing if nothing is called for, without further checking */
871+
if (upper < lower)
872+
return a;
873+
870874
if (lower < 0 || upper < 0)
871875
elog(ERROR, "negative bitmapset member not allowed");
872876
if (lower > upper)
@@ -878,13 +882,12 @@ bms_add_range(Bitmapset *a, int lower, int upper)
878882
a = (Bitmapset *) palloc0(BITMAPSET_SIZE(uwordnum + 1));
879883
a->nwords = uwordnum + 1;
880884
}
881-
882-
/* ensure we have enough words to store the upper bit */
883885
else if (uwordnum >= a->nwords)
884886
{
885887
int oldnwords = a->nwords;
886888
int i;
887889

890+
/* ensure we have enough words to store the upper bit */
888891
a = (Bitmapset *) repalloc(a, BITMAPSET_SIZE(uwordnum + 1));
889892
a->nwords = uwordnum + 1;
890893
/* zero out the enlarged portion */

src/test/regress/expected/partition_prune.out

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1180,6 +1180,21 @@ explain (costs off) select * from coercepart where a !~ all ('{ab,bc}');
11801180
(7 rows)
11811181

11821182
drop table coercepart;
1183+
CREATE TABLE part (a INT, b INT) PARTITION BY LIST (a);
1184+
CREATE TABLE part_p1 PARTITION OF part FOR VALUES IN (-2,-1,0,1,2);
1185+
CREATE TABLE part_p2 PARTITION OF part DEFAULT PARTITION BY RANGE(a);
1186+
CREATE TABLE part_p2_p1 PARTITION OF part_p2 DEFAULT;
1187+
INSERT INTO part VALUES (-1,-1), (1,1), (2,NULL), (NULL,-2),(NULL,NULL);
1188+
EXPLAIN (COSTS OFF) SELECT tableoid::regclass as part, a, b FROM part WHERE a IS NULL ORDER BY 1, 2, 3;
1189+
QUERY PLAN
1190+
---------------------------------------------------------------------------
1191+
Sort
1192+
Sort Key: ((part_p2_p1.tableoid)::regclass), part_p2_p1.a, part_p2_p1.b
1193+
-> Append
1194+
-> Seq Scan on part_p2_p1
1195+
Filter: (a IS NULL)
1196+
(5 rows)
1197+
11831198
--
11841199
-- some more cases
11851200
--

src/test/regress/sql/partition_prune.sql

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,13 @@ explain (costs off) select * from coercepart where a !~ all ('{ab,bc}');
173173

174174
drop table coercepart;
175175

176+
CREATE TABLE part (a INT, b INT) PARTITION BY LIST (a);
177+
CREATE TABLE part_p1 PARTITION OF part FOR VALUES IN (-2,-1,0,1,2);
178+
CREATE TABLE part_p2 PARTITION OF part DEFAULT PARTITION BY RANGE(a);
179+
CREATE TABLE part_p2_p1 PARTITION OF part_p2 DEFAULT;
180+
INSERT INTO part VALUES (-1,-1), (1,1), (2,NULL), (NULL,-2),(NULL,NULL);
181+
EXPLAIN (COSTS OFF) SELECT tableoid::regclass as part, a, b FROM part WHERE a IS NULL ORDER BY 1, 2, 3;
182+
176183
--
177184
-- some more cases
178185
--

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy