Re: logical column ordering

From: Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>
To: Tomas Vondra <tomas(dot)vondra(at)2ndquadrant(dot)com>
Cc: Josh Berkus <josh(at)agliodbs(dot)com>, Arthur Silva <arthurprs(at)gmail(dot)com>, Andres Freund <andres(at)2ndquadrant(dot)com>, Jim Nasby <Jim(dot)Nasby(at)bluetreble(dot)com>, "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: logical column ordering
Date: 2015-03-01 15:08:13
Message-ID: 20150301150813.GS2384@alvh.no-ip.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Tomas Vondra wrote:

> > We need an API for physical column reordering, even if it's just pg_
> > functions. The reason is that we want to enable people writing their
> > own physical column re-ordering tools, so that our users can figure out
> > for us what the best reordering algorithm is.
>
> I doubt that. For example, do you realize you can only do that while the
> table is completely empty, and in that case you can just do a CREATE
> TABLE with the proper order?

Not if you have views or constraints depending on the table definition
-- it's not trivial to drop/recreate the table in that case, but you can
of course think about truncating it, then reorder columns, then
repopulate.

Even better you can cause a full table rewrite if needed.

> But if we want to allow users to define this, I'd say let's make that
> part of CREATE TABLE, i.e. the order of columns defines logical order,
> and you use something like 'AFTER' to specify physical order.
>
> CREATE TABLE test (
> a INT AFTER b, -- attlognum = 1, attphysnum = 2
> b INT -- attlognum = 2, attphysnum = 1
> );

Surely you want an ALTER command as a minimum; perhaps that is enough
and there is no need for options in CREATE.

> It might get tricky because of cycles, though.

If there's a cycle, just raise an error.

--
Álvaro Herrera http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Alvaro Herrera 2015-03-01 15:09:22 Re: logical column ordering
Previous Message Stephen Frost 2015-03-01 15:03:29 Re: Enforce creation of destination folders for source files in pg_regress (Was: pg_regress writes into source tree)