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 1h3EgK-0001F8-KO for pgsql-bugs@arkaria.postgresql.org; Mon, 11 Mar 2019 06:45:04 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1h3EgJ-0004Xm-0J for pgsql-bugs@arkaria.postgresql.org; Mon, 11 Mar 2019 06:45:03 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1h3EgI-0004Ux-Ok for pgsql-bugs@lists.postgresql.org; Mon, 11 Mar 2019 06:45:02 +0000 Received: from tama500.ecl.ntt.co.jp ([129.60.39.148]) by magus.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1h3EgF-0003kF-IT for pgsql-bugs@lists.postgresql.org; Mon, 11 Mar 2019 06:45:02 +0000 Received: from vc2.ecl.ntt.co.jp (vc2.ecl.ntt.co.jp [129.60.86.154]) by tama500.ecl.ntt.co.jp (8.13.8/8.13.8) with ESMTP id x2B6irvI010632; Mon, 11 Mar 2019 15:44:53 +0900 Received: from vc2.ecl.ntt.co.jp (localhost [127.0.0.1]) by vc2.ecl.ntt.co.jp (Postfix) with ESMTP id 8ED7B639AA8; Mon, 11 Mar 2019 15:44:53 +0900 (JST) Received: from jcms-pop21.ecl.ntt.co.jp (jcms-pop21.ecl.ntt.co.jp [129.60.87.134]) by vc2.ecl.ntt.co.jp (Postfix) with ESMTP id 674E8639AA9; Mon, 11 Mar 2019 15:44:53 +0900 (JST) Received: from [127.0.0.1] (unknown [129.60.241.61]) by jcms-pop21.ecl.ntt.co.jp (Postfix) with ESMTPSA id 3710B4007A7; Mon, 11 Mar 2019 15:44:53 +0900 (JST) Subject: Re: BUG #15668: Server crash in transformPartitionRangeBounds References: <15668-0377b1981aa1a393@postgresql.org> <20190306064825.GH30982@paquier.xyz> <6ed2c24c-2f73-fa1c-0ed1-ed3597f13d0d@lab.ntt.co.jp> <20190306082730.GJ30982@paquier.xyz> From: Amit Langote Message-ID: Date: Mon, 11 Mar 2019 15:44:39 +0900 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:60.0) Gecko/20100101 Thunderbird/60.5.3 MIME-Version: 1.0 In-Reply-To: <20190306082730.GJ30982@paquier.xyz> Content-Type: multipart/mixed; boundary="------------3B0806AA65CB1D98FB37DF5B" Content-Language: en-US X-CC-Mail-RelayStamp: 1 To: Michael Paquier Cc: Amit Langote , exclusion@gmail.com, PostgreSQL mailing lists , PostgreSQL-development , Peter Eisentraut X-TM-AS-MML: disable List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk This is a multi-part message in MIME format. --------------3B0806AA65CB1D98FB37DF5B Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit Hi, On 2019/03/06 17:27, Michael Paquier wrote: > On Wed, Mar 06, 2019 at 04:00:42PM +0900, Amit Langote wrote: >> Thanks for looking at this. Your patch seems better, because it allows us >> to keep the error message consistent with the message one would get with >> list-partitioned syntax. > > Thanks for confirming. I think that it would be nice as well to add > more test coverage for such error patterns with all the strategies. > It would be good to fix that first, so I can take care of that. I've added some tests to your patch. Also improved the comments a bit. I noticed another issue with the code -- it's using strcmp() to compare specified string against "minvalue" and "maxvalue", which causes the following silly error: create table q2 partition of q for values from ("MINVALUE") to (maxvalue); ERROR: column "MINVALUE" does not exist LINE 1: create table q2 partition of q for values from ("MINVALUE") ... It should be using pg_strncasecmp(). > Now I don't really find the error "missing FROM-clause entry for > table" quite convincing when this is applied to a partition bound when > using a column defined in the relation. Adding more error classes in > the set of CRERR_NO_RTE would be perhaps nice, still I am not sure how > elegant it could be made when looking at expressions for partition > bounds. Note that this is not just a problem for partition bounds. You can see it with default expressions too. create table foo (a int default (aa.a)); ERROR: missing FROM-clause entry for table "aa" LINE 1: create table foo (a int default (aa.a)); create table foo (a int default (a.a.aa.a.a.a.a.aa)); ERROR: improper qualified name (too many dotted names): a.a.aa.a.a.a.a.aa LINE 1: create table foo (a int default (a.a.aa.a.a.a.a.aa)); We could make the error message more meaningful depending on the context, but maybe it'd better be pursue it as a separate project. Thanks, Amit --------------3B0806AA65CB1D98FB37DF5B Content-Type: text/plain; charset=UTF-8; name="partition-bound-crash-v2.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="partition-bound-crash-v2.patch" diff --git a/src/backend/parser/parse_utilcmd.c b/src/backend/parser/parse_utilcmd.c index a37d1f18be..67b05b8039 100644 --- a/src/backend/parser/parse_utilcmd.c +++ b/src/backend/parser/parse_utilcmd.c @@ -3746,18 +3746,28 @@ transformPartitionRangeBounds(ParseState *pstate, List *blist, ColumnRef *cref = (ColumnRef *) expr; char *cname = NULL; + /* + * There should be a single field named "minvalue" or "maxvalue". + */ if (list_length(cref->fields) == 1 && IsA(linitial(cref->fields), String)) cname = strVal(linitial(cref->fields)); - Assert(cname != NULL); - if (strcmp("minvalue", cname) == 0) + if (cname == NULL) + { + /* + * ColumnRef is not in the desired single-field-name form; for + * consistency, let transformExpr() report the error rather + * than doing it ourselves. + */ + } + else if (pg_strncasecmp(cname, "minvalue", 6) == 0) { prd = makeNode(PartitionRangeDatum); prd->kind = PARTITION_RANGE_DATUM_MINVALUE; prd->value = NULL; } - else if (strcmp("maxvalue", cname) == 0) + else if (pg_strncasecmp(cname, "maxvalue", 6) == 0) { prd = makeNode(PartitionRangeDatum); prd->kind = PARTITION_RANGE_DATUM_MAXVALUE; diff --git a/src/test/regress/expected/create_table.out b/src/test/regress/expected/create_table.out index d51e547278..503dca5866 100644 --- a/src/test/regress/expected/create_table.out +++ b/src/test/regress/expected/create_table.out @@ -709,6 +709,66 @@ ERROR: modulus for hash partition must be a positive integer -- remainder must be greater than or equal to zero and less than modulus CREATE TABLE fail_part PARTITION OF hash_parted2 FOR VALUES WITH (MODULUS 8, REMAINDER 8); ERROR: remainder for hash partition must be less than modulus +-- more tests for generalized expression syntax for list/range partition bounds +CREATE TABLE list_parted_bound_exprs(a int) PARTITION BY LIST (a); +CREATE TABLE list_parted_bound_exprs1 PARTITION OF list_parted_bound_exprs FOR VALUES IN ("UNKNOWN"); +ERROR: column "UNKNOWN" does not exist +LINE 1: ...RTITION OF list_parted_bound_exprs FOR VALUES IN ("UNKNOWN")... + ^ +CREATE TABLE list_parted_bound_exprs1 PARTITION OF list_parted_bound_exprs FOR VALUES IN (a); +ERROR: cannot use column references in partition bound expression +LINE 1: ...prs1 PARTITION OF list_parted_bound_exprs FOR VALUES IN (a); + ^ +CREATE TABLE list_parted_bound_exprs1 PARTITION OF list_parted_bound_exprs FOR VALUES IN (foo.a); +ERROR: missing FROM-clause entry for table "foo" +LINE 1: ... PARTITION OF list_parted_bound_exprs FOR VALUES IN (foo.a); + ^ +CREATE TABLE list_parted_bound_exprs1 PARTITION OF list_parted_bound_exprs FOR VALUES IN (list_parted_bound_exprs.a); +ERROR: missing FROM-clause entry for table "list_parted_bound_exprs" +LINE 1: ...RTITION OF list_parted_bound_exprs FOR VALUES IN (list_parte... + ^ +CREATE TABLE list_parted_bound_exprs1 PARTITION OF list_parted_bound_exprs FOR VALUES IN (list_parted_bound_exprs1.a.a.a.a); +ERROR: improper qualified name (too many dotted names): list_parted_bound_exprs1.a.a.a.a +LINE 1: ...RTITION OF list_parted_bound_exprs FOR VALUES IN (list_parte... + ^ +CREATE TABLE list_parted_bound_exprs1 PARTITION OF list_parted_bound_exprs FOR VALUES IN (list_parted_bound_exprs1.a); +ERROR: cannot use column references in partition bound expression +LINE 1: ...RTITION OF list_parted_bound_exprs FOR VALUES IN (list_parte... + ^ +CREATE TABLE range_parted_bound_exprs(a int) PARTITION BY RANGE (a); +CREATE TABLE range_parted_bound_exprs1 PARTITION OF range_parted_bound_exprs FOR VALUES FROM (1) TO (unknown); +ERROR: column "unknown" does not exist +LINE 1: ...F range_parted_bound_exprs FOR VALUES FROM (1) TO (unknown); + ^ +CREATE TABLE range_parted_bound_exprs1 PARTITION OF range_parted_bound_exprs FOR VALUES FROM (1) TO ("a".unknown); +ERROR: missing FROM-clause entry for table "a" +LINE 1: ... range_parted_bound_exprs FOR VALUES FROM (1) TO ("a".unknow... + ^ +CREATE TABLE range_parted_bound_exprs1 PARTITION OF range_parted_bound_exprs FOR VALUES FROM (1) TO ("a"."a"); +ERROR: missing FROM-clause entry for table "a" +LINE 1: ...F range_parted_bound_exprs FOR VALUES FROM (1) TO ("a"."a"); + ^ +CREATE TABLE range_parted_bound_exprs1 PARTITION OF range_parted_bound_exprs FOR VALUES FROM (1) TO ("range_parted_bound_exprs1"."a"); +ERROR: cannot use column references in partition bound expression +LINE 1: ... range_parted_bound_exprs FOR VALUES FROM (1) TO ("range_par... + ^ +CREATE TABLE range_parted_bound_exprs1 PARTITION OF range_parted_bound_exprs FOR VALUES FROM (1) TO ("range_parted_bound_exprs1"."a".a.a); +ERROR: cross-database references are not implemented: range_parted_bound_exprs1.a.a.a +LINE 1: ... range_parted_bound_exprs FOR VALUES FROM (1) TO ("range_par... + ^ +-- the following two should work +CREATE TABLE range_parted_bound_exprs1 PARTITION OF range_parted_bound_exprs FOR VALUES FROM ("minValue") TO (1); +CREATE TABLE range_parted_bound_exprs2 PARTITION OF range_parted_bound_exprs FOR VALUES FROM (1) TO (MAXVALUE); +\d+ range_parted_bound_exprs + Partitioned table "public.range_parted_bound_exprs" + Column | Type | Collation | Nullable | Default | Storage | Stats target | Description +--------+---------+-----------+----------+---------+---------+--------------+------------- + a | integer | | | | plain | | +Partition key: RANGE (a) +Partitions: range_parted_bound_exprs1 FOR VALUES FROM (MINVALUE) TO (1), + range_parted_bound_exprs2 FOR VALUES FROM (1) TO (MAXVALUE) + +drop table list_parted_bound_exprs, range_parted_bound_exprs; -- check schema propagation from parent CREATE TABLE parted ( a text, diff --git a/src/test/regress/sql/create_table.sql b/src/test/regress/sql/create_table.sql index 4091c19cf0..399a882430 100644 --- a/src/test/regress/sql/create_table.sql +++ b/src/test/regress/sql/create_table.sql @@ -627,6 +627,28 @@ CREATE TABLE fail_part PARTITION OF hash_parted2 FOR VALUES WITH (MODULUS 0, REM -- remainder must be greater than or equal to zero and less than modulus CREATE TABLE fail_part PARTITION OF hash_parted2 FOR VALUES WITH (MODULUS 8, REMAINDER 8); +-- more tests for generalized expression syntax for list/range partition bounds +CREATE TABLE list_parted_bound_exprs(a int) PARTITION BY LIST (a); +CREATE TABLE list_parted_bound_exprs1 PARTITION OF list_parted_bound_exprs FOR VALUES IN ("UNKNOWN"); +CREATE TABLE list_parted_bound_exprs1 PARTITION OF list_parted_bound_exprs FOR VALUES IN (a); +CREATE TABLE list_parted_bound_exprs1 PARTITION OF list_parted_bound_exprs FOR VALUES IN (foo.a); +CREATE TABLE list_parted_bound_exprs1 PARTITION OF list_parted_bound_exprs FOR VALUES IN (list_parted_bound_exprs.a); +CREATE TABLE list_parted_bound_exprs1 PARTITION OF list_parted_bound_exprs FOR VALUES IN (list_parted_bound_exprs1.a.a.a.a); +CREATE TABLE list_parted_bound_exprs1 PARTITION OF list_parted_bound_exprs FOR VALUES IN (list_parted_bound_exprs1.a); + +CREATE TABLE range_parted_bound_exprs(a int) PARTITION BY RANGE (a); +CREATE TABLE range_parted_bound_exprs1 PARTITION OF range_parted_bound_exprs FOR VALUES FROM (1) TO (unknown); +CREATE TABLE range_parted_bound_exprs1 PARTITION OF range_parted_bound_exprs FOR VALUES FROM (1) TO ("a".unknown); +CREATE TABLE range_parted_bound_exprs1 PARTITION OF range_parted_bound_exprs FOR VALUES FROM (1) TO ("a"."a"); +CREATE TABLE range_parted_bound_exprs1 PARTITION OF range_parted_bound_exprs FOR VALUES FROM (1) TO ("range_parted_bound_exprs1"."a"); +CREATE TABLE range_parted_bound_exprs1 PARTITION OF range_parted_bound_exprs FOR VALUES FROM (1) TO ("range_parted_bound_exprs1"."a".a.a); +-- the following two should work +CREATE TABLE range_parted_bound_exprs1 PARTITION OF range_parted_bound_exprs FOR VALUES FROM ("minValue") TO (1); +CREATE TABLE range_parted_bound_exprs2 PARTITION OF range_parted_bound_exprs FOR VALUES FROM (1) TO (MAXVALUE); +\d+ range_parted_bound_exprs + +drop table list_parted_bound_exprs, range_parted_bound_exprs; + -- check schema propagation from parent CREATE TABLE parted ( --------------3B0806AA65CB1D98FB37DF5B--