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 E8818528B7 for ; Fri, 10 Jun 2005 15:01:12 -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 98787-09 for ; Fri, 10 Jun 2005 18:01:03 +0000 (GMT) Received: from server07.icaen.uiowa.edu (server07.icaen.uiowa.edu [128.255.17.47]) by svr1.postgresql.org (Postfix) with ESMTP id 98728528B1 for ; Fri, 10 Jun 2005 15:01:02 -0300 (ADT) Received: from server11.icaen.uiowa.edu (server11.icaen.uiowa.edu [128.255.17.51]) by server07.icaen.uiowa.edu (8.13.3/8.12.9) with ESMTP id j5AI10ot023276; (envelope-from ) Fri, 10 Jun 2005 13:01:01 -0500 (CDT) Received: from [192.168.1.11] ([12.215.118.172]) (authenticated user=jfmeinel) by server11.icaen.uiowa.edu (8.13.2/smtp-serv-1.7) with ESMTP id j5AI0x7I005269 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256); (envelope-from ) Fri, 10 Jun 2005 13:01:00 -0500 (CDT) Message-ID: <42A9D556.7070108@arbash-meinel.com> Date: Fri, 10 Jun 2005 13:00:54 -0500 From: John A Meinel User-Agent: Mozilla Thunderbird 1.0.2-1.3.3 (X11/20050513) X-Accept-Language: en-us, en MIME-Version: 1.0 To: Clark Slater Cc: pgsql-performance@postgresql.org Subject: Re: faster search References: <20050610132812.R94573@vbp2.vbp2.com> In-Reply-To: <20050610132812.R94573@vbp2.vbp2.com> X-Enigmail-Version: 0.91.0.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="------------enig9A20CF5F1BDB9BD858893E30" X-Virus-Scanned: ClamAV version 0.83, clamav-milter version 0.83 on clamav.icaen.uiowa.edu X-Virus-Scanned: ClamAV version 0.83, clamav-milter version 0.83 on clamav.icaen.uiowa.edu X-Virus-Status: Clean X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.004 tagged_above=0 required=5 tests=AWL X-Spam-Level: X-Archive-Number: 200506/245 X-Sequence-Number: 12882 This is an OpenPGP/MIME signed message (RFC 2440 and 3156) --------------enig9A20CF5F1BDB9BD858893E30 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Clark Slater wrote: > Hi- > > Would someone please enlighten me as > to why I'm not seeing a faster execution > time on the simple scenario below? > > there are 412,485 rows in the table and the > query matches on 132,528 rows, taking > almost a minute to execute. vaccuum > analyze was just run. Well, if you are matching 130k out of 400k rows, then a sequential scan is certainly prefered to an index scan. And then you have to sort those 130k rows by partnumber. This *might* be spilling to disk depending on what your workmem/sortmem is set to. I would also say that what you would really want is some way to get the whole thing from an index. And I think the way to do that is: CREATE INDEX test_partnum_listid_typeid_idx ON test(partnumber, productlistid, typeid); VACUUM ANALYZE test; EXPLAIN ANALYZE SELECT * FROM test WHERE productlistid=3 AND typeid=9 ORDER BY partnumber, productlistid, typeid LIMIT 15 ; The trick is that you have to match the order by exactly with the index, so the planner realizes it can do an indexed lookup to get the information. You could also just create an index on partnumber, and see how that affects your original query. I think the planner could use an index lookup on partnumber to get the ordering correct. But it will have to do filtering after the fact based on productlistid and typeid. With my extended index, I think the planner can be smarter and lookup all 3 by the index. > > Thanks! > Clark Good luck, John =:-> --------------enig9A20CF5F1BDB9BD858893E30 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.4.1 (GNU/Linux) Comment: Using GnuPG with Fedora - http://enigmail.mozdev.org iD8DBQFCqdVZJdeBCYSNAAMRAi3iAJ99hAuDUUDttUAvzpO7+b96NyEZAACfRUOx Z+BUvbxWcVRAWDcrABX48so= =jQ1Z -----END PGP SIGNATURE----- --------------enig9A20CF5F1BDB9BD858893E30--