pg.ddx.io  pgsql-performance@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Kevin Grittner <Kevin.Grittner@wicourts.gov>
Cc: Marcin Miros*aw <marcin@mejor.pl>
Cc: pgsql-performance@postgresql.org
Subject: Re: [planner] Ignore "order by" in subselect if parrent do count(*)
Date: Thu, 01 Mar 2012 12:50:02 -0500
Message-ID: <14667.1330624202@sss.pgh.pa.us> (raw)
In-Reply-To: <4F4F54910200002500045D59@gw.wicourts.gov>
References: <4F4F6158.7060200@mejor.pl>
	<4F4F54910200002500045D59@gw.wicourts.gov>

"Kevin Grittner" <Kevin.Grittner@wicourts.gov> writes:
> Marcin Miros*aw<marcin@mejor.pl> wrote:
>> SELECT count(*)
>> from (select * from users_profile order by id) u_p;
 
>> "order by id" can be ignored by planner.
 
> This has been discussed before.  Certainly not all ORDER BY clauses
> within query steps can be ignored, so there would need to be code to
> determine whether it was actually useful, which wouldn't be free,
> either in terms of planning time or code maintenance.  It wasn't
> judged to be worth the cost.  If you want to avoid the cost of the
> sort, don't specify ORDER BY where it doesn't matter.

Considering that ORDER BY in a subquery isn't even legal per spec,
there does not seem to be any tenable argument for supposing that
a user wrote it there "by accident".  It's much more likely that
he had some semantic reason for it (say, an order-sensitive function
in a higher query level) and that we'd break his results by ignoring
the ORDER BY.  I doubt that very many of the possible reasons for
needing ordered output are reliably detectable by the planner, either.

			regards, tom lane



view thread (9+ messages)  latest in thread

Message-ID: <14667.1330624202@sss.pgh.pa.us>
Permalink:  ../14667.1330624202@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/14667.1330624202@sss.pgh.pa.us

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-performance@postgresql.org
  Cc: tgl@sss.pgh.pa.us, Kevin.Grittner@wicourts.gov, marcin@mejor.pl
  Subject: Re: [planner] Ignore "order by" in subselect if parrent do count(*)
  In-Reply-To: <14667.1330624202@sss.pgh.pa.us>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox