Received: from sss.pgh.pa.us (sss.pgh.pa.us [209.114.132.154]) by mail.postgresql.org (8.11.1/8.11.1) with ESMTP id f1M4SMx69502 for ; Wed, 21 Feb 2001 23:28:22 -0500 (EST) (envelope-from tgl@sss.pgh.pa.us) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.11.1/8.11.1) with ESMTP id f1M4S7913809; Wed, 21 Feb 2001 23:28:08 -0500 (EST) To: Jeremy Buchmann cc: pgsql-admin Subject: Re: Using the correct index In-reply-to: References: Comments: In-reply-to Jeremy Buchmann message dated "Wed, 21 Feb 2001 16:05:52 -0800" Date: Wed, 21 Feb 2001 23:28:07 -0500 Message-ID: <13806.982816087@sss.pgh.pa.us> From: Tom Lane X-Archive-Number: 200102/160 X-Sequence-Number: 762 Jeremy Buchmann writes: > I have a table I'll call SomeTable that has columns called id, date, and > name along with a few others. I created two indexes for this table, one was > on id (called SomeTable_id) and the other was on id and date (called > SomeTable_id_date). When I do: > EXPLAIN SELECT * FROM SomeTable WHERE id = '0101' > it tells me: > Index Scan using SomeTable_id_date on Sometable ... > Even when I do: > EXPLAIN SELECT id FROM SomeTable WHERE id = '0101' > it still says it's using the SomeTable_id_date index. Why is it using the > multicolumn index when the date column isn't involved? If the indexes are small then the cost estimates for scanning them will be the same, and it's a random matter which one gets picked (in fact, I suspect 7.0 may deliberately prefer the "more sorted" one). Once the indexes get larger --- more than 100 pages or so --- the system will notice that scanning the double-column index is more expensive, and will avoid using it unless there's good reason. regards, tom lane