OSDN Git Service

Add notion of a "transform function" that can simplify function calls.
[pg-rex/syncrep.git] / src / backend / catalog / pg_proc.c
index 2523653..92be0a7 100644 (file)
@@ -304,6 +304,7 @@ ProcedureCreate(const char *procedureName,
        values[Anum_pg_proc_procost - 1] = Float4GetDatum(procost);
        values[Anum_pg_proc_prorows - 1] = Float4GetDatum(prorows);
        values[Anum_pg_proc_provariadic - 1] = ObjectIdGetDatum(variadicType);
+       values[Anum_pg_proc_protransform - 1] = ObjectIdGetDatum(InvalidOid);
        values[Anum_pg_proc_proisagg - 1] = BoolGetDatum(isAgg);
        values[Anum_pg_proc_proiswindow - 1] = BoolGetDatum(isWindowFunc);
        values[Anum_pg_proc_prosecdef - 1] = BoolGetDatum(security_definer);
@@ -671,7 +672,6 @@ fmgr_internal_validator(PG_FUNCTION_ARGS)
 {
        Oid                     funcoid = PG_GETARG_OID(0);
        HeapTuple       tuple;
-       Form_pg_proc proc;
        bool            isnull;
        Datum           tmp;
        char       *prosrc;
@@ -684,7 +684,6 @@ fmgr_internal_validator(PG_FUNCTION_ARGS)
        tuple = SearchSysCache1(PROCOID, ObjectIdGetDatum(funcoid));
        if (!HeapTupleIsValid(tuple))
                elog(ERROR, "cache lookup failed for function %u", funcoid);
-       proc = (Form_pg_proc) GETSTRUCT(tuple);
 
        tmp = SysCacheGetAttr(PROCOID, tuple, Anum_pg_proc_prosrc, &isnull);
        if (isnull)
@@ -717,7 +716,6 @@ fmgr_c_validator(PG_FUNCTION_ARGS)
        Oid                     funcoid = PG_GETARG_OID(0);
        void       *libraryhandle;
        HeapTuple       tuple;
-       Form_pg_proc proc;
        bool            isnull;
        Datum           tmp;
        char       *prosrc;
@@ -732,7 +730,6 @@ fmgr_c_validator(PG_FUNCTION_ARGS)
        tuple = SearchSysCache1(PROCOID, ObjectIdGetDatum(funcoid));
        if (!HeapTupleIsValid(tuple))
                elog(ERROR, "cache lookup failed for function %u", funcoid);
-       proc = (Form_pg_proc) GETSTRUCT(tuple);
 
        tmp = SysCacheGetAttr(PROCOID, tuple, Anum_pg_proc_prosrc, &isnull);
        if (isnull)
@@ -842,19 +839,24 @@ fmgr_sql_validator(PG_FUNCTION_ARGS)
                if (!haspolyarg)
                {
                        /*
-                        * OK to do full precheck: analyze and rewrite the queries,
-                        * then verify the result type.
+                        * OK to do full precheck: analyze and rewrite the queries, then
+                        * verify the result type.
                         */
+                       SQLFunctionParseInfoPtr pinfo;
+
+                       /* But first, set up parameter information */
+                       pinfo = prepare_sql_fn_parse_info(tuple, NULL, InvalidOid);
+
                        querytree_list = NIL;
                        foreach(lc, raw_parsetree_list)
                        {
                                Node       *parsetree = (Node *) lfirst(lc);
                                List       *querytree_sublist;
 
-                               querytree_sublist = pg_analyze_and_rewrite(parsetree,
-                                                                                                                  prosrc,
-                                                                                                                  proc->proargtypes.values,
-                                                                                                                  proc->pronargs);
+                               querytree_sublist = pg_analyze_and_rewrite_params(parsetree,
+                                                                                                                                 prosrc,
+                                                                          (ParserSetupHook) sql_fn_parser_setup,
+                                                                                                                                 pinfo);
                                querytree_list = list_concat(querytree_list,
                                                                                         querytree_sublist);
                        }