diff options
Diffstat (limited to 'src/backend/executor/execQual.c')
-rw-r--r-- | src/backend/executor/execQual.c | 86 |
1 files changed, 31 insertions, 55 deletions
diff --git a/src/backend/executor/execQual.c b/src/backend/executor/execQual.c index 0faf52dfd79..e410818900d 100644 --- a/src/backend/executor/execQual.c +++ b/src/backend/executor/execQual.c @@ -82,7 +82,7 @@ static Datum ExecEvalParamExec(ExprState *exprstate, ExprContext *econtext, bool *isNull, ExprDoneCond *isDone); static Datum ExecEvalParamExtern(ExprState *exprstate, ExprContext *econtext, bool *isNull, ExprDoneCond *isDone); -static void init_fcache(Oid foid, FuncExprState *fcache, +static void init_fcache(Oid foid, Oid input_collation, FuncExprState *fcache, MemoryContext fcacheCxt, bool needDescForSets); static void ShutdownFuncExpr(Datum arg); static TupleDesc get_cached_rowtype(Oid type_id, int32 typmod, @@ -120,9 +120,6 @@ static Datum ExecEvalAnd(BoolExprState *andExpr, ExprContext *econtext, static Datum ExecEvalConvertRowtype(ConvertRowtypeExprState *cstate, ExprContext *econtext, bool *isNull, ExprDoneCond *isDone); -static Datum ExecEvalCollateExpr(GenericExprState *exprstate, - ExprContext *econtext, - bool *isNull, ExprDoneCond *isDone); static Datum ExecEvalCase(CaseExprState *caseExpr, ExprContext *econtext, bool *isNull, ExprDoneCond *isDone); static Datum ExecEvalCaseTestExpr(ExprState *exprstate, @@ -1179,7 +1176,7 @@ GetAttributeByName(HeapTupleHeader tuple, const char *attname, bool *isNull) * init_fcache - initialize a FuncExprState node during first use */ static void -init_fcache(Oid foid, FuncExprState *fcache, +init_fcache(Oid foid, Oid input_collation, FuncExprState *fcache, MemoryContext fcacheCxt, bool needDescForSets) { AclResult aclresult; @@ -1205,7 +1202,8 @@ init_fcache(Oid foid, FuncExprState *fcache, /* Set up the primary fmgr lookup information */ fmgr_info_cxt(foid, &(fcache->func), fcacheCxt); - fmgr_info_expr((Node *) fcache->xprstate.expr, &(fcache->func)); + fmgr_info_set_collation(input_collation, &(fcache->func)); + fmgr_info_set_expr((Node *) fcache->xprstate.expr, &(fcache->func)); /* Initialize the function call parameter struct as well */ InitFunctionCallInfoData(fcache->fcinfo_data, &(fcache->func), @@ -1976,7 +1974,7 @@ ExecMakeTableFunctionResult(ExprState *funcexpr, { FuncExpr *func = (FuncExpr *) fcache->xprstate.expr; - init_fcache(func->funcid, fcache, + init_fcache(func->funcid, func->inputcollid, fcache, econtext->ecxt_per_query_memory, false); } returnsSet = fcache->func.fn_retset; @@ -2255,7 +2253,8 @@ ExecEvalFunc(FuncExprState *fcache, FuncExpr *func = (FuncExpr *) fcache->xprstate.expr; /* Initialize function lookup info */ - init_fcache(func->funcid, fcache, econtext->ecxt_per_query_memory, true); + init_fcache(func->funcid, func->inputcollid, fcache, + econtext->ecxt_per_query_memory, true); /* Go directly to ExecMakeFunctionResult on subsequent uses */ fcache->xprstate.evalfunc = (ExprStateEvalFunc) ExecMakeFunctionResult; @@ -2277,7 +2276,8 @@ ExecEvalOper(FuncExprState *fcache, OpExpr *op = (OpExpr *) fcache->xprstate.expr; /* Initialize function lookup info */ - init_fcache(op->opfuncid, fcache, econtext->ecxt_per_query_memory, true); + init_fcache(op->opfuncid, op->inputcollid, fcache, + econtext->ecxt_per_query_memory, true); /* Go directly to ExecMakeFunctionResult on subsequent uses */ fcache->xprstate.evalfunc = (ExprStateEvalFunc) ExecMakeFunctionResult; @@ -2318,7 +2318,7 @@ ExecEvalDistinct(FuncExprState *fcache, { DistinctExpr *op = (DistinctExpr *) fcache->xprstate.expr; - init_fcache(op->opfuncid, fcache, + init_fcache(op->opfuncid, op->inputcollid, fcache, econtext->ecxt_per_query_memory, true); Assert(!fcache->func.fn_retset); } @@ -2395,7 +2395,7 @@ ExecEvalScalarArrayOp(ScalarArrayOpExprState *sstate, */ if (sstate->fxprstate.func.fn_oid == InvalidOid) { - init_fcache(opexpr->opfuncid, &sstate->fxprstate, + init_fcache(opexpr->opfuncid, opexpr->inputcollid, &sstate->fxprstate, econtext->ecxt_per_query_memory, true); Assert(!sstate->fxprstate.func.fn_retset); } @@ -2754,20 +2754,6 @@ ExecEvalConvertRowtype(ConvertRowtypeExprState *cstate, } /* ---------------------------------------------------------------- - * ExecEvalCollateExpr - * - * Evaluate a CollateExpr node. - * ---------------------------------------------------------------- - */ -static Datum -ExecEvalCollateExpr(GenericExprState *exprstate, - ExprContext *econtext, - bool *isNull, ExprDoneCond *isDone) -{ - return ExecEvalExpr(exprstate->arg, econtext, isNull, isDone); -} - -/* ---------------------------------------------------------------- * ExecEvalCase * * Evaluate a CASE clause. Will have boolean expressions @@ -3542,7 +3528,7 @@ ExecEvalNullIf(FuncExprState *nullIfExpr, { NullIfExpr *op = (NullIfExpr *) nullIfExpr->xprstate.expr; - init_fcache(op->opfuncid, nullIfExpr, + init_fcache(op->opfuncid, op->inputcollid, nullIfExpr, econtext->ecxt_per_query_memory, true); Assert(!nullIfExpr->func.fn_retset); } @@ -4129,9 +4115,8 @@ ExecEvalArrayCoerceExpr(ArrayCoerceExprState *astate, /* Set up the primary fmgr lookup information */ fmgr_info_cxt(acoerce->elemfuncid, &(astate->elemfunc), econtext->ecxt_per_query_memory); - - /* Initialize additional info */ - fmgr_info_expr((Node *) acoerce, &(astate->elemfunc)); + /* Note: coercion functions are assumed to not use collation */ + fmgr_info_set_expr((Node *) acoerce, &(astate->elemfunc)); } /* @@ -4400,6 +4385,18 @@ ExecInitExpr(Expr *node, PlanState *parent) state = (ExprState *) fstate; } break; + case T_NullIfExpr: + { + NullIfExpr *nullifexpr = (NullIfExpr *) node; + FuncExprState *fstate = makeNode(FuncExprState); + + fstate->xprstate.evalfunc = (ExprStateEvalFunc) ExecEvalNullIf; + fstate->args = (List *) + ExecInitExpr((Expr *) nullifexpr->args, parent); + fstate->func.fn_oid = InvalidOid; /* not initialized */ + state = (ExprState *) fstate; + } + break; case T_ScalarArrayOpExpr: { ScalarArrayOpExpr *opexpr = (ScalarArrayOpExpr *) node; @@ -4551,16 +4548,6 @@ ExecInitExpr(Expr *node, PlanState *parent) state = (ExprState *) cstate; } break; - case T_CollateExpr: - { - CollateExpr *collate = (CollateExpr *) node; - GenericExprState *gstate = makeNode(GenericExprState); - - gstate->xprstate.evalfunc = (ExprStateEvalFunc) ExecEvalCollateExpr; - gstate->arg = ExecInitExpr(collate->arg, parent); - state = (ExprState *) gstate; - } - break; case T_CaseExpr: { CaseExpr *caseexpr = (CaseExpr *) node; @@ -4713,11 +4700,11 @@ ExecInitExpr(Expr *node, PlanState *parent) Assert(list_length(rcexpr->opfamilies) == nopers); rstate->funcs = (FmgrInfo *) palloc(nopers * sizeof(FmgrInfo)); i = 0; - forthree(l, rcexpr->opnos, l2, rcexpr->opfamilies, l3, rcexpr->collids) + forthree(l, rcexpr->opnos, l2, rcexpr->opfamilies, l3, rcexpr->inputcollids) { Oid opno = lfirst_oid(l); Oid opfamily = lfirst_oid(l2); - Oid collid = lfirst_oid(l3); + Oid inputcollid = lfirst_oid(l3); int strategy; Oid lefttype; Oid righttype; @@ -4739,7 +4726,7 @@ ExecInitExpr(Expr *node, PlanState *parent) * does this code. */ fmgr_info(proc, &(rstate->funcs[i])); - fmgr_info_collation(collid, &(rstate->funcs[i])); + fmgr_info_set_collation(inputcollid, &(rstate->funcs[i])); i++; } state = (ExprState *) rstate; @@ -4799,7 +4786,8 @@ ExecInitExpr(Expr *node, PlanState *parent) * code. */ fmgr_info(typentry->cmp_proc, &(mstate->cfunc)); - fmgr_info_collation(minmaxexpr->collid, &(mstate->cfunc)); + fmgr_info_set_collation(minmaxexpr->inputcollid, + &(mstate->cfunc)); state = (ExprState *) mstate; } break; @@ -4836,18 +4824,6 @@ ExecInitExpr(Expr *node, PlanState *parent) state = (ExprState *) xstate; } break; - case T_NullIfExpr: - { - NullIfExpr *nullifexpr = (NullIfExpr *) node; - FuncExprState *fstate = makeNode(FuncExprState); - - fstate->xprstate.evalfunc = (ExprStateEvalFunc) ExecEvalNullIf; - fstate->args = (List *) - ExecInitExpr((Expr *) nullifexpr->args, parent); - fstate->func.fn_oid = InvalidOid; /* not initialized */ - state = (ExprState *) fstate; - } - break; case T_NullTest: { NullTest *ntest = (NullTest *) node; |