Обсуждение: Re: [HACKERS] Minor correction in alter_table.sgml

Поиск
Список
Период
Сортировка

Re: [HACKERS] Minor correction in alter_table.sgml

От
Tom Lane
Дата:
Alvaro Herrera <alvherre@2ndquadrant.com> writes:
>> I had considered removing those but thought that some users might think
>> that they're only "altering" one table and therefore felt it made sense
>> to keep those explicitly listed.

> I agree with Stephen; it's not crystal clear from the user's POV that
> the command is altering two tables.  It's worth mentioning this
> explicitly; otherwise this is just a documented gotcha.

Well, it already is shown explicitly in the syntax summary.  The text
is simply trying to restate that in an easily remembered fashion, and
the more exceptions, the harder it is to remember.  You might as well
forget trying to provide a rule at all and just say something like
"Most forms of ALTER TABLE can be combined, except as shown in the
syntax diagram."

(Of course, maybe the question we ought to be asking here is why
ATTACH/DETACH PARTITION failed to go with the flow and be a
combinable action.)
        regards, tom lane



Re: [HACKERS] Minor correction in alter_table.sgml

От
Stephen Frost
Дата:
* Tom Lane (tgl@sss.pgh.pa.us) wrote:
> Alvaro Herrera <alvherre@2ndquadrant.com> writes:
> >> I had considered removing those but thought that some users might think
> >> that they're only "altering" one table and therefore felt it made sense
> >> to keep those explicitly listed.
>
> > I agree with Stephen; it's not crystal clear from the user's POV that
> > the command is altering two tables.  It's worth mentioning this
> > explicitly; otherwise this is just a documented gotcha.
>
> Well, it already is shown explicitly in the syntax summary.  The text
> is simply trying to restate that in an easily remembered fashion, and
> the more exceptions, the harder it is to remember.  You might as well
> forget trying to provide a rule at all and just say something like
> "Most forms of ALTER TABLE can be combined, except as shown in the
> syntax diagram."

I do wonder if perhaps we should change 'action' to something like
'combinable_action' or something more explicit which we could easily
refer to later in a statement along the lines of:
 Multiple combinable_actions specified in a single ALTER TABLE statement will be applied together in a single pass over
thetable. 

> (Of course, maybe the question we ought to be asking here is why
> ATTACH/DETACH PARTITION failed to go with the flow and be a
> combinable action.)

I did wonder that myself but havne't looked at the code.  I'm guessing
there's a reason it's that way.

Thanks!

Stephen

Re: [HACKERS] Minor correction in alter_table.sgml

От
Amit Langote
Дата:
On Fri, Dec 23, 2016 at 12:07 AM, Stephen Frost <sfrost@snowman.net> wrote:
> * Tom Lane (tgl@sss.pgh.pa.us) wrote:
>> (Of course, maybe the question we ought to be asking here is why
>> ATTACH/DETACH PARTITION failed to go with the flow and be a
>> combinable action.)
>
> I did wonder that myself but havne't looked at the code.  I'm guessing
> there's a reason it's that way.

I thought the possibility of something like the following happening
should be avoided:

alter table p attach partition p1 for values in (1, 2, 3), add b int;
ERROR:  child table is missing column "b"

Although, the same can be said about ALTER TABLE child INHERIT parent, I guess.

Thanks,
Amit



Re: [HACKERS] Minor correction in alter_table.sgml

От
Stephen Frost
Дата:
Amit,

* Amit Langote (amitlangote09@gmail.com) wrote:
> On Fri, Dec 23, 2016 at 12:07 AM, Stephen Frost <sfrost@snowman.net> wrote:
> > * Tom Lane (tgl@sss.pgh.pa.us) wrote:
> >> (Of course, maybe the question we ought to be asking here is why
> >> ATTACH/DETACH PARTITION failed to go with the flow and be a
> >> combinable action.)
> >
> > I did wonder that myself but havne't looked at the code.  I'm guessing
> > there's a reason it's that way.
>
> I thought the possibility of something like the following happening
> should be avoided:
>
> alter table p attach partition p1 for values in (1, 2, 3), add b int;
> ERROR:  child table is missing column "b"

Sure, but what about something like:

alter table p attach partition p1 for values in (1, 2, 3), alter column
b set default 1; ?

> Although, the same can be said about ALTER TABLE child INHERIT parent, I guess.

Certainly seems like that's an indication that there are use-cases for
allowing it then.  We do tend to avoid arbitrary restrictions and if
there isn't really anything code-level for ATTACH/DETACH partition to be
this way then we change it to be allowed.

Thanks!

Stephen