Re: Boolean partitions syntax

From: "Jonathan S(dot) Katz" <jonathan(dot)katz(at)excoventures(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: David Rowley <david(dot)rowley(at)2ndquadrant(dot)com>, Kyotaro HORIGUCHI <horiguchi(dot)kyotaro(at)lab(dot)ntt(dot)co(dot)jp>, Peter Eisentraut <peter(dot)eisentraut(at)2ndquadrant(dot)com>, Amit Langote <Langote_Amit_f8(at)lab(dot)ntt(dot)co(dot)jp>, David Steele <david(at)pgmasters(dot)net>, Andres Freund <andres(at)anarazel(dot)de>, Robert Haas <robertmhaas(at)gmail(dot)com>, Stephen Frost <sfrost(at)snowman(dot)net>, Mark Dilger <hornschnorter(at)gmail(dot)com>, Dilip Kumar <dilipbalaut(at)gmail(dot)com>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Boolean partitions syntax
Date: 2018-04-10 18:01:34
Message-ID: 123D3E14-0121-4A33-86DC-CB809392F7A2@excoventures.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers


> On Apr 10, 2018, at 1:22 PM, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
>
> David Rowley <david(dot)rowley(at)2ndquadrant(dot)com> writes:
>> On 11 April 2018 at 03:34, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
>>> Well, that just begs the question: why do these expressions need to
>>> be immutable? What we really want, I think, is to evaluate them
>>> and reduce them to constants. After that, it hardly matters whether
>>> the original expression was volatile. I see absolutely no moral
>>> difference between "for values in (random())" and cases like
>>> this, which works today:
>
>> I'd personally be pretty surprised if this worked.
>
> Well, my point is that we're *already* behaving that way in some cases,
> simply because of the existence of macro-like inputs for some of these
> datatypes. I'm not sure that users are going to perceive a big difference
> between 'now'::timestamptz and now(), for example. If we take one but
> not the other, I don't think anybody will see that as a feature.

+1. Also, one hopes that a user tests their code prior to rolling it out
into a production environment, so a case like the “random()” example
has already been vetted as either not something for their partition, or
they want a one-time randomly generated number to determine how
things are partitioned.

>> What other DDL will execute a volatile function?
>
> This might be a valid concern, not sure. It's certainly true that
> most other DDL doesn't result in acquiring a transaction snapshot;
> but it's not *universally* true. Certainly there's DDL that can
> execute nigh-arbitrary user code, such as CREATE INDEX.
>
>> What if the volatile function has side
>> effects?
>
> Can't say that that bothers me. If the user has thought about what
> they're doing, the results won't surprise them; if they haven't,
> they're likely to be surprised in any case.

+1. I’m all for protecting users from themselves, but there’s only so
much you can do. This is where we can make up any knowledge
gap with documentation.

> We might be well advised to do a CCI after evaluating the expressions,
> but that could still be before anything interesting happens.
>
>> What if the user didn't want the function evaluated and
>> somehow thought they wanted the evaluation to take place on INSERT?
>
> You could object to awfully large chunks of SQL on the grounds that
> it might confuse somebody.

That's truer than you may think.

At the end of the day, a user wants to be able to create a partition
with the syntax that they expect from working with other parts of the
database. If we have clear documentation, e.g. “If you use a volatile
function for a partition, it will only be executed once” etc. should be enough
to educate, or at least say we provided notice about the behavior.

Jonathan

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Andrew Dunstan 2018-04-10 18:10:14 Re: [sqlsmith] Segfault in expand_tuple
Previous Message Robert Haas 2018-04-10 17:57:54 Re: Function to track shmem reinit time