From fc43696d1a28ccc5f58b2b0abce8e86f0920433d Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Sat, 2 Oct 1999 04:37:52 +0000 Subject: [PATCH] Fix make_clause and make_opclause to record valid type info in the Expr nodes they produce. This fixes a few cases of errors like 'typeidTypeRelid: Invalid type - oid = 0' caused by calling parser-related routines on expression trees that have already been processed by planner- related routines. --- src/backend/optimizer/util/clauses.c | 42 +++++++++++++++------------- 1 file changed, 22 insertions(+), 20 deletions(-) diff --git a/src/backend/optimizer/util/clauses.c b/src/backend/optimizer/util/clauses.c index 7f77ae78a6..1fc91f0cae 100644 --- a/src/backend/optimizer/util/clauses.c +++ b/src/backend/optimizer/util/clauses.c @@ -7,7 +7,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/optimizer/util/clauses.c,v 1.52 1999/09/26 02:28:33 tgl Exp $ + * $Header: /cvsroot/pgsql/src/backend/optimizer/util/clauses.c,v 1.53 1999/10/02 04:37:52 tgl Exp $ * * HISTORY * AUTHOR DATE MAJOR EVENT @@ -49,27 +49,29 @@ static Node *eval_const_expressions_mutator (Node *node, void *context); Expr * make_clause(int type, Node *oper, List *args) { - if (type == AND_EXPR || type == OR_EXPR || type == NOT_EXPR || - type == OP_EXPR || type == FUNC_EXPR) - { - Expr *expr = makeNode(Expr); + Expr *expr = makeNode(Expr); - /* - * assume type checking already done and we don't need the type of - * the expr any more. - */ - expr->typeOid = InvalidOid; - expr->opType = type; - expr->oper = oper; /* ignored for AND, OR, NOT */ - expr->args = args; - return expr; - } - else + switch (type) { - elog(ERROR, "make_clause: unsupported type %d", type); - /* will this ever happen? translated from lispy C code - ay 10/94 */ - return (Expr *) args; + case AND_EXPR: + case OR_EXPR: + case NOT_EXPR: + expr->typeOid = BOOLOID; + break; + case OP_EXPR: + expr->typeOid = ((Oper *) oper)->opresulttype; + break; + case FUNC_EXPR: + expr->typeOid = ((Func *) oper)->functype; + break; + default: + elog(ERROR, "make_clause: unsupported type %d", type); + break; } + expr->opType = type; + expr->oper = oper; /* ignored for AND, OR, NOT */ + expr->args = args; + return expr; } @@ -107,7 +109,7 @@ make_opclause(Oper *op, Var *leftop, Var *rightop) { Expr *expr = makeNode(Expr); - expr->typeOid = InvalidOid; /* assume type checking done */ + expr->typeOid = op->opresulttype; expr->opType = OP_EXPR; expr->oper = (Node *) op; if (rightop)