Re: [BUGS] BUG #14866: The generated constraint in the typed tablecauses the server to crash - Mailing list pgsql-bugs

From Michael Paquier
Subject Re: [BUGS] BUG #14866: The generated constraint in the typed tablecauses the server to crash
Date
Msg-id CAB7nPqS+ofdMRy4+pNrLDyN6My6xDutX5SN_ObbJdKasYNH7wQ@mail.gmail.com
Whole thread Raw
In response to Re: [BUGS] BUG #14866: The generated constraint in the typed tablecauses the server to crash  (Michael Paquier <michael.paquier@gmail.com>)
Responses Re: [BUGS] BUG #14866: The generated constraint in the typed tablecauses the server to crash  (Peter Eisentraut <peter.eisentraut@2ndquadrant.com>)
List pgsql-bugs
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

Attachment

pgsql-bugs by date:

Previous
From: Chris Hanks
Date:
Subject: Re: [BUGS] Connections hang indefinitely while taking a LWLockTranchebuffer_content lock.
Next
From: tschimail1@gmail.com
Date:
Subject: [BUGS] BUG #14868: Postgres as Windows Service doesn't shutdown properly