diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2008-09-12 14:56:19 +0000 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2008-09-12 14:56:19 +0000 |
commit | e5b1eed7c916bbe747ee86da815ebe4ea8bdd643 (patch) | |
tree | 0a143cc90fd62359154d45d9322e86a11dabd5dc /src | |
parent | 2d4ef572b42eb8062f895db441d319bc1b136aeb (diff) | |
download | postgresql-e5b1eed7c916bbe747ee86da815ebe4ea8bdd643.tar.gz postgresql-e5b1eed7c916bbe747ee86da815ebe4ea8bdd643.zip |
Skip opfamily check in eclass_matches_any_index() when the index isn't a
btree. We can't easily tell whether clauses generated from the equivalence
class could be used with such an index, so just assume that they might be.
This bit of over-optimization prevented use of non-btree indexes for nestloop
inner indexscans, in any case where the join uses an equality operator that
is also a btree operator --- which in particular is typically true for hash
indexes. Noted while trying to test the current hash index patch.
Diffstat (limited to 'src')
-rw-r--r-- | src/backend/optimizer/path/indxpath.c | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/src/backend/optimizer/path/indxpath.c b/src/backend/optimizer/path/indxpath.c index 8a2e808cc30..3100c92d3d8 100644 --- a/src/backend/optimizer/path/indxpath.c +++ b/src/backend/optimizer/path/indxpath.c @@ -9,7 +9,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/optimizer/path/indxpath.c,v 1.227 2008/02/07 17:53:53 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/optimizer/path/indxpath.c,v 1.227.2.1 2008/09/12 14:56:19 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -1584,7 +1584,18 @@ eclass_matches_any_index(EquivalenceClass *ec, EquivalenceMember *em, { Oid curFamily = families[0]; - if (list_member_oid(ec->ec_opfamilies, curFamily) && + /* + * If it's a btree index, we can reject it if its opfamily isn't + * compatible with the EC, since no clause generated from the + * EC could be used with the index. For non-btree indexes, + * we can't easily tell whether clauses generated from the EC + * could be used with the index, so only check for expression + * match. This might mean we return "true" for a useless index, + * but that will just cause some wasted planner cycles; it's + * better than ignoring useful indexes. + */ + if ((index->relam != BTREE_AM_OID || + list_member_oid(ec->ec_opfamilies, curFamily)) && match_index_to_operand((Node *) em->em_expr, indexcol, index)) return true; |