Unix Technical Forum

Re: Order by behaviour

This is a discussion on Re: Order by behaviour within the Pgsql Performance forums, part of the PostgreSQL category; --> >If you can't force PostgreSQL to perform better on the ordered query, >what about retrieving only the primary keys ...


Go Back   Unix Technical Forum > Database Server Software > PostgreSQL > Pgsql Performance

Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 04-19-2008, 06:52 AM
Carlos Benkendorf
 
Posts: n/a
Default Re: Order by behaviour

>If you can't force PostgreSQL to perform better on the ordered query,
>what about retrieving only the primary keys for the rows you want
>unordered in a subquery and using an "where primaryKey in (...) order
>by ..." statement with ordering the five rows?


I appreciate your suggestion but I think I´m misunderstanding something, the select statement should return at about 150.000 rows, why 5 rows?

Guido Neitzer <guido.neitzer@pharmaline.de> escreveu:
On 23.12.2005, at 13:34 Uhr, Carlos Benkendorf wrote:

> For some implementation reason in 8.0.3 the query is returning the
> rows in the correct order even without the order by but in 8.1.1
> probably the implementation changed and the rows are not returning
> in the correct order.


You will never be sure to get rows in a specific order without an
"order by".

I don't know why PG is faster without ordering, perhaps others can
help with that so you don't need a workaround like this:

If you can't force PostgreSQL to perform better on the ordered query,
what about retrieving only the primary keys for the rows you want
unordered in a subquery and using an "where primaryKey in (...) order
by ..." statement with ordering the five rows?



Like this:

select * from mytable where pk in (select pk from mytable where ...)
order by ...;

I don't know whether the query optimizer will flatten this query, but
you can try it.

cug


--
PharmaLine Essen, GERMANY and
Big Nerd Ranch Europe - PostgreSQL Training, Feb. 2006, Rome, Italy
http://www.bignerdranch.com/classes/postgresql.shtml







---------------------------------
Yahoo! doce lar. Faça do Yahoo! sua homepage.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 10:18 PM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com