Re: BUG #15212: Default values in partition tables don't work as expected and allow NOT NULL violation

From: Jürgen Strobel <juergen+postgresql(at)strobel(dot)info>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, Amit Langote <Langote_Amit_f8(at)lab(dot)ntt(dot)co(dot)jp>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: BUG #15212: Default values in partition tables don't work as expected and allow NOT NULL violation
Date: 2018-11-13 12:44:03
Message-ID: dc3d80bb-87ab-496b-b6ce-396bba0eccda@strobel.info
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs pgsql-hackers

On 2018-11-13 00:57, Tom Lane wrote:
> =?UTF-8?Q?J=c3=bcrgen_Strobel?= <juergen+postgresql(at)strobel(dot)info> writes:
>> On 2018-11-12 17:33, Tom Lane wrote:
>>> I'm not entirely convinced that I buy that argument, especially not in
>>> a case like this where it introduces logical inconsistencies where there
>>> otherwise wouldn't be any.
>
>> I think I missed something, what are the *introduced* logical problems?
>
> What to do if a partition introduces a default value that would force
> re-routing to some other partition.

I would claim this is a problem which already exists with the current
behavior:

a) If a tuple is inserted through the parent it's ignored and useless.
b) If a tuple is inserted through the partition it can lead to
inconsistency and a constraint violation (possibly rectifiable by a
re-route which I think we all agree is out of the question).

>> Apart from implementation issues the only logical problems I see are if
>> you allow to change defaults of the partition key columns, and these are
>> problematic (nonsensical really) in either case.
>
> Just claiming that it's nonsensical doesn't fix the problem. Also, it
> is neither problematic nor nonsensical for the root to provide defaults
> for partition key columns. So if we go this route, we are giving up
> useful behavior (key-column defaults on the root) for useless behavior
> (key-column defaults on the partitions).

Yes, I strongly believe defaults on the key columns in partitions should
be disallowed, that's why I called them nonsensical in both cases, see
above a) and b) for why this applies even to current behavior.

Of course disallowing all DEFAULT clauses on partitions is the easiest
way out, and I'd rather see this than inserts through partitions being
more than a pure optimization.

Best regards,
Jürgen

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Peter Eisentraut 2018-11-13 12:52:50 Re: Usage of pg_waldump
Previous Message Lukas Eder 2018-11-13 10:01:45 Re: BUG #15356: Inconsistent documentation about CREATE TYPE

Browse pgsql-hackers by date

  From Date Subject
Next Message Dmitry Dolgov 2018-11-13 12:47:52 Re: using index or check in ALTER TABLE SET NOT NULL
Previous Message Amit Kapila 2018-11-13 12:17:25 Re: Race condition in WaitForBackgroundWorkerStartup