Re: How do I bump a row to the front of sort efficiently

From: hubert depesz lubaczewski <depesz(at)depesz(dot)com>
To: Sam Saffron <sam(dot)saffron(at)gmail(dot)com>
Cc: PGSQL Mailing List <pgsql-general(at)postgresql(dot)org>
Subject: Re: How do I bump a row to the front of sort efficiently
Date: 2015-02-02 08:40:56
Message-ID: 20150202084055.GB29293@depesz.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general pgsql-hackers

On Mon, Feb 02, 2015 at 05:16:40PM +1100, Sam Saffron wrote:
> Even this is fast, and logically equiv as id is primary key unique
> select * from topic
> where id = 1000
> union all
> select * from (
> select * from topics
> where id <> 1000
> order by bumped_at desc
> limit 30
> ) as x
> limit 30
> Is there any clean technique to bump up particular rows to the front
> of a sort if a certain condition is met without paying a huge
> performance hit?

Why don't you use the union-all approach? If it's fast, and does what
you need ?

depesz

--
The best thing about modern society is how easy it is to avoid contact with it.
http://depesz.com/

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Andreas 2015-02-02 09:44:10 Can I habe multi table indices?
Previous Message David G Johnston 2015-02-02 06:29:29 Re: How do I bump a row to the front of sort efficiently

Browse pgsql-hackers by date

  From Date Subject
Next Message Tim Clarke 2015-02-02 09:56:54 Re: How do I bump a row to the front of sort efficiently
Previous Message Kyotaro HORIGUCHI 2015-02-02 07:27:55 Re: [POC] FETCH limited by bytes.