X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.2]) by svr1.postgresql.org (Postfix) with ESMTP id A89D0D1EC43 for ; Tue, 23 Mar 2004 14:54:01 +0000 (GMT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (neptune.hub.org [200.46.204.2]) (amavisd-new, port 10024) with ESMTP id 93105-08 for ; Tue, 23 Mar 2004 10:54:03 -0400 (AST) Received: from sss.pgh.pa.us (unknown [192.204.191.242]) by svr1.postgresql.org (Postfix) with ESMTP id 25275D1EC1A for ; Tue, 23 Mar 2004 10:53:59 -0400 (AST) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.12.11/8.12.11) with ESMTP id i2NEs2Kl020190; Tue, 23 Mar 2004 09:54:02 -0500 (EST) To: "David Witham" Cc: pgsql-sql@postgresql.org Subject: Re: Sorting an aggregated column In-reply-to: References: Comments: In-reply-to "David Witham" message dated "Tue, 23 Mar 2004 18:17:51 +1100" Date: Tue, 23 Mar 2004 09:54:02 -0500 Message-ID: <20189.1080053642@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200403/234 X-Sequence-Number: 17333 "David Witham" writes: > So I see that there is the extra sort above the sub-query that > wouldn't be there using 7.4. Are you saying that the sort by survey > after the sort by survey,question would potentially reorder the > records initially sorted by survey,question? Exactly. Most implementations of qsort() aren't "stable", which means they might reorder equal keys in some random way. So to preserve the sub-ordering on question, you need the upper sort to be skipped. The 7.4 planner is smart enough to notice it doesn't need the upper sort, prior releases were not. regards, tom lane