From: | Tim Clarke <tim(dot)clarke(at)manifest(dot)co(dot)uk> |
---|---|
To: | pgsql-general(at)postgresql(dot)org |
Subject: | Re: How do I bump a row to the front of sort efficiently |
Date: | 2015-02-02 09:56:54 |
Message-ID: | 54CF49E6.6030908@manifest.co.uk |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general pgsql-hackers |
On 02/02/15 08:40, hubert depesz lubaczewski wrote:
> 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
>
Or create another index or column that's build at insertion time with
the sort that you want in it. At least then retrieval time will be fast
at the cost of extra space.
--
Tim Clarke
A: Because we read from top to bottom, left to right.
Q: Why should I start my reply below the quoted text?
From | Date | Subject | |
---|---|---|---|
Next Message | Albe Laurenz | 2015-02-02 09:58:31 | Re: Can I habe multi table indices? |
Previous Message | William Gordon Rutherdale | 2015-02-02 09:46:46 | Re: Problem with REFERENCES on INHERITS |
From | Date | Subject | |
---|---|---|---|
Next Message | Pavel Stehule | 2015-02-02 10:15:22 | Implementation of global temporary tables? |
Previous Message | hubert depesz lubaczewski | 2015-02-02 08:40:56 | Re: How do I bump a row to the front of sort efficiently |