X-Original-To: pgsql-docs-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 95906D8B68 for ; Mon, 12 Sep 2005 16:31:14 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 35424-06 for ; Mon, 12 Sep 2005 19:31:07 +0000 (GMT) Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by svr1.postgresql.org (Postfix) with ESMTP id D1E79D8B28 for ; Mon, 12 Sep 2005 16:31:04 -0300 (ADT) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.13.1/8.13.1) with ESMTP id j8CJV4X5023967; Mon, 12 Sep 2005 15:31:04 -0400 (EDT) To: Michael Fuhr Cc: pgsql-docs@postgresql.org, Teodor Sigaev Subject: Re: Multicolumn index doc out of date? In-reply-to: <20050912142647.GA34685@winnie.fuhr.org> References: <20050912142647.GA34685@winnie.fuhr.org> Comments: In-reply-to Michael Fuhr message dated "Mon, 12 Sep 2005 08:26:47 -0600" Date: Mon, 12 Sep 2005 15:31:04 -0400 Message-ID: <23966.1126553464@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.006 required=5 tests=[AWL=0.006] X-Spam-Level: X-Archive-Number: 200509/22 X-Sequence-Number: 3208 Michael Fuhr writes: > So isn't the following paragraph from "Multicolumn Indexes" out of > date? > The query planner can use a multicolumn index for queries that > involve the leftmost column in the index definition plus any > number of columns listed to the right of it, without a gap. For > example, an index on (a, b, c) can be used in queries involving > all of a, b, and c, or in queries involving both a and b, or in > queries involving only a, but not in other combinations. (In a > query involving a and c the planner could choose to use the index > for a, while treating c like an ordinary unindexed column.) Yeah, I had missed that part of the manual while doing the multicolumn rules change. I've replaced it with this: : A multicolumn B-tree index can be used with query conditions that : involve any subset of the index's columns, but the index is most : efficient when there are constraints on the leading (leftmost) : columns. The exact rule is that equality constraints on leading columns, : plus any inequality constraints on the first column that does not have : an equality constraint, will be used to limit the portion of the index : that is scanned. Constraints on columns to the right of these columns : are checked in the index, so they save visits to the table proper, but : they do not reduce the portion of the index that has to be scanned. For : example, given an index on (a, b, c) and a query condition WHERE a = 5 : AND b >= 42 AND c < 77, the index would have to be scanned from the : first entry with a = 5 and b = 42 up through the last entry with a = : 5. Index entries with c >= 77 would be skipped, but they'd still have to : be scanned through. This index could in principle be used for queries : that have constraints on b and/or c with no constraint on a --- but : the entire index would have to be scanned, so in most cases the planner : would prefer a sequential table scan over using the index. : : A multicolumn GiST index can only be used when there is a query : condition on its leading column. As with B-trees, conditions on : additional columns restrict the entries returned by the index, but do : not in themselves aid the index search. I believe the above is accurate about btree, but I'm not so sure about GiST --- Teodor, any comments? regards, tom lane