Re: Sorting on longer key is faster ?

From: John A Meinel <john(at)arbash-meinel(dot)com>
To: jobapply <jobapply(at)nextmail(dot)ru>
Cc: pgsql-performance(at)postgresql(dot)org
Subject: Re: Sorting on longer key is faster ?
Date: 2005-07-12 01:52:25
Message-ID: 42D32259.2000705@arbash-meinel.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-performance

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

I also thought of another possibility. Are there a lot of similar
entries in X? Meaning that the same value is repeated over and over? It
is possible that the sort code has a weakness when sorting equal values.

For instance, if it was doing a Hash aggregation, you would have the
same hash repeated. (It isn't I'm just mentioning a case where it might
affect something).

If it is creating a tree representation, it might cause some sort of
pathological worst-case behavior, where all entries keep adding to the
same side of the tree, rather than being more balanced.

I don't know the internals of postgresql sorting, but just some ideas.

John
=:->

In response to

Browse pgsql-performance by date

  From Date Subject
Next Message Brent Henry 2005-07-12 06:22:47 General DB Tuning
Previous Message John A Meinel 2005-07-12 01:48:44 Re: Sorting on longer key is faster ?