X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id D8CCA52EBF for ; Sun, 14 Aug 2005 22:06:03 -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 20648-06 for ; Mon, 15 Aug 2005 01:05:59 +0000 (GMT) Received: from sccmmhc91.asp.att.net (sccmmhc91.asp.att.net [204.127.203.211]) by svr1.postgresql.org (Postfix) with ESMTP id 4A01352ABA for ; Sun, 14 Aug 2005 22:05:58 -0300 (ADT) Received: from juju.arbash-meinel.com ([12.214.18.81]) by sccmmhc91.asp.att.net (sccmmhc91) with ESMTP id <20050815010602m9100g6bcte>; Mon, 15 Aug 2005 01:06:02 +0000 Received: by juju.arbash-meinel.com (Postfix, from userid 505) id 25A1155FBA; Sun, 14 Aug 2005 20:06:02 -0500 (CDT) Received: from [192.168.1.11] (liliana.arbash-meinel.com [192.168.1.11]) by juju.arbash-meinel.com (Postfix) with ESMTP id 07EFE55FAD; Sun, 14 Aug 2005 20:05:59 -0500 (CDT) Message-ID: <42FFEA76.6070109@arbash-meinel.com> Date: Sun, 14 Aug 2005 20:05:58 -0500 From: John Arbash Meinel User-Agent: Mozilla Thunderbird 1.0.6 (X11/20050727) X-Accept-Language: en-us, en MIME-Version: 1.0 To: "Steinar H. Gunderson" Cc: pgsql-performance@postgresql.org Subject: Re: Performance pb vs SQLServer. References: <20050811131911.3175A1C0031B@mwinf0401.wanadoo.fr> <42FFE17A.6010208@arbash-meinel.com> <20050815010159.GA27795@uio.no> In-Reply-To: <20050815010159.GA27795@uio.no> X-Enigmail-Version: 0.92.0.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="------------enig600AA473DF119A810C53F557" X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.043 required=5 tests=[AWL=-0.007, FORGED_RCVD_HELO=0.05] X-Spam-Level: X-Archive-Number: 200508/151 X-Sequence-Number: 13898 This is an OpenPGP/MIME signed message (RFC 2440 and 3156) --------------enig600AA473DF119A810C53F557 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Steinar H. Gunderson wrote: >On Sun, Aug 14, 2005 at 07:27:38PM -0500, John Arbash Meinel wrote: > > >>My guess is that this is part of a larger query. There isn't really much >>you can do. If you want all 3.2M rows, then you have to wait for them to >>be pulled in. >> >> > >To me, it looks like he'll get 88 rows, not 3.2M. Surely we must be able to >do something better than a full sequential scan in this case? > >test=# create table foo ( bar char(4) ); >CREATE TABLE >test=# insert into foo values ('0000'); >INSERT 24773320 1 >test=# insert into foo values ('0000'); >INSERT 24773321 1 >test=# insert into foo values ('1111'); >INSERT 24773322 1 >test=# select * from foo group by bar; > bar >------ > 1111 > 0000 >(2 rows) > >I considered doing some odd magic with generate_series() and subqueries with >LIMIT 1, but it was a bit too weird in the end :-) > >/* Steinar */ > > I think a plain "GROUP BY" is not smart enough to detect it doesn't need all rows (since it is generally used because you want to get aggregate values of other columns). I think you would want something like SELECT DISTINCT, possibly with an ORDER BY rather than a GROUP BY (which was my final suggestion). John =:-> --------------enig600AA473DF119A810C53F557 Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.5 (GNU/Linux) Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org iD8DBQFC/+p2JdeBCYSNAAMRAnhQAJ4oOR2RxZyaLi4yJsrSCHJObxtfewCfQZIV 6mg+ebmDTj6dK5q4doe4hj4= =6vR1 -----END PGP SIGNATURE----- --------------enig600AA473DF119A810C53F557--