X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.193]) by svr1.postgresql.org (Postfix) with ESMTP id 6F14630EBD5 for ; Sun, 15 Jun 2003 16:48:47 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (svr1.postgresql.org [64.117.224.193]) (amavisd-new, port 10024) with ESMTP id 44336-09 for ; Sun, 15 Jun 2003 13:48:35 -0300 (ADT) Received: from mta02-svc.ntlworld.com (mta02-svc.ntlworld.com [62.253.162.42]) by svr1.postgresql.org (Postfix) with ESMTP id DD8C530EB6B for ; Sun, 15 Jun 2003 13:48:34 -0300 (ADT) Received: from Wilbur ([81.96.74.182]) by mta02-svc.ntlworld.com (InterMail vM.4.01.03.37 201-229-121-137-20020806) with SMTP id <20030615164833.FOFX15180.mta02-svc.ntlworld.com@Wilbur>; Sun, 15 Jun 2003 17:48:33 +0100 Message-ID: <039401c3335d$f94d1760$0600a8c0@Wilbur> From: "Julian Scarfe" To: "Tom Lane" Cc: References: <036301c33350$a4bd5e60$0600a8c0@Wilbur> <13056.1055692197@sss.pgh.pa.us> Subject: Re: Ordering in an aggregate -- points to paths Date: Sun, 15 Jun 2003 17:48:40 +0100 MIME-Version: 1.0 Content-Type: text/plain; charset="Windows-1252" Content-Transfer-Encoding: 7bit X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 6.00.2800.1158 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165 X-Archive-Number: 200306/155 X-Sequence-Number: 13913 From: "Tom Lane" > Yeah, this is a fairly obvious thing to want to do with a user-written > aggregate. It does not work in released versions, because the planner > does not notice that the inner SELECT's output ordering matches what > the GROUP BY needs, and so it inserts an additional Sort plan step > above the sub-select (you can see this if you look at EXPLAIN output). > Unfortunately, on most platforms qsort() isn't stable and will not > preserve the ordering of its input for equal keys. So you lose the > minor ordering by seq_no in the re-sort. Most grateful for the rapid response Tom. Knowing that, I can work around by iterating through the firs at the application level. Regards Julian Scarfe PS: you shouldn't be working on a Sunday, it's bad for you ;-)