diff options
Diffstat (limited to 'src/backend')
-rw-r--r-- | src/backend/optimizer/path/pathkeys.c | 24 | ||||
-rw-r--r-- | src/backend/optimizer/util/plancat.c | 19 |
2 files changed, 34 insertions, 9 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, diff --git a/src/backend/optimizer/util/plancat.c b/src/backend/optimizer/util/plancat.c index 605e7f64eed..70b3d7d43f5 100644 --- a/src/backend/optimizer/util/plancat.c +++ b/src/backend/optimizer/util/plancat.c @@ -9,7 +9,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/optimizer/util/plancat.c,v 1.135 2007/05/25 17:54:25 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/optimizer/util/plancat.c,v 1.136 2007/05/31 16:57:34 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -171,20 +171,23 @@ get_relation_info(PlannerInfo *root, Oid relationObjectId, bool inhparent, info->ncolumns = ncolumns = index->indnatts; /* - * Need to make opfamily array large enough to put a terminating - * zero at the end. + * Allocate per-column info arrays. To save a few palloc cycles + * we allocate all the Oid-type arrays in one request. Note that + * the opfamily array needs an extra, terminating zero at the end. + * We pre-zero the ordering info in case the index is unordered. */ info->indexkeys = (int *) palloc(sizeof(int) * ncolumns); - info->opfamily = (Oid *) palloc0(sizeof(Oid) * (ncolumns + 1)); - /* initialize these to zeroes in case index is unordered */ - info->fwdsortop = (Oid *) palloc0(sizeof(Oid) * ncolumns); - info->revsortop = (Oid *) palloc0(sizeof(Oid) * ncolumns); + info->opfamily = (Oid *) palloc0(sizeof(Oid) * (4 * ncolumns + 1)); + info->opcintype = info->opfamily + (ncolumns + 1); + info->fwdsortop = info->opcintype + ncolumns; + info->revsortop = info->fwdsortop + ncolumns; info->nulls_first = (bool *) palloc0(sizeof(bool) * ncolumns); for (i = 0; i < ncolumns; i++) { - info->opfamily[i] = indexRelation->rd_opfamily[i]; info->indexkeys[i] = index->indkey.values[i]; + info->opfamily[i] = indexRelation->rd_opfamily[i]; + info->opcintype[i] = indexRelation->rd_opcintype[i]; } info->relam = indexRelation->rd_rel->relam; |