Re: most efficient way to manage ordering

From: Rod Taylor <pg(at)rbt(dot)ca>
To: Matthew Nuzum <cobalt(at)bearfruit(dot)org>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: most efficient way to manage ordering
Date: 2004-06-02 03:10:55
Message-ID: 1086145854.85942.77.camel@jester
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

> Ideally, I'd like to figure out a single SQL query that can be run
> afterwards to clean up the dsply_order to make sure that each number occurs
> only one time and that there are no gaps.

Well... by far the easiest way to approach this is not to clean up the
gaps. Removing gaps will only make things pretty, not easier or faster.

This is one of the many times it is best to differentiate between what
is displayed and what is used for functional purposes.

CREATE TEMPORARY SEQUENCE images_display_count;
SELECT nextval('images_display_count') AS display_order
, *
FROM images
WHERE galleryid = 1
ORDER BY real_order;
DROP SEQUENCE images_display_count;

There are ways of replacing the sequence that may be faster, but this
will address your concern. Do your updates, etc. via real_order and show
the user display_order.

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Rajesh Kumar Mallah 2004-06-02 08:50:04 Re: Query becoming slower on adding a primary key
Previous Message Matthew Nuzum 2004-06-02 02:35:52 most efficient way to manage ordering