]> git.ipfire.org Git - thirdparty/postgresql.git/commitdiff
Prevent satisfies_hash_partition from crashing with VARIADIC NULL.
authorRobert Haas <rhaas@postgresql.org>
Mon, 6 Jul 2026 16:12:41 +0000 (12:12 -0400)
committerRobert Haas <rhaas@postgresql.org>
Mon, 6 Jul 2026 16:24:23 +0000 (12:24 -0400)
Commit f3b0897a1213f46b4d3a99a7f8ef3a4b32e03572 fixed some
related problems, but overlooked this one. That commit first
appeared in PostgreSQL 11, so back-patch to all supported branches.

Backpatch-through: 14
Discussion: http://postgr.es/m/CA+TgmobsvQw3F+KRYT83=N3teh8D2t-oPR=U06QDZJE3viCJRg@mail.gmail.com
Reviewed-by: Tender Wang <tndrwang@gmail.com>
Reviewed-by: Ewan Young <kdbase.hack@gmail.com>
src/backend/partitioning/partbounds.c
src/test/regress/expected/hash_part.out
src/test/regress/sql/hash_part.sql

index 091d6e886b646bfb71521d8d520eb6bec359b53e..57019cf6bf076f340fdf144d6d286ba52227f877 100644 (file)
@@ -4890,6 +4890,12 @@ satisfies_hash_partition(PG_FUNCTION_ARGS)
                                                           fcinfo->flinfo->fn_mcxt);
                        }
                }
+               else if (PG_ARGISNULL(3))
+               {
+                       /* Special case for VARIADIC NULL::sometype[] */
+                       relation_close(parent, NoLock);
+                       PG_RETURN_BOOL(false);
+               }
                else
                {
                        ArrayType  *variadic_array = PG_GETARG_ARRAYTYPE_P(3);
@@ -4960,12 +4966,18 @@ satisfies_hash_partition(PG_FUNCTION_ARGS)
        }
        else
        {
-               ArrayType  *variadic_array = PG_GETARG_ARRAYTYPE_P(3);
+               ArrayType  *variadic_array;
                int                     i;
                int                     nelems;
                Datum      *datum;
                bool       *isnull;
 
+               /* Special case for VARIADIC NULL::sometype[] */
+               if (PG_ARGISNULL(3))
+                       PG_RETURN_BOOL(false);
+
+               variadic_array = PG_GETARG_ARRAYTYPE_P(3);
+
                deconstruct_array(variadic_array,
                                                  my_extra->variadic_type,
                                                  my_extra->variadic_typlen,
index ac3aabee0286a890c8031d74784e2695a287b616..c54b74abf6080d969a4d5ade029401fd3256cddb 100644 (file)
@@ -40,6 +40,13 @@ SELECT satisfies_hash_partition('mchash'::regclass, 4, NULL, NULL);
  f
 (1 row)
 
+-- variadic null
+SELECT satisfies_hash_partition('mchash'::regclass, 4, 0, VARIADIC NULL::int[]);
+ satisfies_hash_partition 
+--------------------------
+ f
+(1 row)
+
 -- too many arguments
 SELECT satisfies_hash_partition('mchash'::regclass, 4, 0, NULL::int, NULL::text, NULL::json);
 ERROR:  number of partitioning columns (2) does not match number of partition keys provided (3)
index e7eb36542cc3390b5638244e8e41578f13779234..0eca58469a7c117bf43dc9f4120048efc709a047 100644 (file)
@@ -35,6 +35,9 @@ SELECT satisfies_hash_partition('mchash'::regclass, NULL, 0, NULL);
 -- remainder is null
 SELECT satisfies_hash_partition('mchash'::regclass, 4, NULL, NULL);
 
+-- variadic null
+SELECT satisfies_hash_partition('mchash'::regclass, 4, 0, VARIADIC NULL::int[]);
+
 -- too many arguments
 SELECT satisfies_hash_partition('mchash'::regclass, 4, 0, NULL::int, NULL::text, NULL::json);