diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2007-05-31 16:57:34 +0000 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2007-05-31 16:57:34 +0000 |
commit | 10f719af331b0248f532fb1eeee642f93ed981a9 (patch) | |
tree | cde09eb1585a3a2e7861517b68a0ac0859d99a09 /src/backend/optimizer/path/pathkeys.c | |
parent | 7ce9b3683ea76233c33e550110c5a63ecd8add89 (diff) | |
download | postgresql-10f719af331b0248f532fb1eeee642f93ed981a9.tar.gz postgresql-10f719af331b0248f532fb1eeee642f93ed981a9.zip |
Change build_index_pathkeys() so that the expressions it builds to represent
index key columns always have the type expected by the index's associated
operators, ie, we add RelabelType nodes when dealing with binary-compatible
index opclasses. This is needed to get varchar indexes to play nicely with
the new EquivalenceClass machinery, as per recent gripe from Josh Berkus that
CVS HEAD was failing to match a varchar index column to a constant restriction
in the query.
It seems likely that this change will allow removal of a lot of ugly ad-hoc
RelabelType-stripping that the planner has traditionally done while matching
expressions to other expressions, but I'll worry about that some other day.
Diffstat (limited to 'src/backend/optimizer/path/pathkeys.c')
-rw-r--r-- | src/backend/optimizer/path/pathkeys.c | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/src/backend/optimizer/path/pathkeys.c b/src/backend/optimizer/path/pathkeys.c index 7a2aaa48f6b..a110fa947b1 100644 --- a/src/backend/optimizer/path/pathkeys.c +++ b/src/backend/optimizer/path/pathkeys.c @@ -11,13 +11,14 @@ * Portions Copyright (c) 1994, Regents of the University of California * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/optimizer/path/pathkeys.c,v 1.84 2007/04/15 20:09:28 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/optimizer/path/pathkeys.c,v 1.85 2007/05/31 16:57:34 tgl Exp $ * *------------------------------------------------------------------------- */ #include "postgres.h" #include "access/skey.h" +#include "catalog/pg_type.h" #include "nodes/makefuncs.h" #include "nodes/plannodes.h" #include "optimizer/clauses.h" @@ -493,6 +494,27 @@ build_index_pathkeys(PlannerInfo *root, indexprs_item = lnext(indexprs_item); } + /* + * When dealing with binary-compatible indexes, we have to ensure that + * the exposed type of the expression tree matches the declared input + * type of the opclass, except when that is a polymorphic type + * (compare the behavior of parse_coerce.c). This ensures that we can + * correctly match the indexkey expression to expressions we find in + * the query, because arguments of operators that could match the + * index will be cast likewise. + */ + if (exprType((Node *) indexkey) != index->opcintype[i] && + !IsPolymorphicType(index->opcintype[i])) + { + /* Strip any existing RelabelType, and add a new one */ + while (indexkey && IsA(indexkey, RelabelType)) + indexkey = (Expr *) ((RelabelType *) indexkey)->arg; + indexkey = (Expr *) makeRelabelType(indexkey, + index->opcintype[i], + -1, + COERCE_DONTCARE); + } + /* OK, make a canonical pathkey for this sort key */ cpathkey = make_pathkey_from_sortinfo(root, indexkey, |