Re: Sorting on longer key is faster ? - Mailing list pgsql-performance

From John A Meinel
Subject Re: Sorting on longer key is faster ?
Date
Msg-id 42D32259.2000705@arbash-meinel.com
Whole thread Raw
In response to Sorting on longer key is faster ?  ("jobapply" <jobapply@nextmail.ru>)
List 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
=:->


Attachment

pgsql-performance by date:

Previous
From: John A Meinel
Date:
Subject: Re: Sorting on longer key is faster ?
Next
From: Simon Riggs
Date:
Subject: Re: cost-based vacuum