pg.ddx.io pgsql-bugs@postgresql.org mailing list archive
help / color / mirror / Atom feedBUG #14866: The generated constraint in the typed table causes the server to crash
16+ messages / 4 participants
[nested] [flat]
* BUG #14866: The generated constraint in the typed table causes the server to crash
@ 2017-10-23 07:44 gomer94@yandex.ru
0 siblings, 1 reply; 16+ messages in thread
From: gomer94@yandex.ru @ 2017-10-23 07:44 UTC (permalink / raw)
To: pgsql-bugs; +Cc: gomer94@yandex.ru
The following bug has been logged on the website:
Bug reference: 14866
Logged by: Мансур Галиев
Email address: gomer94@yandex.ru
PostgreSQL version: 10.0
Operating system: Ubuntu 16.04.3 LTS x64
Description:
This sql code crashes the server:
CREATE TYPE comp AS (f1 integer, f2 text, f3 bigint);
CREATE TABLE typed_table OF comp (
f1 WITH OPTIONS GENERATED ALWAYS AS IDENTITY);
--
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs
^ permalink raw reply [nested|flat] 16+ messages in thread
* Re: BUG #14866: The generated constraint in the typed table causes the server to crash
@ 2017-10-23 14:09 Michael Paquier <michael.paquier@gmail.com>
parent: gomer94@yandex.ru
0 siblings, 1 reply; 16+ messages in thread
From: Michael Paquier @ 2017-10-23 14:09 UTC (permalink / raw)
To: gomer94@yandex.ru; +Cc: pgsql-bugs
On Mon, Oct 23, 2017 at 4:44 PM, <gomer94@yandex.ru> wrote:
> This sql code crashes the server:
>
> CREATE TYPE comp AS (f1 integer, f2 text, f3 bigint);
>
> CREATE TABLE typed_table OF comp (
> f1 WITH OPTIONS GENERATED ALWAYS AS IDENTITY);
Thanks for the report. I can reproduce the crasher here. The problem
happens when doing a type name lookup when transforming the CREATE
clause in the parser. Looking into it now.
--
Michael
--
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs
^ permalink raw reply [nested|flat] 16+ messages in thread
* Re: BUG #14866: The generated constraint in the typed table causes the server to crash
@ 2017-10-23 22:21 Michael Paquier <michael.paquier@gmail.com>
parent: Michael Paquier <michael.paquier@gmail.com>
0 siblings, 1 reply; 16+ messages in thread
From: Michael Paquier @ 2017-10-23 22:21 UTC (permalink / raw)
To: gomer94@yandex.ru; +Cc: pgsql-bugs; Peter Eisentraut <peter.eisentraut@2ndquadrant.com>
On Mon, Oct 23, 2017 at 11:09 PM, Michael Paquier
<michael.paquier@gmail.com> wrote:
> On Mon, Oct 23, 2017 at 4:44 PM, <gomer94@yandex.ru> wrote:
>> This sql code crashes the server:
>>
>> CREATE TYPE comp AS (f1 integer, f2 text, f3 bigint);
>>
>> CREATE TABLE typed_table OF comp (
>> f1 WITH OPTIONS GENERATED ALWAYS AS IDENTITY);
>
> Thanks for the report. I can reproduce the crasher here. The problem
> happens when doing a type name lookup when transforming the CREATE
> clause in the parser. Looking into it now.
Looking at the grammar of CREATE TABLE, child partitions crash as well
for the same reasons:
CREATE TABLE itest_parent (f1 date NOT NULL, f2 int) PARTITION BY RANGE (f1);
CREATE TABLE itest_child PARTITION OF itest_parent (
f2 WITH OPTIONS GENERATED ALWAYS AS IDENTITY
) FOR VALUES FROM ('2016-07-01') TO ('2016-08-01');
Attached is a patch to address the problem. There are a couple of
things to consider:
- transformColumnDefinition is missing the fact that a type may not be
set for a column defined, and as far as I can see the type name is
needed beforehand to allow the generation of all the serial commands.
This can happen when using CREATE TABLE OF, as you reported, for which
the data type can be found in the type defined. But this can happen as
well when declaring a child partition.
- MergeAttributes() needs to copy the identity field from the origin
to the target ColumnDef for both things.
As both MergeAttributes() and transformColumnDefinition() are linked
with each other, I went to the most straight-forward, less ugly
solution as child should not inherit identity constraints by default
from the parent. Comments are welcome.
I am adding Peter E in CC, who is the author and committer of the
feature. I am adding an entry in the CF as well.
--
Michael
--
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs
Attachments:
tab-identity-crashes.patch (application/octet-stream, 8.0K) download
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 2d4dcd7556..abab55ba00 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -1753,6 +1753,7 @@ MergeAttributes(List *schema, List *supers, char relpersistence,
coldef->raw_default = restdef->raw_default;
coldef->cooked_default = restdef->cooked_default;
coldef->constraints = restdef->constraints;
+ coldef->identity = restdef->identity;
coldef->is_from_type = false;
list_delete_cell(schema, rest, prev);
}
@@ -2257,6 +2258,7 @@ MergeAttributes(List *schema, List *supers, char relpersistence,
coldef->cooked_default = restdef->cooked_default;
coldef->constraints = restdef->constraints;
coldef->is_from_parent = false;
+ coldef->identity = restdef->identity;
list_delete_cell(schema, rest, prev);
}
else
diff --git a/src/backend/parser/parse_utilcmd.c b/src/backend/parser/parse_utilcmd.c
index 27e568fc62..cbc6f9b466 100644
--- a/src/backend/parser/parse_utilcmd.c
+++ b/src/backend/parser/parse_utilcmd.c
@@ -80,6 +80,7 @@ typedef struct
bool isforeign; /* true if CREATE/ALTER FOREIGN TABLE */
bool isalter; /* true if altering existing table */
bool hasoids; /* does relation have an OID column? */
+ Oid ofTypeOid; /* type used with CREATE TABLE OF */
List *columns; /* ColumnDef items */
List *ckconstraints; /* CHECK constraints */
List *fkconstraints; /* FOREIGN KEY constraints */
@@ -231,6 +232,7 @@ transformCreateStmt(CreateStmt *stmt, const char *queryString)
cxt.rel = NULL;
cxt.inhRelations = stmt->inhRelations;
cxt.isalter = false;
+ cxt.ofTypeOid = InvalidOid;
cxt.columns = NIL;
cxt.ckconstraints = NIL;
cxt.fkconstraints = NIL;
@@ -240,6 +242,7 @@ transformCreateStmt(CreateStmt *stmt, const char *queryString)
cxt.alist = NIL;
cxt.pkey = NULL;
cxt.ispartitioned = stmt->partspec != NULL;
+ cxt.partbound = stmt->partbound;
/*
* Notice that we allow OIDs here only for plain tables, even though
@@ -661,8 +664,84 @@ transformColumnDefinition(CreateStmtContext *cxt, ColumnDef *column)
{
Type ctype;
Oid typeOid;
+ TypeName *typeName;
+ bool found_type = false;
+ int i;
- ctype = typenameType(cxt->pstate, column->typeName, NULL);
+ /*
+ * Look at the type name of the column. When created
+ * under the context of CREATE TABLE OF, the column type
+ * name is not specified as part of the column clause, so
+ * do a lookup at the composite type defined and extract
+ * the correct type name from it. Columns listed in a
+ * child partition do not define a type name either, so
+ * look at the parent partition in this case and extract
+ * the type needed. Note that the type is needed beforehand
+ * so as serial evaluations can happen in a consistent way.
+ */
+ if (OidIsValid(cxt->ofTypeOid))
+ {
+ TupleDesc tupdesc;
+
+ tupdesc = lookup_rowtype_tupdesc(cxt->ofTypeOid, -1);
+ for (i = 0; i < tupdesc->natts ; i++)
+ {
+ Form_pg_attribute attr = TupleDescAttr(tupdesc, i);
+
+ if (attr->attisdropped)
+ continue;
+
+ if (strcmp(NameStr(attr->attname),
+ column->colname) == 0)
+ {
+ typeName = makeTypeNameFromOid(attr->atttypid,
+ attr->atttypmod);
+ found_type = true;
+ break;
+ }
+ }
+ DecrTupleDescRefCount(tupdesc);
+ }
+ else if (cxt->partbound)
+ {
+ Relation rel;
+ RangeVar *inh = linitial_node(RangeVar,
+ cxt->inhRelations);
+
+ Assert(list_length(cxt->inhRelations) == 1);
+
+ rel = heap_openrv(inh, AccessShareLock);
+ for (i = 0; i < rel->rd_att->natts; i++)
+ {
+ Form_pg_attribute attr =
+ TupleDescAttr(rel->rd_att, i);
+
+ if (attr->attisdropped)
+ continue;
+ if (strcmp(NameStr(attr->attname),
+ column->colname) == 0)
+ {
+ typeName = makeTypeNameFromOid(attr->atttypid,
+ attr->atttypmod);
+ found_type = true;
+ break;
+ }
+ }
+ heap_close(rel, NoLock);
+ }
+ else
+ {
+ typeName = column->typeName;
+ found_type = true;
+ }
+
+ if (!found_type)
+ ereport(ERROR,
+ (errcode(ERRCODE_UNDEFINED_COLUMN),
+ errmsg("column \"%s\" does not exist",
+ column->colname)));
+
+ ctype = typenameType(cxt->pstate, typeName, NULL);
typeOid = HeapTupleGetOid(ctype);
ReleaseSysCache(ctype);
@@ -1217,6 +1296,7 @@ transformOfType(CreateStmtContext *cxt, TypeName *ofTypename)
check_of_type(tuple);
ofTypeId = HeapTupleGetOid(tuple);
ofTypename->typeOid = ofTypeId; /* cached for later */
+ cxt->ofTypeOid = ofTypeId;
tupdesc = lookup_rowtype_tupdesc(ofTypeId, -1);
for (i = 0; i < tupdesc->natts; i++)
@@ -2686,6 +2766,7 @@ transformAlterTableStmt(Oid relid, AlterTableStmt *stmt,
cxt.rel = rel;
cxt.inhRelations = NIL;
cxt.isalter = true;
+ cxt.ofTypeOid = InvalidOid;
cxt.hasoids = false; /* need not be right */
cxt.columns = NIL;
cxt.ckconstraints = NIL;
diff --git a/src/test/regress/expected/identity.out b/src/test/regress/expected/identity.out
index 5fa585d6cc..5a6ba61da9 100644
--- a/src/test/regress/expected/identity.out
+++ b/src/test/regress/expected/identity.out
@@ -333,3 +333,38 @@ SELECT * FROM itest8;
RESET ROLE;
DROP TABLE itest8;
DROP USER regress_user1;
+-- typed table
+CREATE TYPE itest_type AS (f1 integer, f2 text, f3 bigint);
+CREATE TABLE itest9 OF itest_type (
+ f4 WITH OPTIONS GENERATED ALWAYS AS IDENTITY); -- error
+ERROR: column "f4" does not exist
+CREATE TABLE itest9 OF itest_type (
+ f2 WITH OPTIONS GENERATED ALWAYS AS IDENTITY); -- error
+ERROR: identity column type must be smallint, integer, or bigint
+CREATE TABLE itest9 OF itest_type (
+ f1 WITH OPTIONS GENERATED ALWAYS AS IDENTITY); -- ok
+\d itest9
+ Table "public.itest9"
+ Column | Type | Collation | Nullable | Default
+--------+---------+-----------+----------+------------------------------
+ f1 | integer | | not null | generated always as identity
+ f2 | text | | |
+ f3 | bigint | | |
+Typed table of type: itest_type
+
+DROP TYPE itest_type CASCADE;
+NOTICE: drop cascades to table itest9
+-- partitioned tables
+CREATE TABLE itest_parent (f1 date NOT NULL, f2 int) PARTITION BY RANGE (f1);
+CREATE TABLE itest_child PARTITION OF itest_parent (
+ f2 WITH OPTIONS GENERATED ALWAYS AS IDENTITY
+) FOR VALUES FROM ('2016-07-01') TO ('2016-08-01');
+\d itest_child
+ Table "public.itest_child"
+ Column | Type | Collation | Nullable | Default
+--------+---------+-----------+----------+------------------------------
+ f1 | date | | not null |
+ f2 | integer | | not null | generated always as identity
+Partition of: itest_parent FOR VALUES FROM ('07-01-2016') TO ('08-01-2016')
+
+DROP TABLE itest_parent CASCADE;
diff --git a/src/test/regress/sql/identity.sql b/src/test/regress/sql/identity.sql
index e1b5a074c9..734fac70d0 100644
--- a/src/test/regress/sql/identity.sql
+++ b/src/test/regress/sql/identity.sql
@@ -194,3 +194,22 @@ SELECT * FROM itest8;
RESET ROLE;
DROP TABLE itest8;
DROP USER regress_user1;
+
+-- typed table
+CREATE TYPE itest_type AS (f1 integer, f2 text, f3 bigint);
+CREATE TABLE itest9 OF itest_type (
+ f4 WITH OPTIONS GENERATED ALWAYS AS IDENTITY); -- error
+CREATE TABLE itest9 OF itest_type (
+ f2 WITH OPTIONS GENERATED ALWAYS AS IDENTITY); -- error
+CREATE TABLE itest9 OF itest_type (
+ f1 WITH OPTIONS GENERATED ALWAYS AS IDENTITY); -- ok
+\d itest9
+DROP TYPE itest_type CASCADE;
+
+-- partitioned tables
+CREATE TABLE itest_parent (f1 date NOT NULL, f2 int) PARTITION BY RANGE (f1);
+CREATE TABLE itest_child PARTITION OF itest_parent (
+ f2 WITH OPTIONS GENERATED ALWAYS AS IDENTITY
+) FOR VALUES FROM ('2016-07-01') TO ('2016-08-01');
+\d itest_child
+DROP TABLE itest_parent CASCADE;
^ permalink raw reply [nested|flat] 16+ messages in thread
* Re: BUG #14866: The generated constraint in the typed table causes the server to crash
@ 2017-11-01 13:36 Peter Eisentraut <peter.eisentraut@2ndquadrant.com>
parent: Michael Paquier <michael.paquier@gmail.com>
0 siblings, 1 reply; 16+ messages in thread
From: Peter Eisentraut @ 2017-11-01 13:36 UTC (permalink / raw)
To: Michael Paquier <michael.paquier@gmail.com>; gomer94@yandex.ru; +Cc: pgsql-bugs
On 10/23/17 18:21, Michael Paquier wrote:
> Attached is a patch to address the problem. There are a couple of
> things to consider:
> - transformColumnDefinition is missing the fact that a type may not be
> set for a column defined, and as far as I can see the type name is
> needed beforehand to allow the generation of all the serial commands.
> This can happen when using CREATE TABLE OF, as you reported, for which
> the data type can be found in the type defined. But this can happen as
> well when declaring a child partition.
I wonder whether we should even allow this. The SQL standard does not
allow identity columns in typed tables, so there is support for that.
I'm not sure whether it makes sense in partitions. You are supposed to
insert through the partition root, so making identity columns in
partitions would just be confusing.
> I am adding Peter E in CC, who is the author and committer of the
> feature. I am adding an entry in the CF as well.
There are two entries for this now. Maybe remove one?
--
Peter Eisentraut http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services
--
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs
^ permalink raw reply [nested|flat] 16+ messages in thread
* Re: BUG #14866: The generated constraint in the typed table causes the server to crash
@ 2017-11-01 14:05 Michael Paquier <michael.paquier@gmail.com>
parent: Peter Eisentraut <peter.eisentraut@2ndquadrant.com>
0 siblings, 1 reply; 16+ messages in thread
From: Michael Paquier @ 2017-11-01 14:05 UTC (permalink / raw)
To: Peter Eisentraut <peter.eisentraut@2ndquadrant.com>; +Cc: pgsql-bugs; Robert Haas <robertmhaas@gmail.com>; Amit Langote <amitlangote09@gmail.com>
On Wed, Nov 1, 2017 at 1:36 PM, Peter Eisentraut
<peter.eisentraut@2ndquadrant.com> wrote:
> On 10/23/17 18:21, Michael Paquier wrote:
>> Attached is a patch to address the problem. There are a couple of
>> things to consider:
>> - transformColumnDefinition is missing the fact that a type may not be
>> set for a column defined, and as far as I can see the type name is
>> needed beforehand to allow the generation of all the serial commands.
>> This can happen when using CREATE TABLE OF, as you reported, for which
>> the data type can be found in the type defined. But this can happen as
>> well when declaring a child partition.
>
> I wonder whether we should even allow this. The SQL standard does not
> allow identity columns in typed tables, so there is support for that.
OK. At the same time being able to support that is not complicated
either, even if the patch I sent earlier is a bit grotty in the way it
does handle it. I can see arguments in favor of either solution.
> I'm not sure whether it makes sense in partitions. You are supposed to
> insert through the partition root, so making identity columns in
> partitions would just be confusing.
Robert, Amit, do you have opinions on the matter? It is possible to
have multiple level of partitions as well.
>> I am adding Peter E in CC, who is the author and committer of the
>> feature. I am adding an entry in the CF as well.
>
> There are two entries for this now. Maybe remove one?
Fixed.
--
Michael
--
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs
^ permalink raw reply [nested|flat] 16+ messages in thread
* Re: BUG #14866: The generated constraint in the typed table causes the server to crash
@ 2017-11-09 05:39 Amit Langote <Langote_Amit_f8@lab.ntt.co.jp>
parent: Michael Paquier <michael.paquier@gmail.com>
0 siblings, 1 reply; 16+ messages in thread
From: Amit Langote @ 2017-11-09 05:39 UTC (permalink / raw)
To: Michael Paquier <michael.paquier@gmail.com>; Peter Eisentraut <peter.eisentraut@2ndquadrant.com>; +Cc: pgsql-bugs; Robert Haas <robertmhaas@gmail.com>; Amit Langote <amitlangote09@gmail.com>
Sorry Michael. I didn't notice this in my gmail inbox until today.
On 2017/11/01 23:05, Michael Paquier wrote:
> On Wed, Nov 1, 2017 at 1:36 PM, Peter Eisentraut
> <peter.eisentraut@2ndquadrant.com> wrote:
>> On 10/23/17 18:21, Michael Paquier wrote:
>>> Attached is a patch to address the problem. There are a couple of
>>> things to consider:
>>> - transformColumnDefinition is missing the fact that a type may not be
>>> set for a column defined, and as far as I can see the type name is
>>> needed beforehand to allow the generation of all the serial commands.
>>> This can happen when using CREATE TABLE OF, as you reported, for which
>>> the data type can be found in the type defined. But this can happen as
>>> well when declaring a child partition.
>>
>> I wonder whether we should even allow this. The SQL standard does not
>> allow identity columns in typed tables, so there is support for that.
>
> OK. At the same time being able to support that is not complicated
> either, even if the patch I sent earlier is a bit grotty in the way it
> does handle it. I can see arguments in favor of either solution.
Agree that it's not that hard to support IDENTITY on typed table columns.
I rewrote your patch a bit so that it now makes transformColumnDefinition
use the ColumnDef initialized by transformOfType which contains enough
information to get the needed type OID. I think you might find it a bit
simpler. :)
Also, I carved it out into the attached patch 0001.
>> I'm not sure whether it makes sense in partitions. You are supposed to
>> insert through the partition root, so making identity columns in
>> partitions would just be confusing.
>
> Robert, Amit, do you have opinions on the matter? It is possible to
> have multiple level of partitions as well.
IMHO, we should support IDENTITY on partitions, just like we support
specifying DEFAULT on partitions. We support issuing direct INSERT on
partitions no matter where in the hierarchy it is, so having these
features work normally makes sense to me.
I looked at your patch and saw a minor problem with it. With your patch,
there exists a lock-strength-upgrade deadlock hazard. It is making an
earlier phase of partition creation (transformCreateStmt) take an
AccessShareLock on the parent table, whereas a later phase
(DefineRelation) will take an AccessExclusiveLock. I modified your patch
to take the AccessExclusiveLock to begin with and added a comment nearby
clarifying the same.
You'll find the updated version in attached 0002.
Sorry again for the delay in replying.
Thanks,
Amit
--
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs
Attachments: download all (2 files, .tar.gz)
0001-Make-IDENTITY-work-correctly-with-typed-tables.patch (text/plain, 6.1K) download
From a6caf5eac2741759c29255d562571f60878515f5 Mon Sep 17 00:00:00 2001
From: amit <amitlangote09@gmail.com>
Date: Thu, 9 Nov 2017 11:31:58 +0900
Subject: [PATCH 1/2] Make IDENTITY work correctly with typed tables
In the case of CREATE TABLE OF, transformColumnDefinition should
look at the ColumnDef added by transformOfType(), not the one
passed down by gram.y which is mostly dummy.
Authors: Michael Paquier, Amit Langote
---
src/backend/commands/tablecmds.c | 1 +
src/backend/parser/parse_utilcmd.c | 53 ++++++++++++++++++++++++++++++----
src/test/regress/expected/identity.out | 21 ++++++++++++++
src/test/regress/sql/identity.sql | 11 +++++++
4 files changed, 81 insertions(+), 5 deletions(-)
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index b7ddb335d2..192de790c4 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -1754,6 +1754,7 @@ MergeAttributes(List *schema, List *supers, char relpersistence,
coldef->raw_default = restdef->raw_default;
coldef->cooked_default = restdef->cooked_default;
coldef->constraints = restdef->constraints;
+ coldef->identity = restdef->identity;
coldef->is_from_type = false;
list_delete_cell(schema, rest, prev);
}
diff --git a/src/backend/parser/parse_utilcmd.c b/src/backend/parser/parse_utilcmd.c
index 30fc2d9ff8..1be36b846a 100644
--- a/src/backend/parser/parse_utilcmd.c
+++ b/src/backend/parser/parse_utilcmd.c
@@ -92,6 +92,7 @@ typedef struct
IndexStmt *pkey; /* PRIMARY KEY index, if any */
bool ispartitioned; /* true if table is partitioned */
PartitionBoundSpec *partbound; /* transformed FOR VALUES */
+ bool ofType; /* true if statement contains OF typeName */
} CreateStmtContext;
/* State shared by transformCreateSchemaStmt and its subroutines */
@@ -240,6 +241,7 @@ transformCreateStmt(CreateStmt *stmt, const char *queryString)
cxt.alist = NIL;
cxt.pkey = NULL;
cxt.ispartitioned = stmt->partspec != NULL;
+ cxt.ofType = stmt->ofTypename != NULL;
/*
* Notice that we allow OIDs here only for plain tables, even though
@@ -659,13 +661,8 @@ transformColumnDefinition(CreateStmtContext *cxt, ColumnDef *column)
case CONSTR_IDENTITY:
{
- Type ctype;
Oid typeOid;
- ctype = typenameType(cxt->pstate, column->typeName, NULL);
- typeOid = HeapTupleGetOid(ctype);
- ReleaseSysCache(ctype);
-
if (saw_identity)
ereport(ERROR,
(errcode(ERRCODE_SYNTAX_ERROR),
@@ -674,6 +671,51 @@ transformColumnDefinition(CreateStmtContext *cxt, ColumnDef *column)
parser_errposition(cxt->pstate,
constraint->location)));
+ /*
+ * If this is CREATE TABLE OF, use the ColumnDef added by
+ * transformOfType().
+ */
+ if (cxt->ofType)
+ {
+ ListCell *lc;
+ ColumnDef *col;
+
+ foreach (lc, cxt->columns)
+ {
+ col = lfirst_node(ColumnDef, lc);
+
+ /*
+ * ColumnDef's coming from the type, which have
+ * a valid typeName set, are ahead in the list;
+ * only look at those.
+ */
+ if (col->typeName &&
+ strcmp(col->colname, column->colname) == 0)
+ break;
+ }
+
+ /*
+ * None of the ColumnDef's coming from the type
+ * matched.
+ */
+ if (col->typeName == NULL)
+ ereport(ERROR,
+ (errcode(ERRCODE_UNDEFINED_COLUMN),
+ errmsg("column \"%s\" does not exist",
+ column->colname)));
+
+ typeOid = col->typeName->typeOid;
+ }
+ else
+ {
+ Type ctype;
+
+ ctype = typenameType(cxt->pstate, column->typeName, NULL);
+ typeOid = HeapTupleGetOid(ctype);
+ ReleaseSysCache(ctype);
+ }
+
+ Assert(OidIsValid(typeOid));
generateSerialExtraStmts(cxt, column,
typeOid, constraint->options, true,
NULL, NULL);
@@ -2697,6 +2739,7 @@ transformAlterTableStmt(Oid relid, AlterTableStmt *stmt,
cxt.pkey = NULL;
cxt.ispartitioned = (rel->rd_rel->relkind == RELKIND_PARTITIONED_TABLE);
cxt.partbound = NULL;
+ cxt.ofType = false;
/*
* The only subtypes that currently require parse transformation handling
diff --git a/src/test/regress/expected/identity.out b/src/test/regress/expected/identity.out
index 5fa585d6cc..787edd4d06 100644
--- a/src/test/regress/expected/identity.out
+++ b/src/test/regress/expected/identity.out
@@ -333,3 +333,24 @@ SELECT * FROM itest8;
RESET ROLE;
DROP TABLE itest8;
DROP USER regress_user1;
+-- typed table
+CREATE TYPE itest_type AS (f1 integer, f2 text, f3 bigint);
+CREATE TABLE itest9 OF itest_type (
+ f4 WITH OPTIONS GENERATED ALWAYS AS IDENTITY); -- error
+ERROR: column "f4" does not exist
+CREATE TABLE itest9 OF itest_type (
+ f2 WITH OPTIONS GENERATED ALWAYS AS IDENTITY); -- error
+ERROR: identity column type must be smallint, integer, or bigint
+CREATE TABLE itest9 OF itest_type (
+ f1 WITH OPTIONS GENERATED ALWAYS AS IDENTITY); -- ok
+\d itest9
+ Table "public.itest9"
+ Column | Type | Collation | Nullable | Default
+--------+---------+-----------+----------+------------------------------
+ f1 | integer | | not null | generated always as identity
+ f2 | text | | |
+ f3 | bigint | | |
+Typed table of type: itest_type
+
+DROP TYPE itest_type CASCADE;
+NOTICE: drop cascades to table itest9
diff --git a/src/test/regress/sql/identity.sql b/src/test/regress/sql/identity.sql
index e1b5a074c9..b98180f644 100644
--- a/src/test/regress/sql/identity.sql
+++ b/src/test/regress/sql/identity.sql
@@ -194,3 +194,14 @@ SELECT * FROM itest8;
RESET ROLE;
DROP TABLE itest8;
DROP USER regress_user1;
+
+-- typed table
+CREATE TYPE itest_type AS (f1 integer, f2 text, f3 bigint);
+CREATE TABLE itest9 OF itest_type (
+ f4 WITH OPTIONS GENERATED ALWAYS AS IDENTITY); -- error
+CREATE TABLE itest9 OF itest_type (
+ f2 WITH OPTIONS GENERATED ALWAYS AS IDENTITY); -- error
+CREATE TABLE itest9 OF itest_type (
+ f1 WITH OPTIONS GENERATED ALWAYS AS IDENTITY); -- ok
+\d itest9
+DROP TYPE itest_type CASCADE;
--
2.11.0
0002-Make-IDENTITY-work-correctly-with-partitions.patch (text/plain, 5.6K) download
From f55ae5657c99ea8e01caf7454555352f8fa0c70e Mon Sep 17 00:00:00 2001
From: amit <amitlangote09@gmail.com>
Date: Thu, 9 Nov 2017 14:19:31 +0900
Subject: [PATCH 2/2] Make IDENTITY work correctly with partitions
In the case of CREATE TABLE PARTITION OF, transformColumnDefinition
should look at the parent's attribute of the same name to get the type
OID. ColumnDef passed down by gram.y is mostly dummy, so doesn't
contain the needed information.
Authors: Michael Paquier, Amit Langote
---
src/backend/commands/tablecmds.c | 1 +
src/backend/parser/parse_utilcmd.c | 40 ++++++++++++++++++++++++++++++++++
src/test/regress/expected/identity.out | 23 +++++++++++++++++++
src/test/regress/sql/identity.sql | 14 ++++++++++++
4 files changed, 78 insertions(+)
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 192de790c4..9597d594e3 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -2258,6 +2258,7 @@ MergeAttributes(List *schema, List *supers, char relpersistence,
coldef->raw_default = restdef->raw_default;
coldef->cooked_default = restdef->cooked_default;
coldef->constraints = restdef->constraints;
+ coldef->identity = restdef->identity;
coldef->is_from_parent = false;
list_delete_cell(schema, rest, prev);
}
diff --git a/src/backend/parser/parse_utilcmd.c b/src/backend/parser/parse_utilcmd.c
index 1be36b846a..4dae4b4171 100644
--- a/src/backend/parser/parse_utilcmd.c
+++ b/src/backend/parser/parse_utilcmd.c
@@ -241,6 +241,7 @@ transformCreateStmt(CreateStmt *stmt, const char *queryString)
cxt.alist = NIL;
cxt.pkey = NULL;
cxt.ispartitioned = stmt->partspec != NULL;
+ cxt.partbound = stmt->partbound;
cxt.ofType = stmt->ofTypename != NULL;
/*
@@ -706,6 +707,45 @@ transformColumnDefinition(CreateStmtContext *cxt, ColumnDef *column)
typeOid = col->typeName->typeOid;
}
+ else if (cxt->partbound)
+ {
+ Relation rel;
+ RangeVar *inh = linitial_node(RangeVar,
+ cxt->inhRelations);
+ int i;
+
+ Assert(list_length(cxt->inhRelations) == 1);
+
+ /*
+ * First time opening the parent table. We take an
+ * AccessExclusiveLock on it due to certain operations
+ * we do later in DefineRelation(). Don't want to
+ * risk a lock-upgrade deadlock hazard by taking a
+ * weaker lock now and stronger one later.
+ */
+ rel = heap_openrv(inh, AccessExclusiveLock);
+ for (i = 0; i < rel->rd_att->natts; i++)
+ {
+ Form_pg_attribute attr =
+ TupleDescAttr(rel->rd_att, i);
+
+ if (attr->attisdropped)
+ continue;
+ if (strcmp(NameStr(attr->attname),
+ column->colname) == 0)
+ {
+ typeOid = attr->atttypid;
+ break;
+ }
+ }
+ heap_close(rel, NoLock);
+
+ if (i == rel->rd_att->natts)
+ ereport(ERROR,
+ (errcode(ERRCODE_UNDEFINED_COLUMN),
+ errmsg("column \"%s\" does not exist",
+ column->colname)));
+ }
else
{
Type ctype;
diff --git a/src/test/regress/expected/identity.out b/src/test/regress/expected/identity.out
index 787edd4d06..81ec422bbd 100644
--- a/src/test/regress/expected/identity.out
+++ b/src/test/regress/expected/identity.out
@@ -354,3 +354,26 @@ Typed table of type: itest_type
DROP TYPE itest_type CASCADE;
NOTICE: drop cascades to table itest9
+-- partitioned tables
+CREATE TABLE itest_parent (f1 date NOT NULL, f2 text, f3 bigint) PARTITION BY RANGE (f1);
+CREATE TABLE itest_child PARTITION OF itest_parent (
+ f4 WITH OPTIONS GENERATED ALWAYS AS IDENTITY
+) FOR VALUES FROM ('2016-07-01') TO ('2016-08-01'); -- error
+ERROR: column "f4" does not exist
+CREATE TABLE itest_child PARTITION OF itest_parent (
+ f2 WITH OPTIONS GENERATED ALWAYS AS IDENTITY
+) FOR VALUES FROM ('2016-07-01') TO ('2016-08-01'); -- error
+ERROR: identity column type must be smallint, integer, or bigint
+CREATE TABLE itest_child PARTITION OF itest_parent (
+ f3 WITH OPTIONS GENERATED ALWAYS AS IDENTITY
+) FOR VALUES FROM ('2016-07-01') TO ('2016-08-01'); -- ok
+\d itest_child
+ Table "public.itest_child"
+ Column | Type | Collation | Nullable | Default
+--------+--------+-----------+----------+------------------------------
+ f1 | date | | not null |
+ f2 | text | | |
+ f3 | bigint | | not null | generated always as identity
+Partition of: itest_parent FOR VALUES FROM ('07-01-2016') TO ('08-01-2016')
+
+DROP TABLE itest_parent;
diff --git a/src/test/regress/sql/identity.sql b/src/test/regress/sql/identity.sql
index b98180f644..fe88abceb9 100644
--- a/src/test/regress/sql/identity.sql
+++ b/src/test/regress/sql/identity.sql
@@ -205,3 +205,17 @@ CREATE TABLE itest9 OF itest_type (
f1 WITH OPTIONS GENERATED ALWAYS AS IDENTITY); -- ok
\d itest9
DROP TYPE itest_type CASCADE;
+
+-- partitioned tables
+CREATE TABLE itest_parent (f1 date NOT NULL, f2 text, f3 bigint) PARTITION BY RANGE (f1);
+CREATE TABLE itest_child PARTITION OF itest_parent (
+ f4 WITH OPTIONS GENERATED ALWAYS AS IDENTITY
+) FOR VALUES FROM ('2016-07-01') TO ('2016-08-01'); -- error
+CREATE TABLE itest_child PARTITION OF itest_parent (
+ f2 WITH OPTIONS GENERATED ALWAYS AS IDENTITY
+) FOR VALUES FROM ('2016-07-01') TO ('2016-08-01'); -- error
+CREATE TABLE itest_child PARTITION OF itest_parent (
+ f3 WITH OPTIONS GENERATED ALWAYS AS IDENTITY
+) FOR VALUES FROM ('2016-07-01') TO ('2016-08-01'); -- ok
+\d itest_child
+DROP TABLE itest_parent;
--
2.11.0
^ permalink raw reply [nested|flat] 16+ messages in thread
* Re: BUG #14866: The generated constraint in the typed table causes the server to crash
@ 2017-11-10 02:33 Michael Paquier <michael.paquier@gmail.com>
parent: Amit Langote <Langote_Amit_f8@lab.ntt.co.jp>
0 siblings, 2 replies; 16+ messages in thread
From: Michael Paquier @ 2017-11-10 02:33 UTC (permalink / raw)
To: Amit Langote <Langote_Amit_f8@lab.ntt.co.jp>; +Cc: Peter Eisentraut <peter.eisentraut@2ndquadrant.com>; pgsql-bugs; Robert Haas <robertmhaas@gmail.com>; Amit Langote <amitlangote09@gmail.com>
On Thu, Nov 9, 2017 at 2:39 PM, Amit Langote
<Langote_Amit_f8@lab.ntt.co.jp> wrote:
> Sorry Michael. I didn't notice this in my gmail inbox until today.
No problem, happy to see your input on the matter. I took me a bit of
time to digest matters discussed on this thread a bit more.
> On 2017/11/01 23:05, Michael Paquier wrote:
>> On Wed, Nov 1, 2017 at 1:36 PM, Peter Eisentraut
>> <peter.eisentraut@2ndquadrant.com> wrote:
>>> I wonder whether we should even allow this. The SQL standard does not
>>> allow identity columns in typed tables, so there is support for that.
>>
>> OK. At the same time being able to support that is not complicated
>> either, even if the patch I sent earlier is a bit grotty in the way it
>> does handle it. I can see arguments in favor of either solution.
>
> Agree that it's not that hard to support IDENTITY on typed table columns.
Not that hard, still... See my arguments downthread.
> I rewrote your patch a bit so that it now makes transformColumnDefinition
> use the ColumnDef initialized by transformOfType which contains enough
> information to get the needed type OID. I think you might find it a bit
> simpler. :)
>
> Also, I carved it out into the attached patch 0001.
Yeah. I can see the difference.
>>> I'm not sure whether it makes sense in partitions. You are supposed to
>>> insert through the partition root, so making identity columns in
>>> partitions would just be confusing.
>>
>> Robert, Amit, do you have opinions on the matter? It is possible to
>> have multiple level of partitions as well.
>
> IMHO, we should support IDENTITY on partitions, just like we support
> specifying DEFAULT on partitions. We support issuing direct INSERT on
> partitions no matter where in the hierarchy it is, so having these
> features work normally makes sense to me.
Okay, yes there is room for support of such a feature.
> I looked at your patch and saw a minor problem with it. With your patch,
> there exists a lock-strength-upgrade deadlock hazard. It is making an
> earlier phase of partition creation (transformCreateStmt) take an
> AccessShareLock on the parent table, whereas a later phase
> (DefineRelation) will take an AccessExclusiveLock. I modified your patch
> to take the AccessExclusiveLock to begin with and added a comment nearby
> clarifying the same.
Yeah, I have been wondering about similar matters. Good thing that you
took the time to do a lookup. The proposed patches are really giving
me a bad feeling about all this as I look more at the code. Any lock
resolution done now happens within tablecmds.c, and not when doing the
parsing so I think that this patch needs actually far more work that
what's proposed. For one, it seems to me that CONST_IDENTITY handling
should be refactored so as they get a treatment similar to
CONSTR_CHECK and CONSTR_FOREIGN, which appends those clauses to
dedicated lists, which then creates sub-nodes in the ALTER TABLE code
paths. There is already a node for AddIdentity so it would be way
better to rely on that and make all lock resolutions remain there. And
for two, for typed tables, this patch adds another code path to
complain about ERRCODE_UNDEFINED_COLUMN, which is also a duplicate of
something that should fail in tablecmds.c in my opinion.
All in all, I would be more on board with just issuing errors when
trying to attempt typed table creation with identity columns and
partitions for now, by complaining with a
ERRCODE_FEATURE_NOT_SUPPORTED. Any person willing to add this support
later on could always provide a patch for it, I am now rather
convinced that what I proposed upthread is not the correct way to do
so, and there is no rush in implementing it correctly for v11 or even
later.
Peter, Robert, Amit, thoughts?
--
Michael
--
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs
^ permalink raw reply [nested|flat] 16+ messages in thread
* Re: BUG #14866: The generated constraint in the typed table causes the server to crash
@ 2017-11-11 09:11 Michael Paquier <michael.paquier@gmail.com>
parent: Michael Paquier <michael.paquier@gmail.com>
1 sibling, 1 reply; 16+ messages in thread
From: Michael Paquier @ 2017-11-11 09:11 UTC (permalink / raw)
To: Amit Langote <Langote_Amit_f8@lab.ntt.co.jp>; +Cc: Peter Eisentraut <peter.eisentraut@2ndquadrant.com>; pgsql-bugs; Robert Haas <robertmhaas@gmail.com>; Amit Langote <amitlangote09@gmail.com>
On Fri, Nov 10, 2017 at 11:33 AM, Michael Paquier
<michael.paquier@gmail.com> wrote:
> All in all, I would be more on board with just issuing errors when
> trying to attempt typed table creation with identity columns and
> partitions for now, by complaining with a
> ERRCODE_FEATURE_NOT_SUPPORTED. Any person willing to add this support
> later on could always provide a patch for it, I am now rather
> convinced that what I proposed upthread is not the correct way to do
> so, and there is no rush in implementing it correctly for v11 or even
> later.
>
> Peter, Robert, Amit, thoughts?
And this gives the attached. That still looks like the safest thing to
do for now on v10 and HEAD after more thoughts.
--
Michael
--
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs
Attachments:
tab-identity-crashes-v3.patch (text/x-patch, 3.7K) download
diff --git a/src/backend/parser/parse_utilcmd.c b/src/backend/parser/parse_utilcmd.c
index 8461da490a..979c05dd1d 100644
--- a/src/backend/parser/parse_utilcmd.c
+++ b/src/backend/parser/parse_utilcmd.c
@@ -92,6 +92,7 @@ typedef struct
IndexStmt *pkey; /* PRIMARY KEY index, if any */
bool ispartitioned; /* true if table is partitioned */
PartitionBoundSpec *partbound; /* transformed FOR VALUES */
+ bool ofType; /* true if statement contains OF typeName */
} CreateStmtContext;
/* State shared by transformCreateSchemaStmt and its subroutines */
@@ -240,6 +241,8 @@ transformCreateStmt(CreateStmt *stmt, const char *queryString)
cxt.alist = NIL;
cxt.pkey = NULL;
cxt.ispartitioned = stmt->partspec != NULL;
+ cxt.partbound = stmt->partbound;
+ cxt.ofType = stmt->ofTypename != NULL;
/*
* Notice that we allow OIDs here only for plain tables, even though
@@ -662,6 +665,20 @@ transformColumnDefinition(CreateStmtContext *cxt, ColumnDef *column)
Type ctype;
Oid typeOid;
+ /*
+ * If the statement is CREATE TABLE OF or works on a
+ * partition table, forbid the use of identity
+ * columns.
+ */
+ if (cxt->ofType)
+ ereport(ERROR,
+ (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
+ errmsg("identity colums are not supported on typed tables")));
+ if (cxt->partbound)
+ ereport(ERROR,
+ (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
+ errmsg("identify columns are not supported on partition tables")));
+
ctype = typenameType(cxt->pstate, column->typeName, NULL);
typeOid = HeapTupleGetOid(ctype);
ReleaseSysCache(ctype);
@@ -2697,6 +2714,7 @@ transformAlterTableStmt(Oid relid, AlterTableStmt *stmt,
cxt.pkey = NULL;
cxt.ispartitioned = (rel->rd_rel->relkind == RELKIND_PARTITIONED_TABLE);
cxt.partbound = NULL;
+ cxt.ofType = false;
/*
* The only subtypes that currently require parse transformation handling
diff --git a/src/test/regress/expected/identity.out b/src/test/regress/expected/identity.out
index 5fa585d6cc..12ebb3389e 100644
--- a/src/test/regress/expected/identity.out
+++ b/src/test/regress/expected/identity.out
@@ -333,3 +333,16 @@ SELECT * FROM itest8;
RESET ROLE;
DROP TABLE itest8;
DROP USER regress_user1;
+-- Typed tables are not supported.
+CREATE TYPE itest_type AS (f1 integer, f2 text, f3 bigint);
+CREATE TABLE itest9 OF itest_type (
+ f1 WITH OPTIONS GENERATED ALWAYS AS IDENTITY); -- error
+ERROR: identity colums are not supported on typed tables
+DROP TYPE itest_type CASCADE;
+-- Partition tables are not supported.
+CREATE TABLE itest_parent (f1 date NOT NULL, f2 text, f3 bigint) PARTITION BY RANGE (f1);
+CREATE TABLE itest_child PARTITION OF itest_parent (
+ f3 WITH OPTIONS GENERATED ALWAYS AS IDENTITY
+) FOR VALUES FROM ('2016-07-01') TO ('2016-08-01'); -- error
+ERROR: identify columns are not supported on partition tables
+DROP TABLE itest_parent;
diff --git a/src/test/regress/sql/identity.sql b/src/test/regress/sql/identity.sql
index e1b5a074c9..a371fdea64 100644
--- a/src/test/regress/sql/identity.sql
+++ b/src/test/regress/sql/identity.sql
@@ -194,3 +194,16 @@ SELECT * FROM itest8;
RESET ROLE;
DROP TABLE itest8;
DROP USER regress_user1;
+
+-- Typed tables are not supported.
+CREATE TYPE itest_type AS (f1 integer, f2 text, f3 bigint);
+CREATE TABLE itest9 OF itest_type (
+ f1 WITH OPTIONS GENERATED ALWAYS AS IDENTITY); -- error
+DROP TYPE itest_type CASCADE;
+
+-- Partition tables are not supported.
+CREATE TABLE itest_parent (f1 date NOT NULL, f2 text, f3 bigint) PARTITION BY RANGE (f1);
+CREATE TABLE itest_child PARTITION OF itest_parent (
+ f3 WITH OPTIONS GENERATED ALWAYS AS IDENTITY
+) FOR VALUES FROM ('2016-07-01') TO ('2016-08-01'); -- error
+DROP TABLE itest_parent;
^ permalink raw reply [nested|flat] 16+ messages in thread
* Re: BUG #14866: The generated constraint in the typed table causes the server to crash
@ 2017-11-13 07:32 Amit Langote <Langote_Amit_f8@lab.ntt.co.jp>
parent: Michael Paquier <michael.paquier@gmail.com>
1 sibling, 1 reply; 16+ messages in thread
From: Amit Langote @ 2017-11-13 07:32 UTC (permalink / raw)
To: Michael Paquier <michael.paquier@gmail.com>; +Cc: Peter Eisentraut <peter.eisentraut@2ndquadrant.com>; pgsql-bugs; Robert Haas <robertmhaas@gmail.com>; Amit Langote <amitlangote09@gmail.com>
On 2017/11/10 11:33, Michael Paquier wrote:
> On Thu, Nov 9, 2017 at 2:39 PM, Amit Langote wrote:
>> I looked at your patch and saw a minor problem with it. With your patch,
>> there exists a lock-strength-upgrade deadlock hazard. It is making an
>> earlier phase of partition creation (transformCreateStmt) take an
>> AccessShareLock on the parent table, whereas a later phase
>> (DefineRelation) will take an AccessExclusiveLock. I modified your patch
>> to take the AccessExclusiveLock to begin with and added a comment nearby
>> clarifying the same.
>
> Yeah, I have been wondering about similar matters. Good thing that you
> took the time to do a lookup. The proposed patches are really giving
> me a bad feeling about all this as I look more at the code. Any lock
> resolution done now happens within tablecmds.c, and not when doing the
> parsing so I think that this patch needs actually far more work that
> what's proposed.
*After* the patch 0002 for partition tables, lock on the parent table is
taken by parse_utilcmds.c, not tablecmds.c anymore, which is what I'm
assuming you said above.
> For one, it seems to me that CONST_IDENTITY handling
> should be refactored so as they get a treatment similar to
> CONSTR_CHECK and CONSTR_FOREIGN, which appends those clauses to
> dedicated lists, which then creates sub-nodes in the ALTER TABLE code
> paths. There is already a node for AddIdentity so it would be way
> better to rely on that and make all lock resolutions remain there. And
I got similar feelings about that. As you seem to say say, it would be
nice if generateSerialExtraStmts() didn't add the CreateSeqStmt and
AlterSeqStmt nodes directly to CreateStmtCxt.blist and
CreateStmtCxt.alist, respectively.
However, as you might know, any processing that needs a CreateStmtContext
and manipulates its blist and alist fields must occur within
parse_utilcmds.c. If following that rule means we now have to take the
lock on the partition's parent table earlier than it used to, then I don't
see a problem with it, although I may be missing something.
In early versions of the partitioning patch, there used to be a
transformPartitionOf() which would do the same job as transformOfType(),
that is, make new ColumnDef's from the parent table's attributes. But, I
removed it in favor of making MergeAttributes() create those ColumnDef's,
because the latter needed to lock and open the parent anyway. However, to
handle identity columns, it seems we might need to go back to having a
transformPartitionOf() after all, but it's going to be quite some work.
> for two, for typed tables, this patch adds another code path to
> complain about ERRCODE_UNDEFINED_COLUMN, which is also a duplicate of
> something that should fail in tablecmds.c in my opinion.
The duplication is unfortunate, but the code in tablecmds.c you seem to be
talking about (in MergeAttributes()) won't be able to satisfy the
requirement that the sequence for the identity column of a typed table be
created before the table itself is created. By that point, we're already
in DefineRelation() creating the table. In fact, I think to fix the
duplication, it might be better to work on removing the relevant code in
MergeAttributes().
Anyway, I agree with you that the code restructuring required might be
hard to commit as bug fix in the v10 branch. So your downthread patch
that produces error upon specifying IDENTITY option for typed table or
partition table columns seems like a good compromise for now.
Thanks,
Amit
--
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs
^ permalink raw reply [nested|flat] 16+ messages in thread
* Re: BUG #14866: The generated constraint in the typed table causes the server to crash
@ 2017-11-13 07:33 Amit Langote <Langote_Amit_f8@lab.ntt.co.jp>
parent: Michael Paquier <michael.paquier@gmail.com>
0 siblings, 1 reply; 16+ messages in thread
From: Amit Langote @ 2017-11-13 07:33 UTC (permalink / raw)
To: Michael Paquier <michael.paquier@gmail.com>; +Cc: Peter Eisentraut <peter.eisentraut@2ndquadrant.com>; pgsql-bugs; Robert Haas <robertmhaas@gmail.com>; Amit Langote <amitlangote09@gmail.com>
On 2017/11/11 18:11, Michael Paquier wrote:
> On Fri, Nov 10, 2017 at 11:33 AM, Michael Paquier
> <michael.paquier@gmail.com> wrote:
>> All in all, I would be more on board with just issuing errors when
>> trying to attempt typed table creation with identity columns and
>> partitions for now, by complaining with a
>> ERRCODE_FEATURE_NOT_SUPPORTED. Any person willing to add this support
>> later on could always provide a patch for it, I am now rather
>> convinced that what I proposed upthread is not the correct way to do
>> so, and there is no rush in implementing it correctly for v11 or even
>> later.
>>
>> Peter, Robert, Amit, thoughts?
>
> And this gives the attached. That still looks like the safest thing to
> do for now on v10 and HEAD after more thoughts.
That looks good to me. That is, if the consensus turns out to be that we
issue error in those cases.
Thanks,
Amit
--
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs
^ permalink raw reply [nested|flat] 16+ messages in thread
* Re: [BUGS] BUG #14866: The generated constraint in the typed table causes the server to crash
@ 2017-11-15 01:23 Michael Paquier <michael.paquier@gmail.com>
parent: Amit Langote <Langote_Amit_f8@lab.ntt.co.jp>
0 siblings, 1 reply; 16+ messages in thread
From: Michael Paquier @ 2017-11-15 01:23 UTC (permalink / raw)
To: Amit Langote <Langote_Amit_f8@lab.ntt.co.jp>; +Cc: Peter Eisentraut <peter.eisentraut@2ndquadrant.com>; pgsql-bugs; Robert Haas <robertmhaas@gmail.com>; Amit Langote <amitlangote09@gmail.com>
On Mon, Nov 13, 2017 at 4:32 PM, Amit Langote
<Langote_Amit_f8@lab.ntt.co.jp> wrote:
> In early versions of the partitioning patch, there used to be a
> transformPartitionOf() which would do the same job as transformOfType(),
> that is, make new ColumnDef's from the parent table's attributes. But, I
> removed it in favor of making MergeAttributes() create those ColumnDef's,
> because the latter needed to lock and open the parent anyway. However, to
> handle identity columns, it seems we might need to go back to having a
> transformPartitionOf() after all, but it's going to be quite some work.
Another idea that could be done here is to rework as well
transformOfType() so as its column definition logic is pulled down to
MergeAttributes(). There is some logic telling that the typed columns
are first in the list. That's not lovely IMO.
>> for two, for typed tables, this patch adds another code path to
>> complain about ERRCODE_UNDEFINED_COLUMN, which is also a duplicate of
>> something that should fail in tablecmds.c in my opinion.
>
> The duplication is unfortunate, but the code in tablecmds.c you seem to be
> talking about (in MergeAttributes()) won't be able to satisfy the
> requirement that the sequence for the identity column of a typed table be
> created before the table itself is created. By that point, we're already
> in DefineRelation() creating the table. In fact, I think to fix the
> duplication, it might be better to work on removing the relevant code in
> MergeAttributes().
Yeah, possibly. This really requires more thinking as we likely don't
want to make the code more a mess than it is now. There is no urgency
in getting things refactored now anyway. And perhaps there will be no
need to do so.
--
Michael
^ permalink raw reply [nested|flat] 16+ messages in thread
* Re: [BUGS] BUG #14866: The generated constraint in the typed table causes the server to crash
@ 2017-11-28 01:39 Michael Paquier <michael.paquier@gmail.com>
parent: Michael Paquier <michael.paquier@gmail.com>
0 siblings, 1 reply; 16+ messages in thread
From: Michael Paquier @ 2017-11-28 01:39 UTC (permalink / raw)
To: Peter Eisentraut <peter.eisentraut@2ndquadrant.com>; +Cc: pgsql-bugs; Robert Haas <robertmhaas@gmail.com>; Amit Langote <amitlangote09@gmail.com>; Amit Langote <Langote_Amit_f8@lab.ntt.co.jp>
On Wed, Nov 15, 2017 at 10:23 AM, Michael Paquier
<michael.paquier@gmail.com> wrote:
> Yeah, possibly. This really requires more thinking as we likely don't
> want to make the code more a mess than it is now. There is no urgency
> in getting things refactored now anyway. And perhaps there will be no
> need to do so.
Peter, you are marked as a reviewer of this patch which is a bug fix.
Are you planning to look at it? For now I am bumping it to the next
CF.
--
Michael
^ permalink raw reply [nested|flat] 16+ messages in thread
* Re: [BUGS] BUG #14866: The generated constraint in the typed table causes the server to crash
@ 2017-11-28 16:37 Peter Eisentraut <peter.eisentraut@2ndquadrant.com>
parent: Michael Paquier <michael.paquier@gmail.com>
0 siblings, 0 replies; 16+ messages in thread
From: Peter Eisentraut @ 2017-11-28 16:37 UTC (permalink / raw)
To: Michael Paquier <michael.paquier@gmail.com>; +Cc: pgsql-bugs; Robert Haas <robertmhaas@gmail.com>; Amit Langote <amitlangote09@gmail.com>; Amit Langote <Langote_Amit_f8@lab.ntt.co.jp>
On 11/27/17 20:39, Michael Paquier wrote:
> On Wed, Nov 15, 2017 at 10:23 AM, Michael Paquier
> <michael.paquier@gmail.com> wrote:
>> Yeah, possibly. This really requires more thinking as we likely don't
>> want to make the code more a mess than it is now. There is no urgency
>> in getting things refactored now anyway. And perhaps there will be no
>> need to do so.
>
> Peter, you are marked as a reviewer of this patch which is a bug fix.
> Are you planning to look at it? For now I am bumping it to the next
> CF.
I'll look at it at some point.
--
Peter Eisentraut http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services
^ permalink raw reply [nested|flat] 16+ messages in thread
* Re: [BUGS] BUG #14866: The generated constraint in the typed table causes the server to crash
@ 2017-12-08 17:27 Peter Eisentraut <peter.eisentraut@2ndquadrant.com>
parent: Amit Langote <Langote_Amit_f8@lab.ntt.co.jp>
0 siblings, 1 reply; 16+ messages in thread
From: Peter Eisentraut @ 2017-12-08 17:27 UTC (permalink / raw)
To: Amit Langote <Langote_Amit_f8@lab.ntt.co.jp>; Michael Paquier <michael.paquier@gmail.com>; +Cc: pgsql-bugs; Robert Haas <robertmhaas@gmail.com>; Amit Langote <amitlangote09@gmail.com>
On 11/13/17 02:33, Amit Langote wrote:
> On 2017/11/11 18:11, Michael Paquier wrote:
>> On Fri, Nov 10, 2017 at 11:33 AM, Michael Paquier
>> <michael.paquier@gmail.com> wrote:
>>> All in all, I would be more on board with just issuing errors when
>>> trying to attempt typed table creation with identity columns and
>>> partitions for now, by complaining with a
>>> ERRCODE_FEATURE_NOT_SUPPORTED. Any person willing to add this support
>>> later on could always provide a patch for it, I am now rather
>>> convinced that what I proposed upthread is not the correct way to do
>>> so, and there is no rush in implementing it correctly for v11 or even
>>> later.
>>>
>>> Peter, Robert, Amit, thoughts?
>>
>> And this gives the attached. That still looks like the safest thing to
>> do for now on v10 and HEAD after more thoughts.
>
> That looks good to me. That is, if the consensus turns out to be that we
> issue error in those cases.
committed
--
Peter Eisentraut http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services
^ permalink raw reply [nested|flat] 16+ messages in thread
* Re: [BUGS] BUG #14866: The generated constraint in the typed table causes the server to crash
@ 2017-12-09 04:00 Michael Paquier <michael.paquier@gmail.com>
parent: Peter Eisentraut <peter.eisentraut@2ndquadrant.com>
0 siblings, 1 reply; 16+ messages in thread
From: Michael Paquier @ 2017-12-09 04:00 UTC (permalink / raw)
To: Peter Eisentraut <peter.eisentraut@2ndquadrant.com>; +Cc: Amit Langote <Langote_Amit_f8@lab.ntt.co.jp>; pgsql-bugs; Robert Haas <robertmhaas@gmail.com>; Amit Langote <amitlangote09@gmail.com>
On Sat, Dec 9, 2017 at 2:27 AM, Peter Eisentraut
<peter.eisentraut@2ndquadrant.com> wrote:
> committed
Thanks, Peter and Amit.
--
Michael
^ permalink raw reply [nested|flat] 16+ messages in thread
* Re: [BUGS] BUG #14866: The generated constraint in the typed table causes the server to crash
@ 2017-12-11 01:08 Amit Langote <Langote_Amit_f8@lab.ntt.co.jp>
parent: Michael Paquier <michael.paquier@gmail.com>
0 siblings, 0 replies; 16+ messages in thread
From: Amit Langote @ 2017-12-11 01:08 UTC (permalink / raw)
To: Michael Paquier <michael.paquier@gmail.com>; Peter Eisentraut <peter.eisentraut@2ndquadrant.com>; +Cc: pgsql-bugs; Robert Haas <robertmhaas@gmail.com>; Amit Langote <amitlangote09@gmail.com>
On 2017/12/09 13:00, Michael Paquier wrote:
> On Sat, Dec 9, 2017 at 2:27 AM, Peter Eisentraut
> <peter.eisentraut@2ndquadrant.com> wrote:
>> committed
>
> Thanks, Peter and Amit.
Thank you too.
Regards,
Amit
^ permalink raw reply [nested|flat] 16+ messages in thread
end of thread, other threads:[~2017-12-11 01:08 UTC | newest]
Thread overview: 16+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2017-10-23 07:44 BUG #14866: The generated constraint in the typed table causes the server to crash gomer94@yandex.ru
2017-10-23 14:09 ` Michael Paquier <michael.paquier@gmail.com>
2017-10-23 22:21 ` Michael Paquier <michael.paquier@gmail.com>
2017-11-01 13:36 ` Peter Eisentraut <peter.eisentraut@2ndquadrant.com>
2017-11-01 14:05 ` Michael Paquier <michael.paquier@gmail.com>
2017-11-09 05:39 ` Amit Langote <Langote_Amit_f8@lab.ntt.co.jp>
2017-11-10 02:33 ` Michael Paquier <michael.paquier@gmail.com>
2017-11-11 09:11 ` Michael Paquier <michael.paquier@gmail.com>
2017-11-13 07:33 ` Amit Langote <Langote_Amit_f8@lab.ntt.co.jp>
2017-12-08 17:27 ` Peter Eisentraut <peter.eisentraut@2ndquadrant.com>
2017-12-09 04:00 ` Michael Paquier <michael.paquier@gmail.com>
2017-12-11 01:08 ` Amit Langote <Langote_Amit_f8@lab.ntt.co.jp>
2017-11-13 07:32 ` Amit Langote <Langote_Amit_f8@lab.ntt.co.jp>
2017-11-15 01:23 ` Michael Paquier <michael.paquier@gmail.com>
2017-11-28 01:39 ` Michael Paquier <michael.paquier@gmail.com>
2017-11-28 16:37 ` Peter Eisentraut <peter.eisentraut@2ndquadrant.com>
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