X-Original-To: pgsql-admin@postgresql.org Received: from localhost (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id 775404758E6 for ; Fri, 7 Feb 2003 05:05:50 -0500 (EST) Received: from gsy_sbs_1.cisx.com (unknown [213.133.202.58]) by postgresql.org (Postfix) with ESMTP id 8A5654758C9 for ; Fri, 7 Feb 2003 05:05:39 -0500 (EST) Received: from DEMOLITION ([192.168.100.22]) by gsy_sbs_1.cisx.com with SMTP (Microsoft Exchange Internet Mail Service Version 5.5.2650.21) id 13LVZ522; Fri, 7 Feb 2003 09:58:50 -0000 Message-ID: <008201c2ce91$0e627af0$1664a8c0@DEMOLITION> From: "Donald Fraser" To: References: Subject: Re: Indexes on Large Tables Date: Fri, 7 Feb 2003 10:09:47 -0000 MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 5.50.4522.1200 X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4522.1200 X-Virus-Scanned: by AMaViS new-20020517 X-Archive-Number: 200302/112 X-Sequence-Number: 7310 ----- Original Message ----- From: "Curt Sampson" To: "Donny Drummonds" Cc: Sent: Friday, February 07, 2003 5:13 AM Subject: Re: [ADMIN] Indexes on Large Tables > On Mon, 3 Feb 2003, Donny Drummonds wrote: > > > If I do not index the column from the where clause the query returns > > the 150,000 rows in 4 and a half minutes. If in do index the column > > from the where clause using a btree the 150,000 rows return in 11 and > > a half minutes. > > > > Any insight would be greatly appreciated. > > Well, I'm not sure if this is the insight you're looking for, but.... > > The reason it takes longer if you use an index is that you change > from sequential I/O (which is relatively fast) to random I/O (which > is relatively slow). With the table scan (reading the entire table in > whatever order it's in on the disk) you're reading several times as much > data, but you're not doing head seeks all over the place to move the > head to the place where the next bit of data to be read is. > > Obviously, in this case, even though an index was available, the planner > was wrong to chose to use it rather than just read the entire table. > That is, as someone else mentioned, likely due to bad statistics: the > planner thought you were going to select a very small part of the table, > rather than ten percent of it (which is a pretty large fraction, for > these purposes). Try doing an ANALYZE. > > cjs If the index that you use in the WHERE clause is the most common method that you are accessing the table then I recommend that you periodically run the cluster command: CLUSTER indexname ON tablename When a table is clustered, it is physically reordered on disk based on the index information. Donald