fixed the bug of cast

This commit is contained in:
luozihao
2021-07-14 09:29:54 +08:00
parent 468d6bcbc2
commit c98f970368
12 changed files with 477 additions and 358 deletions

View File

@ -40,6 +40,7 @@
#include "access/nbtree.h"
#include "access/tupconvert.h"
#include "access/tableam.h"
#include "catalog/pg_cast.h"
#include "catalog/pg_type.h"
#include "commands/typecmds.h"
#include "executor/execdebug.h"
@ -2717,12 +2718,41 @@ static Datum ExecEvalFunc(FuncExprState* fcache, ExprContext* econtext, bool* is
{
/* This is called only the first time through */
FuncExpr* func = (FuncExpr*)fcache->xprstate.expr;
Oid old_user = InvalidOid;
int save_sec_context = 0;
Oid cast_owner = InvalidOid;
Oid target_type = InvalidOid;
Oid source_type = InvalidOid;
/* Initialize function lookup info */
init_fcache<false>(func->funcid, func->inputcollid, fcache, econtext->ecxt_per_query_memory, true);
bool has_refcursor = func_has_refcursor_args(func->funcid, &fcache->fcinfo_data);
int cursor_return_number = fcache->fcinfo_data.refcursor_data.return_number;
if (func->funcformat == COERCE_EXPLICIT_CAST || func->funcformat == COERCE_IMPLICIT_CAST) {
target_type = func->funcresulttype;
source_type = fcache->fcinfo_data.argTypes[0];
HeapTuple proc_tuple = SearchSysCache(PROCOID, ObjectIdGetDatum(func->funcid), 0, 0, 0);
if (HeapTupleIsValid(proc_tuple)) {
Form_pg_proc proc_struct = (Form_pg_proc)GETSTRUCT(proc_tuple);
source_type = proc_struct->proargtypes.values[0];
ReleaseSysCache(proc_tuple);
}
HeapTuple cast_tuple = SearchSysCache2(CASTSOURCETARGET, ObjectIdGetDatum(source_type),
ObjectIdGetDatum(target_type));
if (HeapTupleIsValid(cast_tuple)) {
Form_pg_cast castForm = (Form_pg_cast)GETSTRUCT(cast_tuple);
cast_owner = castForm->castowner;
ReleaseSysCache(cast_tuple);
}
if (cast_owner != InvalidCastOwnerId && OidIsValid(cast_owner)) {
u_sess->exec_cxt.cast_owner = cast_owner;
}
}
/*
* We need to invoke ExecMakeFunctionResult if either the function itself
* or any of its input expressions can return a set. Otherwise, invoke