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

Commit2f729d8

Browse files
committed
Fix SIGSEGV in pruning for ScalarArrayOp with constant-null array.
Not much to be said here: commit9fdb675 should have checkedconstisnull, didn't.Per report from Piotr Włodarczyk. Back-patch to v11 wherebug was introduced.Discussion:https://postgr.es/m/CAP-dhMr+vRpwizEYjUjsiZ1vwqpohTm+3Pbdt6Pr7FEgPq9R0Q@mail.gmail.com
1 parentbf6455d commit2f729d8

File tree

3 files changed

+84
-1
lines changed

3 files changed

+84
-1
lines changed

‎src/backend/partitioning/partprune.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2034,7 +2034,7 @@ match_clause_to_partition_key(GeneratePruningStepsContext *context,
20342034
* nodes, one for each array element (excepting nulls).
20352035
*/
20362036
Const*arr= (Const*)rightop;
2037-
ArrayType*arrval=DatumGetArrayTypeP(arr->constvalue);
2037+
ArrayType*arrval;
20382038
int16elemlen;
20392039
boolelembyval;
20402040
charelemalign;
@@ -2043,6 +2043,11 @@ match_clause_to_partition_key(GeneratePruningStepsContext *context,
20432043
intnum_elems,
20442044
i;
20452045

2046+
/* If the array itself is null, the saop returns null */
2047+
if (arr->constisnull)
2048+
returnPARTCLAUSE_MATCH_CONTRADICT;
2049+
2050+
arrval=DatumGetArrayTypeP(arr->constvalue);
20462051
get_typlenbyvalalign(ARR_ELEMTYPE(arrval),
20472052
&elemlen,&elembyval,&elemalign);
20482053
deconstruct_array(arrval,

‎src/test/regress/expected/partition_prune.out

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1197,6 +1197,60 @@ explain (costs off) select * from coercepart where a !~ all ('{ab,bc}');
11971197
Filter: ((a)::text !~ ALL ('{ab,bc}'::text[]))
11981198
(7 rows)
11991199

1200+
explain (costs off) select * from coercepart where a = any ('{ab,bc}');
1201+
QUERY PLAN
1202+
-------------------------------------------------------
1203+
Append
1204+
-> Seq Scan on coercepart_ab
1205+
Filter: ((a)::text = ANY ('{ab,bc}'::text[]))
1206+
-> Seq Scan on coercepart_bc
1207+
Filter: ((a)::text = ANY ('{ab,bc}'::text[]))
1208+
(5 rows)
1209+
1210+
explain (costs off) select * from coercepart where a = any ('{ab,null}');
1211+
QUERY PLAN
1212+
---------------------------------------------------------
1213+
Append
1214+
-> Seq Scan on coercepart_ab
1215+
Filter: ((a)::text = ANY ('{ab,NULL}'::text[]))
1216+
(3 rows)
1217+
1218+
explain (costs off) select * from coercepart where a = any (null::text[]);
1219+
QUERY PLAN
1220+
--------------------------
1221+
Result
1222+
One-Time Filter: false
1223+
(2 rows)
1224+
1225+
explain (costs off) select * from coercepart where a = all ('{ab}');
1226+
QUERY PLAN
1227+
----------------------------------------------------
1228+
Append
1229+
-> Seq Scan on coercepart_ab
1230+
Filter: ((a)::text = ALL ('{ab}'::text[]))
1231+
(3 rows)
1232+
1233+
explain (costs off) select * from coercepart where a = all ('{ab,bc}');
1234+
QUERY PLAN
1235+
--------------------------
1236+
Result
1237+
One-Time Filter: false
1238+
(2 rows)
1239+
1240+
explain (costs off) select * from coercepart where a = all ('{ab,null}');
1241+
QUERY PLAN
1242+
--------------------------
1243+
Result
1244+
One-Time Filter: false
1245+
(2 rows)
1246+
1247+
explain (costs off) select * from coercepart where a = all (null::text[]);
1248+
QUERY PLAN
1249+
--------------------------
1250+
Result
1251+
One-Time Filter: false
1252+
(2 rows)
1253+
12001254
drop table coercepart;
12011255
CREATE TABLE part (a INT, b INT) PARTITION BY LIST (a);
12021256
CREATE TABLE part_p1 PARTITION OF part FOR VALUES IN (-2,-1,0,1,2);
@@ -3076,6 +3130,20 @@ select * from stable_qual_pruning
30763130
Filter: (a = ANY ('{"Tue Feb 01 00:00:00 2000 PST","Fri Jan 01 00:00:00 2010 PST"}'::timestamp with time zone[]))
30773131
(4 rows)
30783132

3133+
explain (analyze, costs off, summary off, timing off)
3134+
select * from stable_qual_pruning
3135+
where a = any(null::timestamptz[]);
3136+
QUERY PLAN
3137+
----------------------------------------------------------------
3138+
Append (actual rows=0 loops=1)
3139+
-> Seq Scan on stable_qual_pruning1 (actual rows=0 loops=1)
3140+
Filter: (a = ANY (NULL::timestamp with time zone[]))
3141+
-> Seq Scan on stable_qual_pruning2 (actual rows=0 loops=1)
3142+
Filter: (a = ANY (NULL::timestamp with time zone[]))
3143+
-> Seq Scan on stable_qual_pruning3 (actual rows=0 loops=1)
3144+
Filter: (a = ANY (NULL::timestamp with time zone[]))
3145+
(7 rows)
3146+
30793147
drop table stable_qual_pruning;
30803148
--
30813149
-- Check that pruning with composite range partitioning works correctly when

‎src/test/regress/sql/partition_prune.sql

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,13 @@ explain (costs off) select * from coercepart where a ~ any ('{ab}');
180180
explain (costs off)select*from coercepartwhere a !~ all ('{ab}');
181181
explain (costs off)select*from coercepartwhere a ~ any ('{ab,bc}');
182182
explain (costs off)select*from coercepartwhere a !~ all ('{ab,bc}');
183+
explain (costs off)select*from coercepartwhere a= any ('{ab,bc}');
184+
explain (costs off)select*from coercepartwhere a= any ('{ab,null}');
185+
explain (costs off)select*from coercepartwhere a= any (null::text[]);
186+
explain (costs off)select*from coercepartwhere a= all ('{ab}');
187+
explain (costs off)select*from coercepartwhere a= all ('{ab,bc}');
188+
explain (costs off)select*from coercepartwhere a= all ('{ab,null}');
189+
explain (costs off)select*from coercepartwhere a= all (null::text[]);
183190

184191
droptable coercepart;
185192

@@ -764,6 +771,9 @@ select * from stable_qual_pruning
764771
explain (analyze, costs off, summary off, timing off)
765772
select*from stable_qual_pruning
766773
where a= any(array['2000-02-01','2010-01-01']::timestamptz[]);
774+
explain (analyze, costs off, summary off, timing off)
775+
select*from stable_qual_pruning
776+
where a= any(null::timestamptz[]);
767777

768778
droptable stable_qual_pruning;
769779

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp