Received: from localhost (maia-1.hub.org [200.46.204.191]) by postgresql.org (Postfix) with ESMTP id 32A8E9FBD3B for ; Fri, 18 May 2007 18:36:47 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.191]) (amavisd-maia, port 10024) with ESMTP id 24340-09 for ; Fri, 18 May 2007 18:36:43 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.5 Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by postgresql.org (Postfix) with ESMTP id AB7B69FC1C1 for ; Fri, 18 May 2007 18:36:43 -0300 (ADT) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.1/8.14.1) with ESMTP id l4ILaeNE003127; Fri, 18 May 2007 17:36:40 -0400 (EDT) To: "Tyrrill, Ed" cc: "Scott Marlowe" , pgsql-performance@postgresql.org Subject: Re: Slow queries on big table In-reply-to: References: <464E0036.3030804@g2switchworks.com> <1825.1179518769@sss.pgh.pa.us> Comments: In-reply-to "Tyrrill, Ed" message dated "Fri, 18 May 2007 14:22:52 -0700" Date: Fri, 18 May 2007 17:36:40 -0400 Message-ID: <3126.1179524200@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200705/349 X-Sequence-Number: 24739 "Tyrrill, Ed" writes: > Tom Lane writes: >> This combination of indexes: >> >>> Indexes: >>> "backup_location_pkey" PRIMARY KEY, btree (record_id, backup_id) >>> "backup_location_rid" btree (record_id) >> >> is really just silly. You should have the pkey and then an index on >> backup_id alone. > Thanks for the help guys! That was my problem. I actually need the > backup_location_rid index for a different query so I am going to keep > it. Well, you don't really *need* it; the two-column index on (record_id, backup_id) will serve perfectly well for queries on its leading column alone. It'll be physically bigger and hence slightly slower to scan than a single-column index; but unless the table is almost completely read-only, the update overhead of maintaining all three indexes is probably going to cost more than you can save with it. Try that other query with and without backup_location_rid and see how much you're really saving. > Index Scan using backup_location_bid on backup_location > (cost=0.00..9573.07 rows=415897 width=8) (actual time=0.106..3.486 > rows=2752 loops=1) > Index Cond: (backup_id = 1070) > Total runtime: 4.951 ms That's more like it ;-) regards, tom lane