pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Dmitry Dolgov <9erthalion6@gmail.com>
To: Michael Paquier <michael@paquier.xyz>
Cc: exclusion@gmail.com
Cc: pgsql-bugs@lists.postgresql.org
Subject: Re: BUG #16325: Assert failure on partitioning by int for a text value with a collation
Date: Wed, 1 Apr 2020 14:01:17 +0200
Message-ID: <20200401120117.qkmjxi3xrumbnd3s@localhost> (raw)
In-Reply-To: <20200401070842.GD142683@paquier.xyz>
References: <16325-809194cf742313ab@postgresql.org>
	<20200328125303.4me6vetvzgebobw5@localhost>
	<20200401070842.GD142683@paquier.xyz>

> On Wed, Apr 01, 2020 at 04:08:42PM +0900, Michael Paquier wrote:
> > On Sat, Mar 28, 2020 at 01:53:03PM +0100, Dmitry Dolgov wrote:
> > Thanks for reporting! Looks like transformPartitionBoundValue needs to
> > check that the source collumn is collatable, then we get more expected
> > result:
> >
> >     =# create table part_coll partition of parted for values in ('1' collate "POSIX");
> >     ERROR:  42804: collations are not supported by type integer
>
> We have here a side effect of 7c079d74, that has given the possibility
> to pass down general expressions for partition bounds.

Yep. That's why I've placed a test for this fix close to those
introduced in this commit.

> > +        if (type_is_collatable(colType))
> > +        {
> > +            if (!OidIsValid(exprCollOid))
> > +                ereport(ERROR,
> > +                        (errcode(ERRCODE_INDETERMINATE_COLLATION),
> > +                         errmsg("could not determine which collation to use for partition expression"),
> > +                         errhint("Use the COLLATE clause to set the collation explicitly.")));
> > +        }
> > +        else
> > +        {
> > +            if (OidIsValid(exprCollOid))
> > +                ereport(ERROR,
> > +                        (errcode(ERRCODE_DATATYPE_MISMATCH),
> > +                         errmsg("collations are not supported by type %s",
> > +                                format_type_be(colType))));
> > +        }
> > +
>
> It seems to me that the first error cannot happen, and should not
> happen.  When the expression is transformed, there is a lookup at the
> collation used via transformCollateClause() -> LookupCollation() ->
> get_collation_oid() which would never return an invalid OID if the
> collation exists, throwing an error instead.  The reason why a similar
> check exists in tablecmds.c is that there can be a collation override,
> no?

Good point, I believe you're right. This means that the fix can be
reduced as in attachments.

Attachments:

part_value_collations_v2.patch (text/x-diff, 2.2K) download diff --git a/src/backend/parser/parse_utilcmd.c b/src/backend/parser/parse_utilcmd.c index c1911411d0..403f8148ae 100644 --- a/src/backend/parser/parse_utilcmd.c +++ b/src/backend/parser/parse_utilcmd.c @@ -4069,6 +4069,16 @@ transformPartitionBoundValue(ParseState *pstate, Node *val, { Oid exprCollOid = exprCollation(value); + /* + * No need to check if exprCollOid is invalid, since if it would be, + * then transformCollateClause will throw an error earlier + */ + if (!type_is_collatable(colType)) + ereport(ERROR, + (errcode(ERRCODE_DATATYPE_MISMATCH), + errmsg("collations are not supported by type %s", + format_type_be(colType)))); + if (OidIsValid(exprCollOid) && exprCollOid != DEFAULT_COLLATION_OID && exprCollOid != partCollation) diff --git a/src/test/regress/expected/create_table.out b/src/test/regress/expected/create_table.out index c5e95edbed..abd1bfe2b9 100644 --- a/src/test/regress/expected/create_table.out +++ b/src/test/regress/expected/create_table.out @@ -594,6 +594,8 @@ CREATE TABLE list_parted ( CREATE TABLE part_p1 PARTITION OF list_parted FOR VALUES IN ('1'); CREATE TABLE part_p2 PARTITION OF list_parted FOR VALUES IN (2); CREATE TABLE part_p3 PARTITION OF list_parted FOR VALUES IN ((2+1)); +CREATE TABLE part_p4 PARTITION OF list_parted FOR VALUES IN ('1' collate "POSIX"); +ERROR: collations are not supported by type integer CREATE TABLE part_null PARTITION OF list_parted FOR VALUES IN (null); \d+ list_parted Partitioned table "public.list_parted" diff --git a/src/test/regress/sql/create_table.sql b/src/test/regress/sql/create_table.sql index 00ef81a685..3fe77a7711 100644 --- a/src/test/regress/sql/create_table.sql +++ b/src/test/regress/sql/create_table.sql @@ -522,6 +522,7 @@ CREATE TABLE list_parted ( CREATE TABLE part_p1 PARTITION OF list_parted FOR VALUES IN ('1'); CREATE TABLE part_p2 PARTITION OF list_parted FOR VALUES IN (2); CREATE TABLE part_p3 PARTITION OF list_parted FOR VALUES IN ((2+1)); +CREATE TABLE part_p4 PARTITION OF list_parted FOR VALUES IN ('1' collate "POSIX"); CREATE TABLE part_null PARTITION OF list_parted FOR VALUES IN (null); \d+ list_parted

view thread (9+ messages)  latest in thread

Message-ID: <20200401120117.qkmjxi3xrumbnd3s@localhost>
Permalink:  ../20200401120117.qkmjxi3xrumbnd3s@localhost/
Also on:    postgresql.org/message-id/20200401120117.qkmjxi3xrumbnd3s@localhost

 ·  · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-bugs@postgresql.org
  Cc: 9erthalion6@gmail.com, michael@paquier.xyz, exclusion@gmail.com, pgsql-bugs@lists.postgresql.org
  Subject: Re: BUG #16325: Assert failure on partitioning by int for a text value with a collation
  In-Reply-To: <20200401120117.qkmjxi3xrumbnd3s@localhost>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox