Received: from maia.hub.org (maia-2.hub.org [200.46.204.251]) by mail.postgresql.org (Postfix) with ESMTP id 2F54E63219F for ; Tue, 17 Aug 2010 12:08:01 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.251]) (amavisd-maia, port 10024) with ESMTP id 67133-05 for ; Tue, 17 Aug 2010 15:07:51 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from spinlock.commandprompt.com (host-215.commandprompt.net [207.173.203.215]) by mail.postgresql.org (Postfix) with ESMTP id E69016327F0 for ; Tue, 17 Aug 2010 12:07:50 -0300 (ADT) Received: from localhost (localhost [127.0.0.1]) by spinlock.commandprompt.com (Postfix) with ESMTP id 9829134803E; Tue, 17 Aug 2010 08:07:44 -0700 (PDT) X-Virus-Scanned: Debian amavisd-new at commandprompt.com Received: from spinlock.commandprompt.com ([127.0.0.1]) by localhost (spinlock.commandprompt.com.commandprompt.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id pRt-Qxe-fvKO; Tue, 17 Aug 2010 08:07:42 -0700 (PDT) Received: from perhan.alvh.no-ip.org (200-85-200-241.bk3-dsl.surnet.cl [200.85.200.241]) by spinlock.commandprompt.com (Postfix) with ESMTPSA id 02F87348002; Tue, 17 Aug 2010 08:07:42 -0700 (PDT) Received: by perhan.alvh.no-ip.org (Postfix, from userid 1000) id B2D446E4A3; Tue, 17 Aug 2010 11:07:39 -0400 (CLT) Content-Type: text/plain; charset=UTF-8 Cc: Benjamin Krajmalnik , pgsql-performance Subject: Re: Quesion on the use of indexes From: Alvaro Herrera To: Tom Lane In-reply-to: <29298.1282016009@sss.pgh.pa.us> References: <29298.1282016009@sss.pgh.pa.us> Date: Tue, 17 Aug 2010 11:07:39 -0400 Message-Id: <1282057261-sup-9058@alvh.no-ip.org> User-Agent: Sup/git Content-Transfer-Encoding: 8bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.9 tagged_above=-10 required=5 tests=BAYES_00=-1.9 X-Spam-Level: X-Archive-Number: 201008/177 X-Sequence-Number: 40020 Excerpts from Tom Lane's message of lun ago 16 23:33:29 -0400 2010: > "Benjamin Krajmalnik" writes: > > A little background - I have various multi-column indexes whenever I > > have queries which restrict the output based on the values of the 2 > > fields (for example, a client code and the date of a transaction). > > > Is there a performance gain using this approach as opposed to using 2 > > separate indexes, one on the first column and one on the second column? > > Maybe, maybe not ... it's going to depend on a bunch of factors, one of > which is what your update load is like compared to the queries that read > the indexes. There's a bit of coverage of this in the fine manual: see > http://www.postgresql.org/docs/8.4/static/indexes-multicolumn.html > and the next few pages. Another important factor is how selective is each clause in isolation compared to how selective they are together. We have found that doing BitmapAnd of two bitmap-scanned indexes is sometimes much too slow compared to a two-column index. (I have yet to see a case where indexes beyond two columns are useful; at this point, combined bitmap indexscans are enough.) -- Álvaro Herrera The PostgreSQL Company - Command Prompt, Inc. PostgreSQL Replication, Consulting, Custom Development, 24x7 support