X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id C88B35353F for ; Fri, 13 May 2005 03:05:58 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 71897-09 for ; Fri, 13 May 2005 06:05:49 +0000 (GMT) Received: from stark.xeocode.com (stark.xeocode.com [216.58.44.227]) by svr1.postgresql.org (Postfix) with ESMTP id D7449534A3 for ; Fri, 13 May 2005 03:05:48 -0300 (ADT) Received: from localhost ([127.0.0.1] helo=stark.xeocode.com) by stark.xeocode.com with smtp (Exim 3.36 #1 (Debian)) id 1DWTIn-00022d-00; Fri, 13 May 2005 02:05:37 -0400 To: nickf@doxpop.com Cc: Alvaro Herrera , pgsql-sql@postgresql.org Subject: Re: interesting SQL puzzle - concatenating column with itself. References: <427E60BC.8060701@ontko.com> <20050508212905.GA14422@dcc.uchile.cl> <428111F3.2090002@ontko.com> In-Reply-To: <428111F3.2090002@ontko.com> From: Greg Stark Organization: The Emacs Conspiracy; member since 1992 Date: 13 May 2005 02:05:37 -0400 Message-ID: <87zmuzmzim.fsf@stark.xeocode.com> Lines: 32 User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.3 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.005 tagged_above=0 required=5 tests=AWL X-Spam-Level: X-Archive-Number: 200505/97 X-Sequence-Number: 21410 Nick Fankhauser writes: > Alvaro Herrera wrote: > > > The order is not really guaranteed, though if this is a one-shot thing, > > you may get away with turning off hashed aggregates. > > > > When I read this, I assumed there was a runtime parameter I could set that was > similar to ENABLE_HASHJOIN. Are you referring to a different runtime parameter > or something else entirely? Similar but different. enable_hashagg. You can see all of these with "show all" in psql. However you do not have to worry. Even with (actually, *especially with*) hash aggregates the records will be processed in the order they're received. It's actually the normal aggregate method of sorting on the GROUP BY columns that risks damaging the order. However Postgres does a special check to see if the subquery is already sorted by the GROUP BY column and avoids the extra sort which could cause you problems. So this is not guaranteed by the SQL spec to work (but then the SQL spec doesn't have custom aggregates at all) but Postgres goes out of its way to make sure this doesn't break unnecessarily. [This is all for 8.0 and I think 7.4. Some versions before that might -- greg