Re: Sorting on longer key is faster ?

From: John A Meinel <john(at)arbash-meinel(dot)com>
To: Chris Travers <chris(at)metatrontech(dot)com>, Postgresql Performance <pgsql-performance(at)postgresql(dot)org>
Subject: Re: Sorting on longer key is faster ?
Date: 2005-07-12 01:48:44
Message-ID: 42D3217C.20703@arbash-meinel.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-performance

Chris Travers wrote:
> John A Meinel wrote:
>
>> jobapply wrote:
>>
>>
>>> The 2 queries are almost same, but ORDER BY x||t is FASTER than ORDER
>>> BY x..
>>>
>>> How can that be possible?
>>>
>>> Btw: x and x||t are same ordered
>>>
>>> phoeniks=> explain analyze SELECT * FROM test WHERE i<20 ORDER BY x
>>> || t;
>>> QUERY PLAN
>>>
>>>
>>
>>
>> What types are x and t, I have the feeling "x || t" is actually a
>> boolean, so it is only a True/False sort, while ORDER BY x has to do
>> some sort of string comparison (which might actually be a locale
>> depended comparison, and strcoll can be very slow on some locales)
>>
>>
>>
> Am I reading this that wrong? I would think that x || t would mean
> "concatenate x and t."

Sorry, I think you are right. I was getting my operators mixed up.
>
> This is interesting. I never through of writing a multicolumn sort this
> way....

I'm also surprised that the sort is faster with a merge operation. Are
you using UNICODE as the database format? I'm just wondering if it is
doing something funny like casting it to an easier to sort type.

>
> Best Wishes,
> Chris Travers
> Metatron Technology Consulting

PS> Don't forget to Reply All so that your messages go back to the list.

In response to

Browse pgsql-performance by date

  From Date Subject
Next Message John A Meinel 2005-07-12 01:52:25 Re: Sorting on longer key is faster ?
Previous Message Tom Lane 2005-07-11 23:47:50 Re: Sorting on longer key is faster ?