X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 204E7D82C7 for ; Wed, 12 Oct 2005 22:50:49 -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 73812-01 for ; Thu, 13 Oct 2005 01:50:45 +0000 (GMT) Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by svr1.postgresql.org (Postfix) with ESMTP id 3D8C7D82B3 for ; Wed, 12 Oct 2005 22:50:47 -0300 (ADT) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.13.1/8.13.1) with ESMTP id j9D1okDp016345; Wed, 12 Oct 2005 21:50:46 -0400 (EDT) To: Greg Stark Cc: Scott Marlowe , Stephan Szabo , Rick Schumeyer , pgsql-sql@postgresql.org Subject: Re: pg, mysql comparison with "group by" clause In-reply-to: <87zmpez0au.fsf@stark.xeocode.com> References: <001001c5cea8$77cabc90$0300a8c0@dell8200> <20051011142658.C54076@megazone.bigpanda.com> <87br1u1jvq.fsf@stark.xeocode.com> <1129155875.29961.168.camel@state.g2switchworks.com> <87zmpez0au.fsf@stark.xeocode.com> Comments: In-reply-to Greg Stark message dated "12 Oct 2005 21:13:29 -0400" Date: Wed, 12 Oct 2005 21:50:46 -0400 Message-ID: <16344.1129168246@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.006 required=5 tests=[AWL=0.006] X-Spam-Level: X-Archive-Number: 200510/119 X-Sequence-Number: 22972 Greg Stark writes: > I think most MySQL users don't stumble on it, they learn it as the way > to handle the common use case when you join a master table against a > detail table and then want to aggregate all the detail records. In > standard SQL you have to write GROUP BY ... and list every single > column you need from the master table. Forcing the database to do a > lot of redundant comparisons and sort on uselessly long keys where in > fact you only really need it to sort and group by the primary key. Actually, if you're grouping by a table's primary key, the SQL99 spec says you shouldn't have to explicitly list the other columns from that table --- they are guaranteed to have unique values per group anyway. This is a single case in the "functional dependency" stuff. That verbiage is incredibly dense and I don't think we want to tackle all of it any time soon, but the primary-key case probably wouldn't be very hard to implement. We really ought to have this in TODO ... I'm sure it's been discussed before. regards, tom lane