Re: logical column ordering - Mailing list pgsql-hackers

From David Steele
Subject Re: logical column ordering
Date
Msg-id 54EFC38A.7000406@pgmasters.net
Whole thread Raw
In response to Re: logical column ordering  (Jim Nasby <Jim.Nasby@BlueTreble.com>)
Responses Re: logical column ordering  (Gavin Flower <GavinFlower@archidevsys.co.nz>)
List pgsql-hackers
On 2/26/15 1:49 PM, Jim Nasby wrote:
> On 2/23/15 5:09 PM, Tomas Vondra wrote:
>> Over the time I've heard various use cases for this patch, but in most
>> cases it was quite speculative. If you have an idea where this might be
>> useful, can you explain it here, or maybe point me to a place where it's
>> described?
>
> For better or worse, table structure is a form of documentation for a
> system. As such, it's very valuable to group related fields in a table
> together. When creating a table, that's easy, but as soon as you need to
> alter your careful ordering can easily end up out the window.
>
> Perhaps to some that just sounds like pointless window dressing, but my
> experience is that on a complex system the less organized things are the
> more bugs you get due to overlooking something.

I agree with Jim's comments.  I've generally followed column ordering
that goes something like:

1) primary key
2) foreign keys
3) flags
4) other programmatic data fields (type, order, etc.)
5) non-programmatic data fields (name, description, etc.)

The immediate practical benefit of this is that users are more likely to
see fields that they need without scrolling right.  Documentation is
also clearer because fields tend to go from most to least important
(left to right, top to bottom).  Also, if you are consistent enough then
users just *know* where to look.

I wrote a function a while back that reorders columns in tables (it not
only deals with reordering, but triggers, constraints, indexes, etc.,
though there are some caveats).  It's painful and not very efficient,
but easy to use.

Most dimension tables that I've worked with are in the millions of rows
so reordering is not problem.  With fact tables, I assess on a
case-by-case basis. It would be nice to not have to do that triage.

The function is attached if anyone is interested.

--
- David Steele
david@pgmasters.net

Attachment

pgsql-hackers by date:

Previous
From: Andres Freund
Date:
Subject: Re: MemoryContext reset/delete callbacks
Next
From: Josh Berkus
Date:
Subject: Re: GSoC idea - Simulated annealing to search for query plans