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 3275452DCC for ; Sun, 14 Aug 2005 21:27:55 -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 13076-04 for ; Mon, 15 Aug 2005 00:27:52 +0000 (GMT) Received: from sccmmhc92.asp.att.net (sccmmhc92.asp.att.net [204.127.203.212]) by svr1.postgresql.org (Postfix) with ESMTP id A700552DC4 for ; Sun, 14 Aug 2005 21:27:50 -0300 (ADT) Received: from juju.arbash-meinel.com ([12.214.18.81]) by sccmmhc92.asp.att.net (sccmmhc92) with ESMTP id <20050815002743m92009jakke>; Mon, 15 Aug 2005 00:27:53 +0000 Received: by juju.arbash-meinel.com (Postfix, from userid 505) id F3CF455FBA; Sun, 14 Aug 2005 19:27:42 -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 2F1F455FAD; Sun, 14 Aug 2005 19:27:39 -0500 (CDT) Message-ID: <42FFE17A.6010208@arbash-meinel.com> Date: Sun, 14 Aug 2005 19:27:38 -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: =?ISO-8859-1?Q?St=E9phane_COEZ?= Cc: pgsql-performance@postgresql.org Subject: Re: Performance pb vs SQLServer. References: <20050811131911.3175A1C0031B@mwinf0401.wanadoo.fr> In-Reply-To: <20050811131911.3175A1C0031B@mwinf0401.wanadoo.fr> X-Enigmail-Version: 0.92.0.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="------------enigD250D4B21DC4E3093825C750" 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/147 X-Sequence-Number: 13894 This is an OpenPGP/MIME signed message (RFC 2440 and 3156) --------------enigD250D4B21DC4E3093825C750 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable St=E9phane COEZ wrote: >Hi, > >I have a perfomance issue : > >I run PG (8.0.3) and SQLServer2000 on a Windows2000 Server (P4 1,5Ghz 51= 2Mo) >I have a table (3200000 rows) and I run this single query : > >select cod from mytable group by cod >I have an index on cod (char(4) - 88 different values) > >PG =3D ~ 20 sec. >SQLServer =3D < 8 sec > > >the explain is : > >HashAggregate (cost=3D64410.09..64410.09 rows=3D55 width=3D8) > -> Seq Scan on mytable (cost=3D0.00..56325.27 rows=3D3233927 width=3D= 8) > > >if I switch to "enable_hashagg =3D false" (just for a try...) >the planner will choose my index : > >Group (cost=3D0.00..76514.01 rows=3D55 width=3D8) > -> Index Scan using myindex on mytable (cost=3D0.00..68429.20 rows=3D= 3233927 >width=3D8) > >but performance will be comparable to previous test. > >So with or without using Index I have the same result. > =20 > 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. What you generally can do for performance, is to restructure things, so that you *don't* have to touch all 3.2M rows. If you are just trying to determine what the unique entries are for cod, you probably are better off doing some normalization, and keeping a separate table of cod values. I'm guessing the reason your query is faster with SQLServer is because of how postgres handles MVCC. Basically, it still has to fetch the main page to determine if a row exists. While SQL server doesn't do MVCC, so it can just look things up in the index. You might also try a different query, something like: SELECT DISTINCT cod FROM mytable ORDER BY cod GROUP BY cod; (You may or may not want order by, or group by, try the different combinations.) It might be possible to have the planner realize that all you want is unique rows, just doing a group by doesn't give you that. John =3D:-> > >Thanks for help. >=20 >St=E9phane COEZ > > > > >---------------------------(end of broadcast)---------------------------= >TIP 9: In versions below 8.0, the planner will ignore your desire to > choose an index scan if your joining column's datatypes do not > match > > =20 > --------------enigD250D4B21DC4E3093825C750 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/+F6JdeBCYSNAAMRAjKFAJ9N79+cvK394sIPq4gIvwfFu8x2XgCaAwnm QJu7OTqD6J+QWxIeIEj0jvk= =I7DZ -----END PGP SIGNATURE----- --------------enigD250D4B21DC4E3093825C750--