Re: Boolean partitions syntax

Поиск
Список
Период
Сортировка
От David Rowley
Тема Re: Boolean partitions syntax
Дата
Msg-id CAKJS1f9VtCHmbAvPLiL40Txgh_fSXmfer4DNrLTaSxc7OvQ6ng@mail.gmail.com
обсуждение исходный текст
Ответ на Re: Boolean partitions syntax  (Tom Lane <tgl@sss.pgh.pa.us>)
Ответы Re: Boolean partitions syntax  (Tom Lane <tgl@sss.pgh.pa.us>)
Список pgsql-hackers
On 11 April 2018 at 03:34, Tom Lane <tgl@sss.pgh.pa.us> wrote:
> David Rowley <david.rowley@2ndquadrant.com> writes:
>> I imagined this would have had a check for volatile functions and some
>> user-friendly error message to say partition bounds must be immutable,
>> but instead, it does:
>
>> postgres=# create table d_p1 partition of d for values in (Random());
>> ERROR:  specified value cannot be cast to type double precision for column "d"
>> LINE 1: create table d_p1 partition of d for values in (Random());
>>                                                         ^
>> DETAIL:  The cast requires a non-immutable conversion.
>> HINT:  Try putting the literal value in single quotes.
>
>> For inspiration, maybe you could follow the lead of CREATE INDEX:
>
>> postgres=# create index on d ((random()));
>> ERROR:  functions in index expression must be marked IMMUTABLE
>
> 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. What other DDL will
execute a volatile function? What if the volatile function has side
effects? What if the user didn't want the function evaluated and
somehow thought they wanted the evaluation to take place on INSERT?

I imagine if someone does this then they're probably doing something
wrong, and we should tell them, rather than perhaps silently doing
something they don't want. Perhaps someone might think they can
randomly distribute records into a set of partitions with something
like: for values in(((random() * 1000)::int between 0 and 100)), they
might be surprised when all their records end up in the same (random)
partition.

If we did this, then it seems like we're more likely to live to regret
doing it, rather than regret not doing it.  If someone comes along and
gives us some valid use case in the future, then maybe it can be
considered then. I just can't imagine what that use case would be...

-- 
 David Rowley                   http://www.2ndQuadrant.com/
 PostgreSQL Development, 24x7 Support, Training & Services


В списке pgsql-hackers по дате отправления:

Предыдущее
От: Alvaro Herrera
Дата:
Сообщение: Re: pgsql: Support partition pruning at execution time
Следующее
От: Magnus Hagander
Дата:
Сообщение: Re: [PATCH] pg_hba.conf : new auth option : clientcert=verify-full