Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit1b68010

Browse files
committed
Change bms_add_range to be a no-op for empty ranges
In commit8494064, bms_add_range was added with an API to fail withan error if an empty range was specified. This seems arbitrary andunhelpful, so turn that case into a no-op instead. Callers that requirefurther verification on the arguments or result can apply them bythemselves.This fixes the bug that partition pruning throws an API error for a caseinvolving the default partition of a default partition, as in theincluded 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 parent7dc5a96 commit1b68010

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+
returna;
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
elseif (uwordnum >=a->nwords)
884886
{
885887
intoldnwords=a->nwords;
886888
inti;
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
droptable coercepart;
175175

176+
CREATETABLEpart (aINT, bINT) PARTITION BY LIST (a);
177+
CREATETABLEpart_p1 PARTITION OF part FORVALUESIN (-2,-1,0,1,2);
178+
CREATETABLEpart_p2 PARTITION OF part DEFAULT PARTITION BY RANGE(a);
179+
CREATETABLEpart_p2_p1 PARTITION OF part_p2 DEFAULT;
180+
INSERT INTO partVALUES (-1,-1), (1,1), (2,NULL), (NULL,-2),(NULL,NULL);
181+
EXPLAIN (COSTS OFF)SELECT tableoid::regclassas part, a, bFROM partWHERE a ISNULLORDER BY1,2,3;
182+
176183
--
177184
-- some more cases
178185
--

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp