Received: from localhost (unknown [200.46.204.184]) by postgresql.org (Postfix) with ESMTP id 464B12E2DF3 for ; Fri, 16 Nov 2007 15:34:44 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.184]) (amavisd-maia, port 10024) with ESMTP id 12624-03 for ; Fri, 16 Nov 2007 15:34:28 -0400 (AST) Received: from serv01.siteground137.com (ns1.siteground137.com [67.15.250.10]) by postgresql.org (Postfix) with ESMTP id 5E20B2E2DD6 for ; Fri, 16 Nov 2007 15:34:40 -0400 (AST) Received: from cragnux.laika.com ([209.162.219.253]:60840 helo=dogma.ljc.laika.com) by serv01.siteground137.com with esmtpa (Exim 4.68) (envelope-from ) id 1It6xY-0005e7-LA; Fri, 16 Nov 2007 13:34:36 -0600 Subject: Re: Clustered/covering indexes (or lack thereof :-) From: Jeff Davis To: adrobj Cc: pgsql-performance@postgresql.org In-Reply-To: <13700848.post@talk.nabble.com> References: <13700848.post@talk.nabble.com> Content-Type: text/plain Date: Fri, 16 Nov 2007 11:34:36 -0800 Message-Id: <1195241676.22428.218.camel@dogma.ljc.laika.com> Mime-Version: 1.0 X-Mailer: Evolution 2.0.4 (2.0.4-7) Content-Transfer-Encoding: 7bit X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - serv01.siteground137.com X-AntiAbuse: Original Domain - postgresql.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - j-davis.com X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200711/248 X-Sequence-Number: 27663 On Sun, 2007-11-11 at 22:59 -0800, adrobj wrote: > This is probably a FAQ, but I can't find a good answer... > > So - are there common techniques to compensate for the lack of > clustered/covering indexes in PostgreSQL? To be more specific - here is my > table (simplified): > > topic_id int > post_id int > post_text varchar(1024) > > The most used query is: SELECT post_id, post_text FROM Posts WHERE > topic_id=XXX. Normally I would have created a clustered index on topic_id, > and the whole query would take ~1 disk seek. > > What would be the common way to handle this in PostgreSQL, provided that I > can't afford 1 disk seek per record returned? > Periodically CLUSTER the table on the topic_id index. The table will not be perfectly clustered at all times, but it will be close enough that it won't make much difference. There's still the hit of performing a CLUSTER, however. Another option, if you have a relatively small number of topic_ids, is to break it into separate tables, one for each topic_id. Regards, Jeff Davis