diff options
Diffstat (limited to 'src/backend/optimizer')
-rw-r--r-- | src/backend/optimizer/path/indxpath.c | 100 | ||||
-rw-r--r-- | src/backend/optimizer/path/pathkeys.c | 3 | ||||
-rw-r--r-- | src/backend/optimizer/plan/createplan.c | 17 | ||||
-rw-r--r-- | src/backend/optimizer/prep/preptlist.c | 7 | ||||
-rw-r--r-- | src/backend/optimizer/prep/prepunion.c | 5 |
5 files changed, 16 insertions, 116 deletions
diff --git a/src/backend/optimizer/path/indxpath.c b/src/backend/optimizer/path/indxpath.c index 5595e1aec99..cfd20e8f488 100644 --- a/src/backend/optimizer/path/indxpath.c +++ b/src/backend/optimizer/path/indxpath.c @@ -9,7 +9,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/optimizer/path/indxpath.c,v 1.122 2002/09/04 20:31:20 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/optimizer/path/indxpath.c,v 1.123 2002/09/18 21:35:21 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -825,32 +825,15 @@ match_clause_to_indexkey(RelOptInfo *rel, * is whether the operator has a commutator operator that matches * the index's opclass. * - * We try both the straightforward match and matches that rely on - * recognizing binary-compatible datatypes. For example, if we have - * an expression like "oid = 123", the operator will be oideqint4, - * which we need to replace with oideq in order to recognize it as - * matching an oid_ops index on the oid field. A variant case is where - * the expression is like "oid::int4 = 123", where the given operator - * will be int4eq and again we need to intuit that we want to use oideq. - * * Returns the OID of the matching operator, or InvalidOid if no match. - * Note that the returned OID will be different from the one in the given - * expression if we used a binary-compatible substitution. Also note that - * if indexkey_on_left is FALSE (meaning we need to commute), the returned - * OID is *not* commuted; it can be plugged directly into the given clause. + * (Formerly, this routine might return a binary-compatible operator + * rather than the original one, but that kluge is history.) */ Oid indexable_operator(Expr *clause, Oid opclass, bool indexkey_on_left) { Oid expr_op = ((Oper *) clause->oper)->opno; - Oid commuted_op, - new_op; - Operator oldoptup; - Form_pg_operator oldopform; - char *opname; - Oid ltype, - rtype, - indexkeytype; + Oid commuted_op; /* Get the commuted operator if necessary */ if (indexkey_on_left) @@ -860,83 +843,10 @@ indexable_operator(Expr *clause, Oid opclass, bool indexkey_on_left) if (commuted_op == InvalidOid) return InvalidOid; - /* Done if the (commuted) operator is a member of the index's opclass */ + /* OK if the (commuted) operator is a member of the index's opclass */ if (op_in_opclass(commuted_op, opclass)) return expr_op; - /* - * Maybe the index uses a binary-compatible operator set. - * - * Get the nominal input types of the given operator and the actual type - * (before binary-compatible relabeling) of the index key. - */ - oldoptup = SearchSysCache(OPEROID, - ObjectIdGetDatum(expr_op), - 0, 0, 0); - if (!HeapTupleIsValid(oldoptup)) - return InvalidOid; /* probably can't happen */ - oldopform = (Form_pg_operator) GETSTRUCT(oldoptup); - opname = pstrdup(NameStr(oldopform->oprname)); - ltype = oldopform->oprleft; - rtype = oldopform->oprright; - ReleaseSysCache(oldoptup); - - if (indexkey_on_left) - { - Node *leftop = (Node *) get_leftop(clause); - - if (leftop && IsA(leftop, RelabelType)) - leftop = ((RelabelType *) leftop)->arg; - indexkeytype = exprType(leftop); - } - else - { - Node *rightop = (Node *) get_rightop(clause); - - if (rightop && IsA(rightop, RelabelType)) - rightop = ((RelabelType *) rightop)->arg; - indexkeytype = exprType(rightop); - } - - /* - * Make sure we have different but binary-compatible types. - */ - if (ltype == indexkeytype && rtype == indexkeytype) - return InvalidOid; /* no chance for a different operator */ - if (!IsBinaryCompatible(ltype, indexkeytype)) - return InvalidOid; - if (!IsBinaryCompatible(rtype, indexkeytype)) - return InvalidOid; - - /* - * OK, look for operator of the same name with the indexkey's data - * type. (In theory this might find a non-semantically-comparable - * operator, but in practice that seems pretty unlikely for - * binary-compatible types.) - */ - new_op = compatible_oper_opid(makeList1(makeString(opname)), - indexkeytype, indexkeytype, true); - - if (OidIsValid(new_op)) - { - if (new_op != expr_op) - { - /* - * OK, we found a binary-compatible operator of the same name; - * now does it match the index? - */ - if (indexkey_on_left) - commuted_op = new_op; - else - commuted_op = get_commutator(new_op); - if (commuted_op == InvalidOid) - return InvalidOid; - - if (op_in_opclass(commuted_op, opclass)) - return new_op; - } - } - return InvalidOid; } diff --git a/src/backend/optimizer/path/pathkeys.c b/src/backend/optimizer/path/pathkeys.c index fc33d5296ad..350c761165b 100644 --- a/src/backend/optimizer/path/pathkeys.c +++ b/src/backend/optimizer/path/pathkeys.c @@ -11,7 +11,7 @@ * Portions Copyright (c) 1994, Regents of the University of California * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/optimizer/path/pathkeys.c,v 1.40 2002/09/04 20:31:20 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/optimizer/path/pathkeys.c,v 1.41 2002/09/18 21:35:21 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -520,6 +520,7 @@ build_index_pathkeys(Query *root, funcnode->funcid = index->indproc; funcnode->funcresulttype = get_func_rettype(index->indproc); funcnode->funcretset = false; /* can never be a set */ + funcnode->funcformat = COERCE_DONTCARE; /* to match any user expr */ funcnode->func_fcache = NULL; while (*indexkeys != 0) diff --git a/src/backend/optimizer/plan/createplan.c b/src/backend/optimizer/plan/createplan.c index da3568bbd7d..9cdbcc2e5e5 100644 --- a/src/backend/optimizer/plan/createplan.c +++ b/src/backend/optimizer/plan/createplan.c @@ -10,7 +10,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/optimizer/plan/createplan.c,v 1.118 2002/09/04 20:31:21 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/optimizer/plan/createplan.c,v 1.119 2002/09/18 21:35:21 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -1027,8 +1027,7 @@ fix_indxqual_sublist(List *indexqual, int baserelid, IndexOptInfo *index, Expr *clause = (Expr *) lfirst(i); Expr *newclause; List *leftvarnos; - Oid opclass, - newopno; + Oid opclass; if (!is_opclause((Node *) clause) || length(clause->args) != 2) elog(ERROR, "fix_indxqual_sublist: indexqual clause is not binary opclause"); @@ -1061,23 +1060,13 @@ fix_indxqual_sublist(List *indexqual, int baserelid, IndexOptInfo *index, index, &opclass); - /* - * Substitute the appropriate operator if the expression operator - * is merely binary-compatible with the index. This shouldn't - * fail, since indxpath.c found it before... - */ - newopno = indexable_operator(newclause, opclass, true); - if (newopno == InvalidOid) - elog(ERROR, "fix_indxqual_sublist: failed to find substitute op"); - ((Oper *) newclause->oper)->opno = newopno; - fixed_qual = lappend(fixed_qual, newclause); /* * Finally, check to see if index is lossy for this operator. If * so, add (a copy of) original form of clause to recheck list. */ - if (op_requires_recheck(newopno, opclass)) + if (op_requires_recheck(((Oper *) newclause->oper)->opno, opclass)) recheck_qual = lappend(recheck_qual, copyObject((Node *) clause)); } diff --git a/src/backend/optimizer/prep/preptlist.c b/src/backend/optimizer/prep/preptlist.c index 5b930e2b5e6..95687cb0d0d 100644 --- a/src/backend/optimizer/prep/preptlist.c +++ b/src/backend/optimizer/prep/preptlist.c @@ -15,7 +15,7 @@ * Portions Copyright (c) 1994, Regents of the University of California * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/optimizer/prep/preptlist.c,v 1.56 2002/09/04 20:31:22 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/optimizer/prep/preptlist.c,v 1.57 2002/09/18 21:35:21 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -187,8 +187,9 @@ expand_targetlist(List *tlist, int command_type, false, /* not a set */ false); if (!att_tup->attisdropped) - new_expr = coerce_type_constraints(NULL, new_expr, - atttype, false); + new_expr = coerce_type_constraints(new_expr, + atttype, + COERCE_IMPLICIT_CAST); break; case CMD_UPDATE: /* Insert NULLs for dropped columns */ diff --git a/src/backend/optimizer/prep/prepunion.c b/src/backend/optimizer/prep/prepunion.c index 414e26c54cb..914b0eee618 100644 --- a/src/backend/optimizer/prep/prepunion.c +++ b/src/backend/optimizer/prep/prepunion.c @@ -14,7 +14,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/optimizer/prep/prepunion.c,v 1.79 2002/09/11 14:48:55 tgl Exp $ + * $Header: /cvsroot/pgsql/src/backend/optimizer/prep/prepunion.c,v 1.80 2002/09/18 21:35:21 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -420,8 +420,7 @@ generate_setop_tlist(List *colTypes, int flag, } else { - expr = coerce_to_common_type(NULL, - expr, + expr = coerce_to_common_type(expr, colType, "UNION/INTERSECT/EXCEPT"); colTypmod = -1; |