Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1h3FFa-0002uz-1t for pgsql-hackers@arkaria.postgresql.org; Mon, 11 Mar 2019 07:21:30 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1h3FFY-0006gS-Cg for pgsql-hackers@arkaria.postgresql.org; Mon, 11 Mar 2019 07:21:28 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1h3FFV-0006gL-L0 for pgsql-hackers@lists.postgresql.org; Mon, 11 Mar 2019 07:21:27 +0000 Received: from out2-smtp.messagingengine.com ([66.111.4.26]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1h3FFR-0000GN-7y for pgsql-hackers@postgresql.org; Mon, 11 Mar 2019 07:21:24 +0000 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id 772B1210DB; Mon, 11 Mar 2019 03:21:20 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute4.internal (MEProxy); Mon, 11 Mar 2019 03:21:20 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=paquier.xyz; h= date:from:to:cc:subject:message-id:references:mime-version :content-type:in-reply-to; s=fm1; bh=YROGUlKfS87Evu0FJXkgApk9F/D ldo/bKCLLtRGjtiI=; b=EyIfLDhjHuEmDvgXj/3UMF/vJ7dokXSNYXb2T1v3YHp GD0Q0smFTKvozPgoEnJGc6xxa7qVEMxjxaF7evi+A8YEJb8XKABlPomhk+fI50qd vBEr7TuwLCkK3/VaG+rkmMAUDpuqiTavyDYUVScBhrigxj/zyNEhM3w0Ir/vjqeF ewtzRKXu2YYoHkuY7o+SmJNedRxWytVvDrx39/Z2pL6LDQ2yxaWPh1evOtHa75bx +yey1C+ovmpGoyaMGm8iJ/ln9v5wQbrQqitC9mjJj1hn1aMSYViyjH0xviFly/A+ FfOORfKsVt52PZyX5o5PrgfINbtHOoH7+0i1xtBzngQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-me-proxy :x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm2; bh=YROGUl KfS87Evu0FJXkgApk9F/Dldo/bKCLLtRGjtiI=; b=SDjjfvkMJkAp9qhO8WD36n vH2/kFa2w+/eYM8srOLDMec/WH+ELrx2LBHrR0PufN+y1hLI6ke2bY3vbyorliM9 Syk1VAfn1p1pe4akrhJWZXua1071J+QDIy44QKZ/9kqGMKRztby8P3WFRikixMo6 BXdYUNkf9bOdVcpuUAXh8ilIvkwtAViwq+J/y1lazauya+LmAL59wZ09SBZ17l43 NvwtwAIoHJPSph05E75QU2a4mf/VKiUFzIdTjoKm+845VknUmcDpIS+imxgzqrK0 1eG/FiCal2/lONzuxTzC11L7PmCfH9gcAMV9c1A24JE1wU394R/GO3m73t3si8EQ == X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedutddrgeehgddutdehucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne gfrhhlucfvnfffucdljedtmdenucfjughrpeffhffvuffkfhggtggujgesghdtreertddt vdenucfhrhhomhepofhitghhrggvlhcurfgrqhhuihgvrhcuoehmihgthhgrvghlsehprg hquhhivghrrdighiiiqeenucfkphepiedurddvudehrddufeejrdduiedvnecurfgrrhgr mhepmhgrihhlfhhrohhmpehmihgthhgrvghlsehprghquhhivghrrdighiiinecuvehluh hsthgvrhfuihiivgeptd X-ME-Proxy: Received: from paquier.xyz (c137162.net61215.cablenet.ne.jp [61.215.137.162]) by mail.messagingengine.com (Postfix) with ESMTPA id 70773E4173; Mon, 11 Mar 2019 03:21:17 -0400 (EDT) Date: Mon, 11 Mar 2019 16:21:14 +0900 From: Michael Paquier To: Amit Langote Cc: Amit Langote , exclusion@gmail.com, PostgreSQL mailing lists , PostgreSQL-development , Peter Eisentraut Subject: Re: BUG #15668: Server crash in transformPartitionRangeBounds Message-ID: <20190311072114.GG1818@paquier.xyz> References: <15668-0377b1981aa1a393@postgresql.org> <20190306064825.GH30982@paquier.xyz> <6ed2c24c-2f73-fa1c-0ed1-ed3597f13d0d@lab.ntt.co.jp> <20190306082730.GJ30982@paquier.xyz> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="nEsDIrWrg+hrB7l1" Content-Disposition: inline In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk --nEsDIrWrg+hrB7l1 Content-Type: multipart/mixed; boundary="dMyqICaxQaaUjrCL" Content-Disposition: inline --dMyqICaxQaaUjrCL Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Mon, Mar 11, 2019 at 03:44:39PM +0900, Amit Langote wrote: > We could make the error message more meaningful depending on the context, > but maybe it'd better be pursue it as a separate project. Yeah, I noticed that stuff when working on it this afternoon. The error message does not completely feel right even in your produced tests. Out of curiosity I have been working on this thing myself, and it is possible to have a context-related message. Please see attached, that's in my opinion less confusing, and of course debatable. Still this approach does not feel completely right either as that means hijacking the code path which generates a generic message for missing RTEs. :( -- Michael --dMyqICaxQaaUjrCL Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="partbound-error.patch" Content-Transfer-Encoding: quoted-printable diff --git a/src/backend/parser/parse_relation.c b/src/backend/parser/parse= _relation.c index f3b6d193aa..6b248f116f 100644 --- a/src/backend/parser/parse_relation.c +++ b/src/backend/parser/parse_relation.c @@ -3259,6 +3259,9 @@ errorMissingRTE(ParseState *pstate, RangeVar *relatio= n) * If we found a match that doesn't meet those criteria, assume the * problem is illegal use of a relation outside its scope, as in the * MySQL-ism "SELECT ... FROM a, b LEFT JOIN c ON (a.x =3D c.y)". + * + * Also, in the context of parsing a partition bound, produce a more + * helpful error message. */ if (rte && rte->alias && strcmp(rte->eref->aliasname, relation->relname) !=3D 0 && @@ -3267,7 +3270,12 @@ errorMissingRTE(ParseState *pstate, RangeVar *relati= on) &sublevels_up) =3D=3D rte) badAlias =3D rte->eref->aliasname; =20 - if (rte) + if (pstate->p_expr_kind =3D=3D EXPR_KIND_PARTITION_BOUND) + ereport(ERROR, + (errcode(ERRCODE_UNDEFINED_TABLE), + errmsg("invalid reference in partition bound expression for table \"%= s\"", + relation->relname))); + else if (rte) ereport(ERROR, (errcode(ERRCODE_UNDEFINED_TABLE), errmsg("invalid reference to FROM-clause entry for table \"%s\"", diff --git a/src/backend/parser/parse_utilcmd.c b/src/backend/parser/parse_= utilcmd.c index a37d1f18be..ee129ba18f 100644 --- a/src/backend/parser/parse_utilcmd.c +++ b/src/backend/parser/parse_utilcmd.c @@ -3750,8 +3750,16 @@ transformPartitionRangeBounds(ParseState *pstate, Li= st *blist, IsA(linitial(cref->fields), String)) cname =3D strVal(linitial(cref->fields)); =20 - Assert(cname !=3D NULL); - if (strcmp("minvalue", cname) =3D=3D 0) + if (cname =3D=3D NULL) + { + /* + * No field names have been found, meaning that there + * is not much to do with special value handling. Instead + * let the expression transformation handle any errors and + * limitations. + */ + } + else if (strcmp("minvalue", cname) =3D=3D 0) { prd =3D makeNode(PartitionRangeDatum); prd->kind =3D PARTITION_RANGE_DATUM_MINVALUE; diff --git a/src/test/regress/expected/create_table.out b/src/test/regress/= expected/create_table.out index d51e547278..0b3c9fb1ff 100644 --- a/src/test/regress/expected/create_table.out +++ b/src/test/regress/expected/create_table.out @@ -494,6 +494,10 @@ CREATE TABLE part_bogus_expr_fail PARTITION OF list_pa= rted FOR VALUES IN (somena ERROR: column "somename" does not exist LINE 1: ...expr_fail PARTITION OF list_parted FOR VALUES IN (somename); ^ +CREATE TABLE part_bogus_expr_fail PARTITION OF list_parted FOR VALUES IN (= somename.somename); +ERROR: invalid reference in partition bound expression for table "somenam= e" +CREATE TABLE part_bogus_expr_fail PARTITION OF list_parted FOR VALUES IN (= somename.somename.somename); +ERROR: invalid reference in partition bound expression for table "somenam= e" CREATE TABLE part_bogus_expr_fail PARTITION OF list_parted FOR VALUES IN (= a); ERROR: cannot use column references in partition bound expression LINE 1: ..._bogus_expr_fail PARTITION OF list_parted FOR VALUES IN (a); @@ -558,6 +562,33 @@ DROP TABLE bigintp; CREATE TABLE range_parted ( a date ) PARTITION BY RANGE (a); +-- forbidden expressions for partition bounds +CREATE TABLE part_bogus_expr_fail PARTITION OF range_parted + FOR VALUES FROM (a) TO (1); +ERROR: cannot use column references in partition bound expression +LINE 2: FOR VALUES FROM (a) TO (1); + ^ +CREATE TABLE part_bogus_expr_fail PARTITION OF range_parted + FOR VALUES FROM (somename) TO (1); +ERROR: column "somename" does not exist +LINE 2: FOR VALUES FROM (somename) TO (1); + ^ +CREATE TABLE part_bogus_expr_fail PARTITION OF range_parted + FOR VALUES FROM (somename.somename) TO (1); +ERROR: invalid reference in partition bound expression for table "somenam= e" +CREATE TABLE part_bogus_expr_fail PARTITION OF range_parted + FOR VALUES FROM (somename.somename.somename) TO (1); +ERROR: invalid reference in partition bound expression for table "somenam= e" +CREATE TABLE part_bogus_expr_fail PARTITION OF range_parted + FOR VALUES FROM ((select 1)) TO (10); +ERROR: cannot use subquery in partition bound +LINE 2: FOR VALUES FROM ((select 1)) TO (10); + ^ +CREATE TABLE part_bogus_expr_fail PARTITION OF range_parted + FOR VALUES FROM (generate_series(4, 6)) TO (10); +ERROR: set-returning functions are not allowed in partition bound +LINE 2: FOR VALUES FROM (generate_series(4, 6)) TO (10); + ^ -- trying to specify list for range partitioned table CREATE TABLE fail_part PARTITION OF range_parted FOR VALUES IN ('a'); ERROR: invalid bound specification for a range partition diff --git a/src/test/regress/sql/create_table.sql b/src/test/regress/sql/c= reate_table.sql index 4091c19cf0..7ffa187eb4 100644 --- a/src/test/regress/sql/create_table.sql +++ b/src/test/regress/sql/create_table.sql @@ -452,6 +452,8 @@ CREATE TABLE part_null PARTITION OF list_parted FOR VAL= UES IN (null); =20 -- forbidden expressions for partition bound CREATE TABLE part_bogus_expr_fail PARTITION OF list_parted FOR VALUES IN (= somename); +CREATE TABLE part_bogus_expr_fail PARTITION OF list_parted FOR VALUES IN (= somename.somename); +CREATE TABLE part_bogus_expr_fail PARTITION OF list_parted FOR VALUES IN (= somename.somename.somename); CREATE TABLE part_bogus_expr_fail PARTITION OF list_parted FOR VALUES IN (= a); CREATE TABLE part_bogus_expr_fail PARTITION OF list_parted FOR VALUES IN (= sum(a)); CREATE TABLE part_bogus_expr_fail PARTITION OF list_parted FOR VALUES IN (= (select 1)); @@ -497,6 +499,20 @@ CREATE TABLE range_parted ( a date ) PARTITION BY RANGE (a); =20 +-- forbidden expressions for partition bounds +CREATE TABLE part_bogus_expr_fail PARTITION OF range_parted + FOR VALUES FROM (a) TO (1); +CREATE TABLE part_bogus_expr_fail PARTITION OF range_parted + FOR VALUES FROM (somename) TO (1); +CREATE TABLE part_bogus_expr_fail PARTITION OF range_parted + FOR VALUES FROM (somename.somename) TO (1); +CREATE TABLE part_bogus_expr_fail PARTITION OF range_parted + FOR VALUES FROM (somename.somename.somename) TO (1); +CREATE TABLE part_bogus_expr_fail PARTITION OF range_parted + FOR VALUES FROM ((select 1)) TO (10); +CREATE TABLE part_bogus_expr_fail PARTITION OF range_parted + FOR VALUES FROM (generate_series(4, 6)) TO (10); + -- trying to specify list for range partitioned table CREATE TABLE fail_part PARTITION OF range_parted FOR VALUES IN ('a'); -- trying to specify modulus and remainder for range partitioned table --dMyqICaxQaaUjrCL-- --nEsDIrWrg+hrB7l1 Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAABCgAdFiEEG72nH6vTowiyblFKnvQgOdbyQH0FAlyGDGoACgkQnvQgOdby QH2feg//Uru1rsZAcVBktklZh2e0sKI7T2c4bh0FhnvZkknANA6ipHSNFIDhxrYq +ztdcdjxWjrMxuVsBuUaP/+R8QCwPydJlFWtwk6aTs93OoLtSKx9B5FDxASK5qXn CRA8Bm0M4mnW0wTRsNFu8cyzn4vJjw46XbjHMSu7fUBzvSzOiSshUu73Bw0E4Dn1 yP/fg6JY7Ws6oxPjNnoJ7lDB8MGqQ2NI2y8LbmjFGwVmhS6fg7Lnquj5bRS0fKnE zp1fvmuWWMI60V5YWaYx02dXgDm9KPOR+c/0QFhdMzRTrr59x+e3kIQoTCm+pjrP MgS5Rz41AG78HsK67QaQy4i4CUeqAjx/TVCFFTqzueZHYqshgzzDI1pteTBjusgV MJ3qjjEWSuKPhxt//4vtWNMIooLK3zUe/RwCfEH5FLb+iA6D83Nbb5aJDRyTOYtR tEj445LAWxqX2hSow/h59Vn/+QuHDK69hu027bO8cVzL0vlHgQaxjkch8LYpDUQ7 uyrRZb858OIzmtSqm9GcaV96hIXn0S3rEyYdr6LWGDer9wfNLGkpwSS9+JeUfv1Z geCUmk6cJP6kbeMximtqPLQL80tpvqwY+z6o3ft4TGlxmZla3f6c3YWwi3gwJKDi AmeGnxe8sU2piBAlLR/Odp9mx0tUz+iNCTJryF4sAcbaZtwXDxU= =5yFa -----END PGP SIGNATURE----- --nEsDIrWrg+hrB7l1--