From: PG Bug reporting form <noreply@postgresql.org>
To: pgsql-bugs@lists.postgresql.org
Cc: alexey.ermakov@dataegret.com
Subject: BUG #15113: alter table .. add column .. default null leads to table rewrite
Date: Thu, 15 Mar 2018 06:41:01 +0000
Message-ID: <152109606107.1215.5847972621624822423@wrigleys.postgresql.org> (raw)
The following bug has been logged on the website:
Bug reference: 15113
Logged by: Alexey Ermakov
Email address: alexey.ermakov@dataegret.com
PostgreSQL version: 9.6.8
Operating system: Linux
Description:
Hello,
I've recently discovered that following 2 alters produces different
results:
alter table xx add column yy1 character varying(10) default null;
alter table xx add column yy2 character varying(10);
yy1 | character varying(10) | default NULL::character varying
| extended | |
yy2 | character varying(10) |
| extended | |
First one will lead to table rewrite which might be surprising since there
is no such difference for types without constraints, last one won't.
I found this comment which I think explains why this happens in
https://github.com/postgres/postgres/blob/REL_10_STABLE/src/backend/commands/tablecmds.c#L5323:
* An exception occurs when the new column is of a domain type: the
domain
* might have a NOT NULL constraint, or a check constraint that
indirectly
* rejects nulls. If there are any domain constraints then we construct
* an explicit NULL default value that will be passed through
* CoerceToDomain processing. (This is a tad inefficient, since it
causes
* rewriting the table which we really don't have to do, but the present
* design of domain processing doesn't offer any simple way of checking
* the constraints more directly.)
Perhaps something need to be changed to handle such cases better.
Thanks,
Alexey Ermakov
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 from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-bugs@postgresql.org
Cc: noreply@postgresql.org, alexey.ermakov@dataegret.com
Subject: Re: BUG #15113: alter table .. add column .. default null leads to table rewrite
In-Reply-To: <152109606107.1215.5847972621624822423@wrigleys.postgresql.org>
References: <152109606107.1215.5847972621624822423@wrigleys.postgresql.org>
* 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