X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id B730F11F606B for ; Wed, 12 Apr 2006 09:59:23 -0300 (ADT) X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Score: 0.12 X-Spam-Level: X-Spam-Status: No, score=0.12 required=5 tests=[AWL=0.120] Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id eVKj5-ytTDbq for ; Wed, 12 Apr 2006 09:59:16 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey- Received: from mail.logix-tt.com (unknown [212.211.145.186]) by postgresql.org (Postfix) with ESMTP id 95E6E11F6004 for ; Wed, 12 Apr 2006 09:59:19 -0300 (ADT) Received: from kingfisher.intern.logix-tt.com (T9c8e.t.pppool.de [89.55.156.142]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.logix-tt.com (Postfix) with ESMTP id 8EA67656C1; Wed, 12 Apr 2006 15:00:12 +0200 (CEST) Received: from [127.0.0.1] (localhost [127.0.0.1]) by kingfisher.intern.logix-tt.com (Postfix) with ESMTP id C4134181C1E89; Wed, 12 Apr 2006 14:59:32 +0200 (CEST) Message-ID: <443CF9B4.2080009@logix-tt.com> Date: Wed, 12 Apr 2006 14:59:32 +0200 From: Markus Schaber Organization: Logical Tracking and Tracing International AG, Switzerland User-Agent: Debian Thunderbird 1.0.7 (X11/20051017) X-Accept-Language: en-us, en MIME-Version: 1.0 To: Oscar Picasso Cc: pgsql-performance@postgresql.org Subject: Re: Better index stategy for many fields with few values References: <20060410165857.91471.qmail@web54705.mail.yahoo.com> In-Reply-To: <20060410165857.91471.qmail@web54705.mail.yahoo.com> X-Enigmail-Version: 0.93.0.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Archive-Number: 200604/259 X-Sequence-Number: 18343 Hi, Oscar, Oscar Picasso wrote: > [ all the 20 paramXX columns are used in the query} > How can I optimize this kind of query? PostgreSQL 8.1 has so-called bitmap index scans, which can combine several index scans before actually accessing the data. So I think it's best to create an index on each of the paramXX columns, and see with EXPLAIN ANALYZE what it is doing. > I was thinking about using a multicolumns index, but I have read that > we should limit multicolumns indice to at most 2 or 3 columns. Yes, that's true, the index overhead gets too high. > If that's true then 22 columns for a multicolumn incdex seems way too > much. Or maybe it is workable as every column uses only a very limited > set of values? Yes, I think that a 22 column index is way too much, especially with the new bitmap index scans available. > I was also thinking about about using a functional index. If there's a logical relation between those values that they can easily combined, that may be a good alternative. I just had another weird idea: As your paramXX values can have only 10 parameters, it also might be feasible to use a bunch of 10 conditional indices, like: CREATE INDEX foo1 ON table (param1, param2 WHERE param0='1st value'; CREATE INDEX foo2 ON table (param1, param2 WHERE param0='2nd value'; CREATE INDEX foo3 ON table (param1, param2 WHERE param0='3rd value'; [...] This way, you don't have the index bloat of a 3-column index, but 10 2-column indices that cover 1/10th of the table each. For 22 columns, you'd need a bunch of seven such indices plus a single-column one, or can use some 3+1 and some 2+1 column index. I'd like to see the query plans from explain analyze. Btw, I expect query planning time to get rather significant for so much columns, so gequo tuning, tuning work_mem (for the bitmap scans) and prepared statements will pay off. HTH, Markus -- Markus Schaber | Logical Tracking&Tracing International AG Dipl. Inf. | Software Development GIS Fight against software patents in EU! www.ffii.org www.nosoftwarepatents.org