!46 Add prokind in pg_proc, remove proisagg and proiswindow.

Merge pull request !46 from TotaJ/feature/pg_proc
This commit is contained in:
opengauss-bot 2020-07-24 21:34:48 +08:00 committed by Gitee
commit 33fb785204
29 changed files with 3294 additions and 3215 deletions

View File

@ -4694,7 +4694,7 @@ AggInfo* getAggregates(Archive* fout, int* numAggs)
"(%s proowner) AS rolname, "
"proacl AS aggacl "
"FROM pg_proc p "
"WHERE proisagg AND ("
"WHERE prokind = 'a' AND ("
"pronamespace != "
"(SELECT oid FROM pg_namespace "
"WHERE nspname = 'pg_catalog')",
@ -4716,7 +4716,7 @@ AggInfo* getAggregates(Archive* fout, int* numAggs)
"(%s proowner) AS rolname, "
"proacl AS aggacl "
"FROM pg_proc "
"WHERE proisagg "
"WHERE prokind = 'a' "
"AND pronamespace != "
"(SELECT oid FROM pg_namespace WHERE nspname = 'pg_catalog')",
username_subquery);
@ -4862,7 +4862,7 @@ FuncInfo* getFuncs(Archive* fout, int* numFuncs)
"pronamespace, "
"(%s proowner) AS rolname "
"FROM pg_proc p "
"WHERE NOT proisagg AND ("
"WHERE prokind != 'a' AND ("
"pronamespace != "
"(SELECT oid FROM pg_namespace "
"WHERE nspname = 'pg_catalog')",
@ -11118,7 +11118,7 @@ static void dumpFunc(Archive* fout, FuncInfo* finfo)
char* proallargtypes = NULL;
char* proargmodes = NULL;
char* proargnames = NULL;
char* proiswindow = NULL;
char* prokind = NULL;
char* provolatile = NULL;
char* proisstrict = NULL;
char* prosecdef = NULL;
@ -11171,7 +11171,7 @@ static void dumpFunc(Archive* fout, FuncInfo* finfo)
"pg_catalog.pg_get_function_arguments(oid) AS funcargs, "
"pg_catalog.pg_get_function_identity_arguments(oid) AS funciargs, "
"pg_catalog.pg_get_function_result(oid) AS funcresult, "
"proiswindow, provolatile, proisstrict, prosecdef, "
"prokind, provolatile, proisstrict, prosecdef, "
"proleakproof, proconfig, procost, prorows, "
"%s, "
"%s, "
@ -11192,7 +11192,7 @@ static void dumpFunc(Archive* fout, FuncInfo* finfo)
funciargs = PQgetvalue(res, 0, PQfnumber(res, "funciargs"));
funcresult = PQgetvalue(res, 0, PQfnumber(res, "funcresult"));
proallargtypes = proargmodes = proargnames = NULL;
proiswindow = PQgetvalue(res, 0, PQfnumber(res, "proiswindow"));
prokind = PQgetvalue(res, 0, PQfnumber(res, "prokind"));
provolatile = PQgetvalue(res, 0, PQfnumber(res, "provolatile"));
proisstrict = PQgetvalue(res, 0, PQfnumber(res, "proisstrict"));
prosecdef = PQgetvalue(res, 0, PQfnumber(res, "prosecdef"));
@ -11303,7 +11303,7 @@ static void dumpFunc(Archive* fout, FuncInfo* finfo)
appendPQExpBuffer(q, "\n LANGUAGE %s", fmtId(lanname));
if (proiswindow[0] == 't')
if (PROC_IS_WIN(prokind[0]))
appendPQExpBuffer(q, " WINDOW");
if (provolatile[0] != PROVOLATILE_VOLATILE) {

View File

@ -101,7 +101,7 @@ bool describeAggregates(const char* pattern, bool verbose, bool showSystem)
" pg_catalog.obj_description(p.oid, 'pg_proc') as \"%s\"\n"
"FROM pg_catalog.pg_proc p\n"
" LEFT JOIN pg_catalog.pg_namespace n ON n.oid = p.pronamespace\n"
"WHERE p.proisagg\n",
"WHERE p.prokind = 'a'\n",
gettext_noop("Description"));
if (!showSystem && (pattern == NULL))
@ -264,8 +264,8 @@ bool describeFunctions(const char* functypes, const char* pattern, bool verbose,
" pg_catalog.pg_get_function_result(p.oid) as \"%s\",\n"
" pg_catalog.pg_get_function_arguments(p.oid) as \"%s\",\n"
" CASE\n"
" WHEN p.proisagg THEN '%s'\n"
" WHEN p.proiswindow THEN '%s'\n"
" WHEN p.prokind = 'a' THEN '%s'\n"
" WHEN p.prokind = 'w' THEN '%s'\n"
" WHEN p.prorettype = 'pg_catalog.trigger'::pg_catalog.regtype THEN '%s'\n"
" ELSE '%s'\n"
"END as \"%s\"",
@ -311,7 +311,7 @@ bool describeFunctions(const char* functypes, const char* pattern, bool verbose,
" ), ', ')\n"
" END AS \"%s\",\n"
" CASE\n"
" WHEN p.proisagg THEN '%s'\n"
" WHEN p.prokind = 'a' THEN '%s'\n"
" WHEN p.prorettype = 'pg_catalog.trigger'::pg_catalog.regtype THEN '%s'\n"
" ELSE '%s'\n"
" END AS \"%s\"",
@ -328,7 +328,7 @@ bool describeFunctions(const char* functypes, const char* pattern, bool verbose,
" pg_catalog.format_type(p.prorettype, NULL) as \"%s\",\n"
" pg_catalog.oidvectortypes(p.proargtypes) as \"%s\",\n"
" CASE\n"
" WHEN p.proisagg THEN '%s'\n"
" WHEN p.prokind = 'a' THEN '%s'\n"
" WHEN p.prorettype = 'pg_catalog.trigger'::pg_catalog.regtype THEN '%s'\n"
" ELSE '%s'\n"
" END AS \"%s\"",
@ -384,7 +384,7 @@ bool describeFunctions(const char* functypes, const char* pattern, bool verbose,
appendPQExpBuffer(&buf, "WHERE ");
have_where = true;
}
appendPQExpBuffer(&buf, "NOT p.proisagg\n");
appendPQExpBuffer(&buf, "p.prokind != 'a'\n");
}
if (!showTrigger) {
if (have_where) {
@ -402,7 +402,7 @@ bool describeFunctions(const char* functypes, const char* pattern, bool verbose,
appendPQExpBuffer(&buf, "WHERE ");
have_where = true;
}
appendPQExpBuffer(&buf, "NOT p.proiswindow\n");
appendPQExpBuffer(&buf, "p.prokind != 'w'\n");
}
} else {
bool needs_or = false;
@ -411,7 +411,7 @@ bool describeFunctions(const char* functypes, const char* pattern, bool verbose,
have_where = true;
/* Note: at least one of these must be true ... */
if (showAggregate) {
appendPQExpBuffer(&buf, "p.proisagg\n");
appendPQExpBuffer(&buf, "p.prokind = 'a'\n");
needs_or = true;
}
if (showTrigger) {
@ -425,7 +425,7 @@ bool describeFunctions(const char* functypes, const char* pattern, bool verbose,
if (needs_or) {
appendPQExpBuffer(&buf, " OR ");
}
appendPQExpBuffer(&buf, "p.proiswindow\n");
appendPQExpBuffer(&buf, "p.prokind = 'w'\n");
needs_or = true;
}
appendPQExpBuffer(&buf, " )\n");

View File

@ -198,7 +198,7 @@ static const SchemaQuery Query_for_list_of_aggregates = {
/* catname */
"pg_catalog.pg_proc p",
/* selcondition */
"p.proisagg",
"p.prokind",
/* viscondition */
"pg_catalog.pg_function_is_visible(p.oid)",
/* namespace */

File diff suppressed because it is too large Load Diff

View File

@ -299,8 +299,7 @@ void AggregateCreate(const char* aggName, Oid aggNamespace, Oid* aggArgTypes, in
InvalidOid, /* no validator */
"aggregate_dummy", /* placeholder proc */
NULL, /* probin */
true, /* isAgg */
false, /* isWindowFunc */
PROKIND_AGGREGATE, /* prokind */
false, /* security invoker (currently not
* definable for agg) */
false, /* isLeakProof */

View File

@ -106,7 +106,7 @@ static char* getCFunProbin(const char* probin, const char* fun_name, Oid procNam
static void checkFunctionConflicts(HeapTuple oldtup, const char* procedureName, Oid proowner, Oid returnType,
Datum allParameterTypes, Datum parameterModes, Datum parameterNames, bool returnsSet, bool replace, bool isOraStyle,
bool isAgg, bool isWindowFunc);
char prokind);
static bool user_define_func_check(Oid languageId, const char* probin, char** absolutePath, CFunType* function_type);
static const char* get_file_name(const char* filePath, CFunType function_type);
@ -677,12 +677,11 @@ static bool checkPackageFunctionConflicts(
* @in returnsSet: Return type if is set.
* @in replace: Is replace.
* @in isOraStyle: Is a style.
* @in isAgg: Is agg function.
* @in isWindowFunc: Is windows function.
* @in prokind: Procedure kind.
*/
static void checkFunctionConflicts(HeapTuple oldtup, const char* procedureName, Oid proowner, Oid returnType,
Datum allParameterTypes, Datum parameterModes, Datum parameterNames, bool returnsSet, bool replace, bool isOraStyle,
bool isAgg, bool isWindowFunc)
char prokind)
{
Datum proargnames;
bool isnull = false;
@ -778,8 +777,8 @@ static void checkFunctionConflicts(HeapTuple oldtup, const char* procedureName,
}
/* Can't change aggregate or window-function status, either */
if (oldproc->proisagg != isAgg) {
if (oldproc->proisagg) {
if (PROC_IS_AGG(oldproc->prokind) != PROC_IS_AGG(prokind)) {
if (PROC_IS_AGG(oldproc->prokind)) {
ereport(ERROR,
(errcode(ERRCODE_WRONG_OBJECT_TYPE),
errmsg("function \"%s\" is an aggregate function", procedureName)));
@ -790,8 +789,8 @@ static void checkFunctionConflicts(HeapTuple oldtup, const char* procedureName,
}
}
if (oldproc->proiswindow != isWindowFunc) {
if (oldproc->proiswindow) {
if (PROC_IS_WIN(oldproc->prokind) != PROC_IS_WIN(prokind)) {
if (PROC_IS_WIN(oldproc->prokind)) {
ereport(ERROR,
(errcode(ERRCODE_WRONG_OBJECT_TYPE), errmsg("function \"%s\" is a window function", procedureName)));
} else {
@ -897,7 +896,7 @@ static bool user_define_func_check(Oid languageId, const char* probin, char** ab
*/
Oid ProcedureCreate(const char* procedureName, Oid procNamespace, bool isOraStyle, bool replace, bool returnsSet,
Oid returnType, Oid proowner, Oid languageObjectId, Oid languageValidator, const char* prosrc, const char* probin,
bool isAgg, bool isWindowFunc, bool security_definer, bool isLeakProof, bool isStrict, char volatility,
char prokind, bool security_definer, bool isLeakProof, bool isStrict, char volatility,
oidvector* parameterTypes, Datum allParameterTypes, Datum parameterModes, Datum parameterNames,
List* parameterDefaults, Datum proconfig, float4 procost, float4 prorows, int2vector* prodefaultargpos, bool fenced,
bool shippable, bool package)
@ -1145,8 +1144,7 @@ Oid ProcedureCreate(const char* procedureName, Oid procNamespace, bool isOraStyl
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_prokind - 1] = CharGetDatum(prokind);
values[Anum_pg_proc_prosecdef - 1] = BoolGetDatum(security_definer);
values[Anum_pg_proc_proleakproof - 1] = BoolGetDatum(isLeakProof);
values[Anum_pg_proc_proisstrict - 1] = BoolGetDatum(isStrict);
@ -1244,8 +1242,7 @@ Oid ProcedureCreate(const char* procedureName, Oid procNamespace, bool isOraStyl
returnsSet,
replace,
isOraStyle,
isAgg,
isWindowFunc);
prokind);
bool isNull = false;
Datum ispackage = SysCacheGetAttr(PROCOID, oldtup, Anum_pg_proc_package, &isNull);

View File

@ -366,8 +366,8 @@ WHERE
UNION ALL
SELECT
l.objoid, l.classoid, l.objsubid,
CASE WHEN pro.proisagg = true THEN 'aggregate'::text
WHEN pro.proisagg = false THEN 'function'::text
CASE WHEN pro.prokind = 'a' THEN 'aggregate'::text
WHEN pro.prokind != 'a' THEN 'function'::text
END AS objtype,
pro.pronamespace AS objnamespace,
CASE WHEN pg_function_is_visible(pro.oid)

View File

@ -762,8 +762,8 @@ static Node* build_coercion_expression(Node* node, CoercionPathType pathtype, Oi
* various binary-compatibility cases.
*/
AssertEreport(!procstruct->proretset, MOD_OPT, "function is not return set");
AssertEreport(!procstruct->proisagg, MOD_OPT, "function is not agg");
AssertEreport(!procstruct->proiswindow, MOD_OPT, "function is not window function");
AssertEreport(!PROC_IS_AGG(procstruct->prokind), MOD_OPT, "function is not agg");
AssertEreport(!PROC_IS_WIN(procstruct->prokind), MOD_OPT, "function is not window function");
nargs = procstruct->pronargs;
AssertEreport((nargs >= 1 && nargs <= 3), MOD_OPT, "The number of parameters in the function is incorrect.");
AssertEreport((nargs < 2 || procstruct->proargtypes.values[1] == INT4OID),

View File

@ -1700,9 +1700,9 @@ FuncDetailCode func_get_detail(List* funcname, List* fargs, List* fargnames, int
}
*argdefaults = GetDefaultVale(*funcid, best_candidate->argnumbers, best_candidate->ndargs);
}
if (pform->proisagg) {
if (PROC_IS_AGG(pform->prokind)) {
result = FUNCDETAIL_AGGREGATE;
} else if (pform->proiswindow) {
} else if (PROC_IS_WIN(pform->prokind)) {
result = FUNCDETAIL_WINDOWFUNC;
} else {
result = FUNCDETAIL_NORMAL;
@ -2106,7 +2106,7 @@ Oid LookupAggNameTypeNames(List* aggname, List* argtypes, bool noError)
}
pform = (Form_pg_proc)GETSTRUCT(ftup);
if (!pform->proisagg) {
if (!PROC_IS_AGG(pform->prokind)) {
ReleaseSysCache(ftup);
if (noError)
return InvalidOid;

View File

@ -81,12 +81,12 @@ my $funcName; #[1]
my $nargs; #[2]
my $strict; #[3]
my $retset; #[4]
my $prosrc; #[25]
my $prosrc; #[24]
my $prorettype; #[6]
foreach my $row (@{ $catalog{builtindata} })
{
if ($row =~ /_0\(([0-9A-Z]+)\),\s+_1\(\"(\S+)\"\),\s+_2\((\d+)\),\s+_3\((\w+)\),\s+_4\((\w+)\),\s+.+?_6\((\d+)\),.+?_25\(\"(\w+)\"\),/)
if ($row =~ /_0\(([0-9A-Z]+)\),\s+_1\(\"(\S+)\"\),\s+_2\((\d+)\),\s+_3\((\w+)\),\s+_4\((\w+)\),\s+.+?_6\((\d+)\),.+?_24\(\"(\w+)\"\),/)
{
$foid = $1;
$funcName = $2;

View File

@ -3198,7 +3198,7 @@ char* pg_get_functiondef_worker(Oid funcid, int* headerlines)
proc = (Form_pg_proc)GETSTRUCT(proctup);
name = NameStr(proc->proname);
if (proc->proisagg) {
if (PROC_IS_AGG(proc->prokind)) {
ereport(ERROR, (errcode(ERRCODE_CACHE_LOOKUP_FAILED), errmsg("\"%s\" is an aggregate function", name)));
}
/* Need its pg_language tuple for the language name */
@ -3223,7 +3223,7 @@ char* pg_get_functiondef_worker(Oid funcid, int* headerlines)
/* Emit some miscellaneous options on one line */
oldlen = buf.len;
if (proc->proiswindow) {
if (PROC_IS_WIN(proc->prokind)) {
appendStringInfoString(&buf, " WINDOW");
}
switch (proc->provolatile) {
@ -3454,7 +3454,7 @@ static int print_function_arguments(StringInfo buf, HeapTuple proctup, bool prin
}
/* Check for special treatment of ordered-set aggregates */
if (proc->proisagg) {
if (PROC_IS_AGG(proc->prokind)) {
Oid proc_tup_oid;
HeapTuple agg_tup;
Form_pg_aggregate agg_form;

View File

@ -1825,8 +1825,7 @@ HeapTuple CreateHeapTuple4BuiltinFunc(const Builtin_func* func, TupleDesc desc)
values[Anum_pg_proc_prorows - 1] = Float4GetDatum(func->prorows);
values[Anum_pg_proc_provariadic - 1] = ObjectIdGetDatum(variadicType);
values[Anum_pg_proc_protransform - 1] = ObjectIdGetDatum(func->protransform);
values[Anum_pg_proc_proisagg - 1] = BoolGetDatum(func->proisagg);
values[Anum_pg_proc_proiswindow - 1] = BoolGetDatum(func->proiswindow);
values[Anum_pg_proc_prokind - 1] = CharGetDatum(func->prokind);
values[Anum_pg_proc_prosecdef - 1] = BoolGetDatum(func->prosecdef);
values[Anum_pg_proc_proleakproof - 1] = BoolGetDatum(func->proleakproof);
values[Anum_pg_proc_proisstrict - 1] = BoolGetDatum(func->strict);
@ -2009,7 +2008,7 @@ List* SearchBuiltinProcCacheList(CatCache* cache, int nkey, Datum* arguments, Li
TupleDesc CreateTupDesc4BuiltinFuncWithOid()
{
TupleDesc tupdesc = CreateTemplateTupleDesc(32, false);
TupleDesc tupdesc = CreateTemplateTupleDesc(31, false);
TupleDescInitEntry(tupdesc, (AttrNumber)1, "proname", NAMEOID, -1, 0);
TupleDescInitEntry(tupdesc, (AttrNumber)2, "pronamespace", OIDOID, -1, 0);
@ -2019,30 +2018,29 @@ TupleDesc CreateTupDesc4BuiltinFuncWithOid()
TupleDescInitEntry(tupdesc, (AttrNumber)6, "prorows", FLOAT4OID, -1, 0);
TupleDescInitEntry(tupdesc, (AttrNumber)7, "provariadic", OIDOID, -1, 0);
TupleDescInitEntry(tupdesc, (AttrNumber)8, "protransform", REGPROCOID, -1, 0);
TupleDescInitEntry(tupdesc, (AttrNumber)9, "proisagg", BOOLOID, -1, 0);
TupleDescInitEntry(tupdesc, (AttrNumber)10, "proiswindow", BOOLOID, -1, 0);
TupleDescInitEntry(tupdesc, (AttrNumber)11, "prosecdef", BOOLOID, -1, 0);
TupleDescInitEntry(tupdesc, (AttrNumber)12, "proleakproof", BOOLOID, -1, 0);
TupleDescInitEntry(tupdesc, (AttrNumber)13, "proisstrict", BOOLOID, -1, 0);
TupleDescInitEntry(tupdesc, (AttrNumber)14, "proretset", BOOLOID, -1, 0);
TupleDescInitEntry(tupdesc, (AttrNumber)15, "provolatile", CHAROID, -1, 0);
TupleDescInitEntry(tupdesc, (AttrNumber)16, "pronargs", INT2OID, -1, 0);
TupleDescInitEntry(tupdesc, (AttrNumber)17, "pronargdefaults", INT2OID, -1, 0);
TupleDescInitEntry(tupdesc, (AttrNumber)18, "prorettype", OIDOID, -1, 0);
TupleDescInitEntry(tupdesc, (AttrNumber)19, "proargtypes", OIDVECTOROID, -1, 0);
TupleDescInitEntry(tupdesc, (AttrNumber)20, "proallargtypes", INT4ARRAYOID, -1, 0);
TupleDescInitEntry(tupdesc, (AttrNumber)21, "proargmodes", CHARARRAYOID, -1, 0);
TupleDescInitEntry(tupdesc, (AttrNumber)22, "proargnames", TEXTARRAYOID, -1, 0);
TupleDescInitEntry(tupdesc, (AttrNumber)23, "proargdefaults", PGNODETREEOID, -1, 0);
TupleDescInitEntry(tupdesc, (AttrNumber)24, "prosrc", TEXTOID, -1, 0);
TupleDescInitEntry(tupdesc, (AttrNumber)25, "probin", TEXTOID, -1, 0);
TupleDescInitEntry(tupdesc, (AttrNumber)26, "proconfig", TEXTARRAYOID, -1, 0);
TupleDescInitEntry(tupdesc, (AttrNumber)27, "proacl", ACLITEMARRAYOID, -1, 0);
TupleDescInitEntry(tupdesc, (AttrNumber)28, "prodefaultargpos", INT2VECTOROID, -1, 0);
TupleDescInitEntry(tupdesc, (AttrNumber)29, "fencedmode", BOOLOID, -1, 0);
TupleDescInitEntry(tupdesc, (AttrNumber)30, "proshippable", BOOLOID, -1, 0);
TupleDescInitEntry(tupdesc, (AttrNumber)31, "propackage", BOOLOID, -1, 0);
TupleDescInitEntry(tupdesc, (AttrNumber)32, "oid", OIDOID, -1, 0);
TupleDescInitEntry(tupdesc, (AttrNumber)9, "prokind", CHAROID, -1, 0);
TupleDescInitEntry(tupdesc, (AttrNumber)10, "prosecdef", BOOLOID, -1, 0);
TupleDescInitEntry(tupdesc, (AttrNumber)11, "proleakproof", BOOLOID, -1, 0);
TupleDescInitEntry(tupdesc, (AttrNumber)12, "proisstrict", BOOLOID, -1, 0);
TupleDescInitEntry(tupdesc, (AttrNumber)13, "proretset", BOOLOID, -1, 0);
TupleDescInitEntry(tupdesc, (AttrNumber)14, "provolatile", CHAROID, -1, 0);
TupleDescInitEntry(tupdesc, (AttrNumber)15, "pronargs", INT2OID, -1, 0);
TupleDescInitEntry(tupdesc, (AttrNumber)16, "pronargdefaults", INT2OID, -1, 0);
TupleDescInitEntry(tupdesc, (AttrNumber)17, "prorettype", OIDOID, -1, 0);
TupleDescInitEntry(tupdesc, (AttrNumber)18, "proargtypes", OIDVECTOROID, -1, 0);
TupleDescInitEntry(tupdesc, (AttrNumber)19, "proallargtypes", INT4ARRAYOID, -1, 0);
TupleDescInitEntry(tupdesc, (AttrNumber)20, "proargmodes", CHARARRAYOID, -1, 0);
TupleDescInitEntry(tupdesc, (AttrNumber)21, "proargnames", TEXTARRAYOID, -1, 0);
TupleDescInitEntry(tupdesc, (AttrNumber)22, "proargdefaults", PGNODETREEOID, -1, 0);
TupleDescInitEntry(tupdesc, (AttrNumber)23, "prosrc", TEXTOID, -1, 0);
TupleDescInitEntry(tupdesc, (AttrNumber)24, "probin", TEXTOID, -1, 0);
TupleDescInitEntry(tupdesc, (AttrNumber)25, "proconfig", TEXTARRAYOID, -1, 0);
TupleDescInitEntry(tupdesc, (AttrNumber)26, "proacl", ACLITEMARRAYOID, -1, 0);
TupleDescInitEntry(tupdesc, (AttrNumber)27, "prodefaultargpos", INT2VECTOROID, -1, 0);
TupleDescInitEntry(tupdesc, (AttrNumber)28, "fencedmode", BOOLOID, -1, 0);
TupleDescInitEntry(tupdesc, (AttrNumber)29, "proshippable", BOOLOID, -1, 0);
TupleDescInitEntry(tupdesc, (AttrNumber)30, "propackage", BOOLOID, -1, 0);
TupleDescInitEntry(tupdesc, (AttrNumber)31, "oid", OIDOID, -1, 0);
return tupdesc;
}

View File

@ -1520,7 +1520,7 @@ Oid get_func_lang(Oid funcid)
/*
* get_func_iswindow
* Given procedure id, return the function's proiswindow field.
* Given procedure id, return the function is window or not.
*/
bool get_func_iswindow(Oid funcid)
{
@ -1530,7 +1530,7 @@ bool get_func_iswindow(Oid funcid)
if (!HeapTupleIsValid(tp)) {
ereport(ERROR, (errcode(ERRCODE_CACHE_LOOKUP_FAILED), errmsg("cache lookup failed for function %u", funcid)));
}
result = ((Form_pg_proc)GETSTRUCT(tp))->proiswindow;
result = PROC_IS_WIN(((Form_pg_proc)GETSTRUCT(tp))->prokind);
ReleaseSysCache(tp);
return result;
}
@ -4710,7 +4710,7 @@ bool is_not_strict_agg(Oid funcOid)
return false;
}
func_form = (Form_pg_proc)GETSTRUCT(func_tuple);
if (func_form->proisstrict == false && func_form->proisagg == false) {
if (func_form->proisstrict == false && !PROC_IS_AGG(func_form->prokind)) {
ReleaseSysCache(func_tuple);
return true;
}

View File

@ -6765,7 +6765,7 @@ static Datum pl_coerce_type_typmod(Datum value, Oid targetTypeId, int32 targetTy
* various binary-compatibility cases.
*/
nargs = procstruct->pronargs;
AssertEreport(!procstruct->proretset && !procstruct->proisagg && !procstruct->proiswindow,
AssertEreport(!procstruct->proretset && !PROC_IS_AGG(procstruct->prokind) && !PROC_IS_WIN(procstruct->prokind),
MOD_PLSQL,
"It should not be null.");
AssertEreport(nargs >= 1 && nargs <= 3, MOD_PLSQL, "Args num is out of range.");

View File

@ -90,7 +90,7 @@ void RemoveObjects(DropStmt* stmt, bool missing_ok, bool is_securityadmin)
ereport(ERROR,
(errcode(ERRCODE_CACHE_LOOKUP_FAILED), errmsg("cache lookup failed for function %u", funcOid)));
if (((Form_pg_proc)GETSTRUCT(tup))->proisagg)
if (PROC_IS_AGG(((Form_pg_proc)GETSTRUCT(tup))->prokind))
ereport(ERROR, (errcode(ERRCODE_WRONG_OBJECT_TYPE),
errmsg("\"%s\" is an aggregate function", NameListToString(objname)),
errhint("Use DROP AGGREGATE to drop aggregate functions.")));

View File

@ -1024,8 +1024,7 @@ void CreateFunction(CreateFunctionStmt* stmt, const char* queryString)
languageValidator,
prosrc_str, /* converted to text later */
probin_str, /* converted to text later */
false, /* not an aggregate */
isWindowFunc,
stmt->isProcedure ? PROKIND_PROCEDURE : (isWindowFunc ? PROKIND_WINDOW : PROKIND_FUNCTION),
security,
isLeakProof,
isStrict,
@ -1181,7 +1180,7 @@ void RemoveFunctionById(Oid funcOid)
ereport(ERROR, (errcode(ERRCODE_CACHE_LOOKUP_FAILED), errmsg("cache lookup failed for function %u", funcOid)));
Form_pg_proc procedureStruct = (Form_pg_proc)GETSTRUCT(tup);
isagg = procedureStruct->proisagg;
isagg = PROC_IS_AGG(procedureStruct->prokind);
if (procedureStruct->prolang == ClanguageId) {
PrepareCFunctionLibrary(tup);
@ -1245,7 +1244,7 @@ void RenameFunction(List* name, List* argtypes, const char* newname)
if (!HeapTupleIsValid(tup)) /* should not happen */
ereport(ERROR, (errcode(ERRCODE_CACHE_LOOKUP_FAILED), errmsg("cache lookup failed for function %u", procOid)));
procForm = (Form_pg_proc)GETSTRUCT(tup);
if (procForm->proisagg)
if (PROC_IS_AGG(procForm->prokind))
ereport(ERROR,
(errcode(ERRCODE_WRONG_OBJECT_TYPE),
errmsg("\"%s\" is an aggregate function", NameListToString(name)),
@ -1308,7 +1307,7 @@ void AlterFunctionOwner(List* name, List* argtypes, Oid newOwnerId)
tup = SearchSysCache1(PROCOID, ObjectIdGetDatum(procOid));
if (!HeapTupleIsValid(tup)) /* should not happen */
ereport(ERROR, (errcode(ERRCODE_CACHE_LOOKUP_FAILED), errmsg("cache lookup failed for function %u", procOid)));
if (((Form_pg_proc)GETSTRUCT(tup))->proisagg)
if (PROC_IS_AGG(((Form_pg_proc)GETSTRUCT(tup))->prokind))
ereport(ERROR,
(errcode(ERRCODE_WRONG_OBJECT_TYPE),
errmsg("\"%s\" is an aggregate function", NameListToString(name)),
@ -1507,7 +1506,7 @@ void AlterFunction(AlterFunctionStmt* stmt)
if (!pg_proc_ownercheck(funcOid, GetUserId()))
aclcheck_error(ACLCHECK_NOT_OWNER, ACL_KIND_PROC, NameListToString(stmt->func->funcname));
if (procForm->proisagg)
if (PROC_IS_AGG(procForm->prokind))
ereport(ERROR,
(errcode(ERRCODE_WRONG_OBJECT_TYPE),
errmsg("\"%s\" is an aggregate function", NameListToString(stmt->func->funcname))));
@ -1821,11 +1820,11 @@ void CreateCast(CreateCastStmt* stmt)
if (procstruct->provolatile == PROVOLATILE_VOLATILE)
ereport(ERROR, (errcode(ERRCODE_INVALID_OBJECT_DEFINITION), errmsg("cast function must not be volatile")));
#endif
if (procstruct->proisagg)
if (PROC_IS_AGG(procstruct->prokind))
ereport(ERROR,
(errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
errmsg("cast function must not be an aggregate function")));
if (procstruct->proiswindow)
if (PROC_IS_WIN(procstruct->prokind))
ereport(ERROR,
(errcode(ERRCODE_INVALID_OBJECT_DEFINITION), errmsg("cast function must not be a window function")));
if (procstruct->proretset)

View File

@ -130,8 +130,7 @@ void CreateProceduralLanguage(CreatePLangStmt* stmt)
F_FMGR_C_VALIDATOR,
pltemplate->tmplhandler,
pltemplate->tmpllibrary,
false, /* isAgg */
false, /* isWindowFunc */
PROKIND_FUNCTION, /* prokind */
false, /* security_definer */
false, /* isLeakProof */
false, /* isStrict */
@ -174,8 +173,7 @@ void CreateProceduralLanguage(CreatePLangStmt* stmt)
F_FMGR_C_VALIDATOR,
pltemplate->tmplinline,
pltemplate->tmpllibrary,
false, /* isAgg */
false, /* isWindowFunc */
PROKIND_FUNCTION, /* prokind */
false, /* security_definer */
false, /* isLeakProof */
true, /* isStrict */
@ -220,8 +218,7 @@ void CreateProceduralLanguage(CreatePLangStmt* stmt)
F_FMGR_C_VALIDATOR,
pltemplate->tmplvalidator,
pltemplate->tmpllibrary,
false, /* isAgg */
false, /* isWindowFunc */
PROKIND_FUNCTION, /* prokind */
false, /* security_definer */
false, /* isLeakProof */
true, /* isStrict */

View File

@ -2579,7 +2579,7 @@ ObjectAddresses* PreCheckforRemoveObjects(
(errcode(ERRCODE_CACHE_LOOKUP_FAILED), errmsg("cache lookup failed for function %u", funcOid)));
}
if (((Form_pg_proc)GETSTRUCT(tup))->proisagg)
if (PROC_IS_AGG(((Form_pg_proc)GETSTRUCT(tup))->prokind))
ereport(ERROR,
(errcode(ERRCODE_WRONG_OBJECT_TYPE),
errmsg("\"%s\" is an aggregate function", NameListToString(objname)),

View File

@ -1480,8 +1480,7 @@ static void makeRangeConstructors(const char* name, Oid nmspace, Oid rangeOid, O
F_FMGR_INTERNAL_VALIDATOR, /* language validator */
prosrc[i], /* prosrc */
NULL, /* probin */
false, /* isAgg */
false, /* isWindowFunc */
PROKIND_FUNCTION, /* prokind */
false, /* security_definer */
false, /* leakproof */
false, /* isStrict */

View File

@ -156,7 +156,7 @@ DATA(insert OID = 1247 ( pg_type PGNSP 71 0 PGUID 0 0 0 0 0 0 0 0 0 0 0 0
DESCR("");
DATA(insert OID = 1249 ( pg_attribute PGNSP 75 0 PGUID 0 0 0 0 0 0 0 0 0 0 0 0 f f p r 24 0 f f f f f 0 f f n 3 _null_ _null_ n 3 _null_ _null_));
DESCR("");
DATA(insert OID = 1255 ( pg_proc PGNSP 81 0 PGUID 0 0 0 0 0 0 0 0 0 0 0 0 f f p r 31 0 t f f f f 0 f f n 3 _null_ _null_ n 3 _null_ _null_));
DATA(insert OID = 1255 ( pg_proc PGNSP 81 0 PGUID 0 0 0 0 0 0 0 0 0 0 0 0 f f p r 30 0 t f f f f 0 f f n 3 _null_ _null_ n 3 _null_ _null_));
DESCR("");
DATA(insert OID = 1259 ( pg_class PGNSP 83 0 PGUID 0 0 0 0 0 0 0 0 0 0 0 0 f f p r 39 0 t f f f f 0 f f n 3 _null_ _null_ n 3 _null_ _null_));
DESCR("");

View File

@ -47,8 +47,7 @@ CATALOG(pg_proc,1255) BKI_BOOTSTRAP BKI_ROWTYPE_OID(81) BKI_SCHEMA_MACRO
float4 prorows; /* estimated # of rows out (if proretset) */
Oid provariadic; /* element type of variadic array, or 0 */
regproc protransform; /* transforms calls to it during planning */
bool proisagg; /* is it an aggregate? */
bool proiswindow; /* is it a window function? */
char prokind; /* see PROKIND_ categories below */
bool prosecdef; /* security definer */
bool proleakproof; /* is it a leak-proof function? */
bool proisstrict; /* strict with respect to NULLs? */
@ -92,7 +91,7 @@ typedef FormData_pg_proc *Form_pg_proc;
* compiler constants for pg_proc
* ----------------
*/
#define Natts_pg_proc 31
#define Natts_pg_proc 30
#define Anum_pg_proc_proname 1
#define Anum_pg_proc_pronamespace 2
#define Anum_pg_proc_proowner 3
@ -101,34 +100,33 @@ typedef FormData_pg_proc *Form_pg_proc;
#define Anum_pg_proc_prorows 6
#define Anum_pg_proc_provariadic 7
#define Anum_pg_proc_protransform 8
#define Anum_pg_proc_proisagg 9
#define Anum_pg_proc_proiswindow 10
#define Anum_pg_proc_prosecdef 11
#define Anum_pg_proc_proleakproof 12
#define Anum_pg_proc_proisstrict 13
#define Anum_pg_proc_proretset 14
#define Anum_pg_proc_provolatile 15
#define Anum_pg_proc_pronargs 16
#define Anum_pg_proc_pronargdefaults 17
#define Anum_pg_proc_prorettype 18
#define Anum_pg_proc_proargtypes 19
#define Anum_pg_proc_proallargtypes 20
#define Anum_pg_proc_proargmodes 21
#define Anum_pg_proc_proargnames 22
#define Anum_pg_proc_proargdefaults 23
#define Anum_pg_proc_prosrc 24
#define Anum_pg_proc_probin 25
#define Anum_pg_proc_proconfig 26
#define Anum_pg_proc_proacl 27
#define Anum_pg_proc_prodefaultargpos 28
#define Anum_pg_proc_fenced 29
#define Anum_pg_proc_shippable 30
#define Anum_pg_proc_package 31
#define Anum_pg_proc_prokind 9
#define Anum_pg_proc_prosecdef 10
#define Anum_pg_proc_proleakproof 11
#define Anum_pg_proc_proisstrict 12
#define Anum_pg_proc_proretset 13
#define Anum_pg_proc_provolatile 14
#define Anum_pg_proc_pronargs 15
#define Anum_pg_proc_pronargdefaults 16
#define Anum_pg_proc_prorettype 17
#define Anum_pg_proc_proargtypes 18
#define Anum_pg_proc_proallargtypes 19
#define Anum_pg_proc_proargmodes 20
#define Anum_pg_proc_proargnames 21
#define Anum_pg_proc_proargdefaults 22
#define Anum_pg_proc_prosrc 23
#define Anum_pg_proc_probin 24
#define Anum_pg_proc_proconfig 25
#define Anum_pg_proc_proacl 26
#define Anum_pg_proc_prodefaultargpos 27
#define Anum_pg_proc_fenced 28
#define Anum_pg_proc_shippable 29
#define Anum_pg_proc_package 30
/* proc_oid is only for builitin
* func view shouldn't be included in Natts_pg_proc
*/
#define Anum_pg_proc_oid 32
#define Anum_pg_proc_oid 31
/* ----------------
* initial contents of pg_proc
@ -389,6 +387,20 @@ typedef FormData_pg_proc *Form_pg_proc;
#define TESTSKEWNESSRETURNTYPE 4048
#define PERCENTILECONTAGGFUNCOID 4452
#define PGCHECKAUTHIDFUNCOID 3228
/*
* Symbolic values for prokind column
*/
#define PROKIND_FUNCTION 'f'
#define PROKIND_AGGREGATE 'a'
#define PROKIND_WINDOW 'w'
#define PROKIND_PROCEDURE 'p'
#define PROC_IS_FUNC(prokind) ((prokind) == PROKIND_FUNCTION)
#define PROC_IS_AGG(prokind) ((prokind) == PROKIND_AGGREGATE)
#define PROC_IS_WIN(prokind) ((prokind) == PROKIND_WINDOW)
#define PROC_IS_PRO(prokind) ((prokind) == PROKIND_PROCEDURE)
/*
* Symbolic values for provolatile column: these indicate whether the result
* of a function is dependent *only* on the values of its explicit arguments,

View File

@ -27,8 +27,7 @@ extern Oid ProcedureCreate(const char *procedureName,
Oid languageValidator,
const char *prosrc,
const char *probin,
bool isAgg,
bool isWindowFunc,
char prokind,
bool security_definer,
bool isLeakProof,
bool isStrict,

View File

@ -54,31 +54,30 @@ typedef struct {
float4 prorows; /* [11] estimated # of rows out (if proretset) */
Oid provariadic; /* [12] element type of variadic array, or 0 */
regproc protransform; /* [13] transforms calls to it during planning */
bool proisagg; /* [14] is it an aggregate? */
bool proiswindow; /* [15] is it a window function? */
bool prosecdef; /* [16] security definer */
bool proleakproof; /* [17] is it a leak-proof function? */
char provolatile; /* [18] see PROVOLATILE_ categories below */
int2 pronargdefaults; /* [19] number of arguments with defaults */
char prokind; /* [14] */
bool prosecdef; /* [15] security definer */
bool proleakproof; /* [16] is it a leak-proof function? */
char provolatile; /* [17] see PROVOLATILE_ categories below */
int2 pronargdefaults; /* [18] number of arguments with defaults */
/* variable-length fields start here */
ArrayOid proargtypes; /* [20] parameter types (excludes OUT params) */
ArrayOid proargtypes; /* [19] parameter types (excludes OUT params) */
/* nullable fields start here, they are defined by pointer, if one of them
* is null pointer, it means it has SQL NULL value */
ArrayOid* proallargtypes; /* [21] all param types (NULL if IN only) */
ArrayChar* proargmodes; /* [22] parameter modes (NULL if IN only) */
ArrayCStr* proargnames; /* [23] parameter names (NULL if no names) */
const char* proargdefaults; /* [24] list of expression trees for argument defaults (NULL if none) */
const char* prosrc; /* [25] procedure source text */
const char* probin; /* [26] secondary procedure info (can be NULL) */
ArrayCStr* proconfig; /* [27] procedure-local GUC settings */
ArrayAcl* proacl; /* [28] access permissions */
ArrayInt2* prodefaultargpos; /* [29] */
bool* fencedmode; /* [30] */
bool* proshippable; /* [31] if provolatile is not 'i', proshippable will determine if the func can be shipped */
bool* propackage; /* [32] */
const char* descr; /* [33] description */
ArrayOid* proallargtypes; /* [20] all param types (NULL if IN only) */
ArrayChar* proargmodes; /* [21] parameter modes (NULL if IN only) */
ArrayCStr* proargnames; /* [22] parameter names (NULL if no names) */
const char* proargdefaults; /* [23] list of expression trees for argument defaults (NULL if none) */
const char* prosrc; /* [24] procedure source text */
const char* probin; /* [25] secondary procedure info (can be NULL) */
ArrayCStr* proconfig; /* [26] procedure-local GUC settings */
ArrayAcl* proacl; /* [27] access permissions */
ArrayInt2* prodefaultargpos; /* [28] */
bool* fencedmode; /* [29] */
bool* proshippable; /* [30] if provolatile is not 'i', proshippable will determine if the func can be shipped */
bool* propackage; /* [31] */
const char* descr; /* [32] description */
} Builtin_func;
/* The function has the same names are put in one group */
@ -114,20 +113,19 @@ static_assert(sizeof(NULL) == sizeof(void*), "NULL must be a 8 byte-length point
#define _11(rows) _SetField(prorows, rows)
#define _12(vari_oid) _SetField(provariadic, vari_oid)
#define _13(tansf_oid) _SetField(protransform, tansf_oid)
#define _14(is_agg) _SetField(proisagg, is_agg)
#define _15(is_window) _SetField(proiswindow, is_window)
#define _16(is_secdef) _SetField(prosecdef, is_secdef)
#define _17(is_leakproof) _SetField(proleakproof, is_leakproof)
#define _14(pro_kind) _SetField(prokind, pro_kind)
#define _15(is_secdef) _SetField(prosecdef, is_secdef)
#define _16(is_leakproof) _SetField(proleakproof, is_leakproof)
/* the set provolatile field, 'i', 's', 'v' */
#define _18(volt_type) _SetField(provolatile, volt_type)
#define _17(volt_type) _SetField(provolatile, volt_type)
#define _19(nargdefaults) _SetField(pronargdefaults, nargdefaults)
#define _18(nargdefaults) _SetField(pronargdefaults, nargdefaults)
/* Set the value for proargtypes, which is an array, The argument cnt of the Macro
* means the number of elements that are used to initialize the array,
* e.g., _20(3, oid1, oid2, oid3), means the array field hash 3 elements oid1, oid2, and oid3 */
#define _20(cnt, ...) _SetField(proargtypes, MakeArrayOid(cnt, __VA_ARGS__))
#define _19(cnt, ...) _SetField(proargtypes, MakeArrayOid(cnt, __VA_ARGS__))
/* The following Macros are used for initializing nullable fields.
* For an array field, its initializer is like _xx(ind_cnt, ...), e.g., _21, _22,
@ -141,30 +139,30 @@ static_assert(sizeof(NULL) == sizeof(void*), "NULL must be a 8 byte-length point
* _xx(fvalue): means the field has the value *fvalue*
* */
/* Set the proallargtypes field. The input must be an array of Oids, e.g., _21(4, oid1, oid2, oid3, oid4) */
#define _21(ind_cnt, ...) _SetPointerField(proallargtypes, ind_cnt, MakeArrayOidPtr(GET_ARGNUMS(ind_cnt), __VA_ARGS__))
#define _20(ind_cnt, ...) _SetPointerField(proallargtypes, ind_cnt, MakeArrayOidPtr(GET_ARGNUMS(ind_cnt), __VA_ARGS__))
/* Set the proargmodes field, The input must be an array of chars: 'i', 'o', 'b', 'v', 't'
* the usage is: _22(3, 'i', 'b', 'o') */
#define _22(ind_cnt, ...) _SetPointerField(proargmodes, ind_cnt, MakeArrayCharPtr(GET_ARGNUMS(ind_cnt), __VA_ARGS__))
#define _21(ind_cnt, ...) _SetPointerField(proargmodes, ind_cnt, MakeArrayCharPtr(GET_ARGNUMS(ind_cnt), __VA_ARGS__))
/* The input must be an array of c-string, e.g., _23(3, "argname1", "argname2", "argname3") */
#define _23(ind_cnt, ...) _SetPointerField(proargnames, ind_cnt, MakeArrayCStrPtr(GET_ARGNUMS(ind_cnt), __VA_ARGS__))
#define _22(ind_cnt, ...) _SetPointerField(proargnames, ind_cnt, MakeArrayCStrPtr(GET_ARGNUMS(ind_cnt), __VA_ARGS__))
#define _24(arg_default_expr_str) _SetField(proargdefaults, arg_default_expr_str)
#define _25(proc_src) _SetField(prosrc, proc_src)
#define _26(bin_info) _SetField(probin, bin_info)
#define _23(arg_default_expr_str) _SetField(proargdefaults, arg_default_expr_str)
#define _24(proc_src) _SetField(prosrc, proc_src)
#define _25(bin_info) _SetField(probin, bin_info)
#define _27(ind_cnt, ...) _SetPointerField(proconfig, ind_cnt, MakeArrayCStrPtr(GET_ARGNUMS(ind_cnt), __VA_ARGS__))
#define _28(ind_cnt, ...) _SetPointerField(proacl, ind_cnt, MakeArrayInt4Ptr(GET_ARGNUMS(ind_cnt), __VA_ARGS__))
#define _29(ind_cnt, ...) \
#define _26(ind_cnt, ...) _SetPointerField(proconfig, ind_cnt, MakeArrayCStrPtr(GET_ARGNUMS(ind_cnt), __VA_ARGS__))
#define _27(ind_cnt, ...) _SetPointerField(proacl, ind_cnt, MakeArrayInt4Ptr(GET_ARGNUMS(ind_cnt), __VA_ARGS__))
#define _28(ind_cnt, ...) \
_SetPointerField(prodefaultargpos, ind_cnt, MakeArrayInt2Ptr(GET_ARGNUMS(ind_cnt), __VA_ARGS__))
/* .fencedmode = ((ind_fmode) == NVL ? NULL : (bool[1]) { ind_fmode }) */
#define _30(ind_fmode) _SetPointerField(fencedmode, ind_fmode, MakeSingleValuePtr(bool, ind_fmode))
#define _31(ind_shippable) _SetPointerField(proshippable, ind_shippable, MakeSingleValuePtr(bool, ind_shippable))
#define _32(ind_is_pkg) _SetPointerField(propackage, ind_is_pkg, MakeSingleValuePtr(bool, ind_is_pkg))
#define _29(ind_fmode) _SetPointerField(fencedmode, ind_fmode, MakeSingleValuePtr(bool, ind_fmode))
#define _30(ind_shippable) _SetPointerField(proshippable, ind_shippable, MakeSingleValuePtr(bool, ind_shippable))
#define _31(ind_is_pkg) _SetPointerField(propackage, ind_is_pkg, MakeSingleValuePtr(bool, ind_is_pkg))
#define _33(desc_str) _SetField(descr, desc_str)
#define _32(desc_str) _SetField(descr, desc_str)
/* Use Marcos _index() to initialize a built-in function, the indices between 0 ~ 20 are necessary,
* and indices between 21 ~ 32 are optional */
#define AddBuiltinFunc(...) \

View File

@ -28,6 +28,13 @@ BEGIN
return iter;
END;
$$ LANGUAGE plpgsql;
-- check prokind
select prokind from pg_proc where proname = 'test_forall';
prokind
---------
f
(1 row)
CREATE FUNCTION test_forallDML1(IN iter int) RETURNS integer AS $$
BEGIN
forall i in 1..iter
@ -83,6 +90,13 @@ BEGIN
-- raise info 'SQLCODE IS %', PSV_SQLCODE;
END ;
/
-- check prokind
select prokind from pg_proc where proname = 'pro_sqlcode';
prokind
---------
p
(1 row)
CREATE FUNCTION test_forallDML5(IN iter int) RETURNS integer AS $$
BEGIN
forall i in 1..iter;

View File

@ -262,6 +262,31 @@ WHERE d.classoid IS NULL AND p1.oid <= 9999;
-----+---------
(0 rows)
-- Check prokind
select count(*) from pg_proc where prokind = 'a';
count
-------
153
(1 row)
select count(*) from pg_proc where prokind = 'w';
count
-------
16
(1 row)
select count(*) from pg_proc where prokind = 'f';
count
-------
3266
(1 row)
select count(*) from pg_proc where prokind = 'p';
count
-------
11
(1 row)
-- Check that operators' underlying functions have suitable comments,
-- namely 'implementation of XXX operator'. In some cases involving legacy
-- names for operators, there are multiple operators referencing the same
@ -297,15 +322,15 @@ WHERE aggfnoid = 0 OR aggtransfn = 0 OR aggtranstype = 0;
SELECT a.aggfnoid::oid, p.proname
FROM pg_aggregate as a, pg_proc as p
WHERE a.aggfnoid = p.oid AND
(NOT p.proisagg OR p.proretset);
(p.prokind != 'a' OR p.proretset);
aggfnoid | proname
----------+---------
(0 rows)
-- Make sure there are no proisagg pg_proc entries without matches.
-- Make sure there are no prokind = 'a' pg_proc entries without matches.
SELECT oid, proname
FROM pg_proc as p
WHERE p.proisagg AND
WHERE p.prokind = 'a' AND
NOT EXISTS (SELECT 1 FROM pg_aggregate a WHERE a.aggfnoid = p.oid);
oid | proname
-----+---------
@ -442,7 +467,7 @@ ORDER BY 1, 2;
SELECT p1.oid::regprocedure, p2.oid::regprocedure
FROM pg_proc AS p1, pg_proc AS p2
WHERE p1.oid < p2.oid AND p1.proname = p2.proname AND
p1.proisagg AND p2.proisagg AND
p1.prokind = 'a' AND p2.prokind = 'a' AND
array_dims(p1.proargtypes) != array_dims(p2.proargtypes) AND
p1.proname != 'listagg'
ORDER BY 1;
@ -454,7 +479,7 @@ ORDER BY 1;
-- For the same reason, aggregates with default arguments are no good.
SELECT oid, proname
FROM pg_proc AS p
WHERE proisagg AND proargdefaults IS NOT NULL;
WHERE prokind = 'a' AND proargdefaults IS NOT NULL;
oid | proname
-----+---------
(0 rows)

View File

@ -89,10 +89,10 @@ ORDER by 1, 2;
-----+---------
(0 rows)
-- proiswindow shouldn't be set together with proisagg or proretset
-- prokind = 'w' shouldn't be set together with proretset
SELECT p1.oid, p1.proname
FROM pg_proc AS p1
WHERE proiswindow AND (proisagg OR proretset)
WHERE prokind = 'w' AND proretset
ORDER by 1, 2;
oid | proname
-----+---------
@ -160,9 +160,9 @@ FROM pg_proc AS p1, pg_proc AS p2
WHERE p1.oid < p2.oid AND
p1.prosrc = p2.prosrc AND
p1.prolang = 12 AND p2.prolang = 12 AND
(p1.proisagg = false OR p2.proisagg = false) AND
(p1.prokind != 'a' OR p2.prokind != 'a') AND
(p1.prolang != p2.prolang OR
p1.proisagg != p2.proisagg OR
(p1.prokind = 'a') != (p2.prokind = 'a') OR
p1.prosecdef != p2.prosecdef OR
p1.proisstrict != p2.proisstrict OR
p1.proretset != p2.proretset OR
@ -189,7 +189,7 @@ FROM pg_proc AS p1, pg_proc AS p2
WHERE p1.oid != p2.oid AND
p1.prosrc = p2.prosrc AND
p1.prolang = 12 AND p2.prolang = 12 AND
NOT p1.proisagg AND NOT p2.proisagg AND
p1.prokind != 'a' AND p2.prokind != 'a' AND
p1.prosrc NOT LIKE E'range\\_constructor_' AND
p2.prosrc NOT LIKE E'range\\_constructor_' AND
(p1.prorettype < p2.prorettype)
@ -206,7 +206,7 @@ FROM pg_proc AS p1, pg_proc AS p2
WHERE p1.oid != p2.oid AND
p1.prosrc = p2.prosrc AND
p1.prolang = 12 AND p2.prolang = 12 AND
NOT p1.proisagg AND NOT p2.proisagg AND
p1.prokind != 'a' AND p2.prokind != 'a' AND
p1.prosrc NOT LIKE E'range\\_constructor_' AND
p2.prosrc NOT LIKE E'range\\_constructor_' AND
(p1.proargtypes[0] < p2.proargtypes[0])
@ -226,7 +226,7 @@ FROM pg_proc AS p1, pg_proc AS p2
WHERE p1.oid != p2.oid AND
p1.prosrc = p2.prosrc AND
p1.prolang = 12 AND p2.prolang = 12 AND
NOT p1.proisagg AND NOT p2.proisagg AND
p1.prokind != 'a' AND p2.prokind != 'a' AND
p1.prosrc NOT LIKE E'range\\_constructor_' AND
p2.prosrc NOT LIKE E'range\\_constructor_' AND
(p1.proargtypes[1] < p2.proargtypes[1])
@ -245,7 +245,7 @@ FROM pg_proc AS p1, pg_proc AS p2
WHERE p1.oid != p2.oid AND
p1.prosrc = p2.prosrc AND
p1.prolang = 12 AND p2.prolang = 12 AND
NOT p1.proisagg AND NOT p2.proisagg AND
p1.prokind != 'a' AND p2.prokind != 'a' AND
(p1.proargtypes[2] < p2.proargtypes[2])
ORDER BY 1, 2;
proargtypes | proargtypes
@ -258,7 +258,7 @@ FROM pg_proc AS p1, pg_proc AS p2
WHERE p1.oid != p2.oid AND
p1.prosrc = p2.prosrc AND
p1.prolang = 12 AND p2.prolang = 12 AND
NOT p1.proisagg AND NOT p2.proisagg AND
p1.prokind != 'a' AND p2.prokind != 'a' AND
(p1.proargtypes[3] < p2.proargtypes[3])
ORDER BY 1, 2;
proargtypes | proargtypes
@ -271,7 +271,7 @@ FROM pg_proc AS p1, pg_proc AS p2
WHERE p1.oid != p2.oid AND
p1.prosrc = p2.prosrc AND
p1.prolang = 12 AND p2.prolang = 12 AND
NOT p1.proisagg AND NOT p2.proisagg AND
p1.prokind != 'a' AND p2.prokind != 'a' AND
(p1.proargtypes[4] < p2.proargtypes[4])
ORDER BY 1, 2;
proargtypes | proargtypes
@ -283,7 +283,7 @@ FROM pg_proc AS p1, pg_proc AS p2
WHERE p1.oid != p2.oid AND
p1.prosrc = p2.prosrc AND
p1.prolang = 12 AND p2.prolang = 12 AND
NOT p1.proisagg AND NOT p2.proisagg AND
p1.prokind != 'a' AND p2.prokind != 'a' AND
(p1.proargtypes[5] < p2.proargtypes[5])
ORDER BY 1, 2;
proargtypes | proargtypes
@ -295,7 +295,7 @@ FROM pg_proc AS p1, pg_proc AS p2
WHERE p1.oid != p2.oid AND
p1.prosrc = p2.prosrc AND
p1.prolang = 12 AND p2.prolang = 12 AND
NOT p1.proisagg AND NOT p2.proisagg AND
p1.prokind != 'a' AND p2.prokind != 'a' AND
(p1.proargtypes[6] < p2.proargtypes[6])
ORDER BY 1, 2;
proargtypes | proargtypes
@ -307,7 +307,7 @@ FROM pg_proc AS p1, pg_proc AS p2
WHERE p1.oid != p2.oid AND
p1.prosrc = p2.prosrc AND
p1.prolang = 12 AND p2.prolang = 12 AND
NOT p1.proisagg AND NOT p2.proisagg AND
p1.prokind != 'a' AND p2.prokind != 'a' AND
(p1.proargtypes[7] < p2.proargtypes[7])
ORDER BY 1, 2;
proargtypes | proargtypes
@ -2673,6 +2673,31 @@ WHERE d.classoid IS NULL AND p1.oid <= 9999 order by 1;
9999 | pg_test_err_contain_err
(2270 rows)
-- Check prokind
select count(*) from pg_proc where prokind = 'a';
count
-------
153
(1 row)
select count(*) from pg_proc where prokind = 'w';
count
-------
15
(1 row)
select count(*) from pg_proc where prokind = 'f';
count
-------
3130
(1 row)
select count(*) from pg_proc where prokind = 'p';
count
-------
0
(1 row)
-- **************** pg_cast ****************
-- Catch bogus values in pg_cast columns (other than cases detected by
-- oidjoins test).
@ -3043,16 +3068,16 @@ ORDER by 1, 2;
SELECT a.aggfnoid::oid, p.proname
FROM pg_aggregate as a, pg_proc as p
WHERE a.aggfnoid = p.oid AND
(NOT p.proisagg OR p.proretset)
(p.prokind != 'a' OR p.proretset)
ORDER by 1, 2;
aggfnoid | proname
----------+---------
(0 rows)
-- Make sure there are no proisagg pg_proc entries without matches.
-- Make sure there are no prokind = 'a' pg_proc entries without matches.
SELECT oid, proname
FROM pg_proc as p
WHERE p.proisagg AND
WHERE p.prokind = 'a' AND
NOT EXISTS (SELECT 1 FROM pg_aggregate a WHERE a.aggfnoid = p.oid)
ORDER by 1, 2;
oid | proname
@ -3196,7 +3221,7 @@ ORDER BY 1, 2;
SELECT p1.oid::regprocedure, p2.oid::regprocedure
FROM pg_proc AS p1, pg_proc AS p2
WHERE p1.oid < p2.oid AND p1.proname = p2.proname AND
p1.proisagg AND p2.proisagg AND
p1.prokind = 'a' AND p2.prokind = 'a' AND
array_dims(p1.proargtypes) != array_dims(p2.proargtypes) AND
p1.proname != 'listagg'
ORDER BY 1;
@ -3208,7 +3233,7 @@ ORDER BY 1;
-- For the same reason, aggregates with default arguments are no good.
SELECT oid, proname
FROM pg_proc AS p
WHERE proisagg AND proargdefaults IS NOT NULL
WHERE prokind = 'a' AND proargdefaults IS NOT NULL
ORDER by 1, 2;
oid | proname
-----+---------

View File

@ -30,6 +30,9 @@ BEGIN
END;
$$ LANGUAGE plpgsql;
-- check prokind
select prokind from pg_proc where proname = 'test_forall';
CREATE FUNCTION test_forallDML1(IN iter int) RETURNS integer AS $$
BEGIN
forall i in 1..iter
@ -78,6 +81,9 @@ BEGIN
END ;
/
-- check prokind
select prokind from pg_proc where proname = 'pro_sqlcode';
CREATE FUNCTION test_forallDML5(IN iter int) RETURNS integer AS $$
BEGIN
forall i in 1..iter;

View File

@ -227,6 +227,12 @@ FROM pg_operator as p1 LEFT JOIN pg_description as d
ON p1.tableoid = d.classoid and p1.oid = d.objoid and d.objsubid = 0
WHERE d.classoid IS NULL AND p1.oid <= 9999;
-- Check prokind
select count(*) from pg_proc where prokind = 'a';
select count(*) from pg_proc where prokind = 'w';
select count(*) from pg_proc where prokind = 'f';
select count(*) from pg_proc where prokind = 'p';
-- Check that operators' underlying functions have suitable comments,
-- namely 'implementation of XXX operator'. In some cases involving legacy
-- names for operators, there are multiple operators referencing the same
@ -260,13 +266,13 @@ WHERE aggfnoid = 0 OR aggtransfn = 0 OR aggtranstype = 0;
SELECT a.aggfnoid::oid, p.proname
FROM pg_aggregate as a, pg_proc as p
WHERE a.aggfnoid = p.oid AND
(NOT p.proisagg OR p.proretset);
(p.prokind != 'a' OR p.proretset);
-- Make sure there are no proisagg pg_proc entries without matches.
-- Make sure there are no prokind = 'a' pg_proc entries without matches.
SELECT oid, proname
FROM pg_proc as p
WHERE p.proisagg AND
WHERE p.prokind = 'a' AND
NOT EXISTS (SELECT 1 FROM pg_aggregate a WHERE a.aggfnoid = p.oid);
-- If there is no finalfn then the output type must be the transtype.
@ -374,7 +380,7 @@ ORDER BY 1, 2;
SELECT p1.oid::regprocedure, p2.oid::regprocedure
FROM pg_proc AS p1, pg_proc AS p2
WHERE p1.oid < p2.oid AND p1.proname = p2.proname AND
p1.proisagg AND p2.proisagg AND
p1.prokind = 'a' AND p2.prokind = 'a' AND
array_dims(p1.proargtypes) != array_dims(p2.proargtypes) AND
p1.proname != 'listagg'
ORDER BY 1;
@ -383,4 +389,4 @@ ORDER BY 1;
SELECT oid, proname
FROM pg_proc AS p
WHERE proisagg AND proargdefaults IS NOT NULL;
WHERE prokind = 'a' AND proargdefaults IS NOT NULL;

View File

@ -88,10 +88,10 @@ FROM pg_proc as p1
WHERE prosrc IS NULL OR prosrc = '' OR prosrc = '-'
ORDER by 1, 2;
-- proiswindow shouldn't be set together with proisagg or proretset
-- prokind = 'w' shouldn't be set together with proretset
SELECT p1.oid, p1.proname
FROM pg_proc AS p1
WHERE proiswindow AND (proisagg OR proretset)
WHERE prokind = 'w' AND proretset
ORDER by 1, 2;
-- pronargdefaults should be 0 iff proargdefaults is null
@ -136,9 +136,9 @@ FROM pg_proc AS p1, pg_proc AS p2
WHERE p1.oid < p2.oid AND
p1.prosrc = p2.prosrc AND
p1.prolang = 12 AND p2.prolang = 12 AND
(p1.proisagg = false OR p2.proisagg = false) AND
(p1.prokind != 'a' OR p2.prokind != 'a') AND
(p1.prolang != p2.prolang OR
p1.proisagg != p2.proisagg OR
(p1.prokind = 'a') != (p2.prokind = 'a') OR
p1.prosecdef != p2.prosecdef OR
p1.proisstrict != p2.proisstrict OR
p1.proretset != p2.proretset OR
@ -162,7 +162,7 @@ FROM pg_proc AS p1, pg_proc AS p2
WHERE p1.oid != p2.oid AND
p1.prosrc = p2.prosrc AND
p1.prolang = 12 AND p2.prolang = 12 AND
NOT p1.proisagg AND NOT p2.proisagg AND
p1.prokind != 'a' AND p2.prokind != 'a' AND
p1.prosrc NOT LIKE E'range\\_constructor_' AND
p2.prosrc NOT LIKE E'range\\_constructor_' AND
(p1.prorettype < p2.prorettype)
@ -173,7 +173,7 @@ FROM pg_proc AS p1, pg_proc AS p2
WHERE p1.oid != p2.oid AND
p1.prosrc = p2.prosrc AND
p1.prolang = 12 AND p2.prolang = 12 AND
NOT p1.proisagg AND NOT p2.proisagg AND
p1.prokind != 'a' AND p2.prokind != 'a' AND
p1.prosrc NOT LIKE E'range\\_constructor_' AND
p2.prosrc NOT LIKE E'range\\_constructor_' AND
(p1.proargtypes[0] < p2.proargtypes[0])
@ -184,7 +184,7 @@ FROM pg_proc AS p1, pg_proc AS p2
WHERE p1.oid != p2.oid AND
p1.prosrc = p2.prosrc AND
p1.prolang = 12 AND p2.prolang = 12 AND
NOT p1.proisagg AND NOT p2.proisagg AND
p1.prokind != 'a' AND p2.prokind != 'a' AND
p1.prosrc NOT LIKE E'range\\_constructor_' AND
p2.prosrc NOT LIKE E'range\\_constructor_' AND
(p1.proargtypes[1] < p2.proargtypes[1])
@ -195,7 +195,7 @@ FROM pg_proc AS p1, pg_proc AS p2
WHERE p1.oid != p2.oid AND
p1.prosrc = p2.prosrc AND
p1.prolang = 12 AND p2.prolang = 12 AND
NOT p1.proisagg AND NOT p2.proisagg AND
p1.prokind != 'a' AND p2.prokind != 'a' AND
(p1.proargtypes[2] < p2.proargtypes[2])
ORDER BY 1, 2;
@ -204,7 +204,7 @@ FROM pg_proc AS p1, pg_proc AS p2
WHERE p1.oid != p2.oid AND
p1.prosrc = p2.prosrc AND
p1.prolang = 12 AND p2.prolang = 12 AND
NOT p1.proisagg AND NOT p2.proisagg AND
p1.prokind != 'a' AND p2.prokind != 'a' AND
(p1.proargtypes[3] < p2.proargtypes[3])
ORDER BY 1, 2;
@ -213,7 +213,7 @@ FROM pg_proc AS p1, pg_proc AS p2
WHERE p1.oid != p2.oid AND
p1.prosrc = p2.prosrc AND
p1.prolang = 12 AND p2.prolang = 12 AND
NOT p1.proisagg AND NOT p2.proisagg AND
p1.prokind != 'a' AND p2.prokind != 'a' AND
(p1.proargtypes[4] < p2.proargtypes[4])
ORDER BY 1, 2;
@ -222,7 +222,7 @@ FROM pg_proc AS p1, pg_proc AS p2
WHERE p1.oid != p2.oid AND
p1.prosrc = p2.prosrc AND
p1.prolang = 12 AND p2.prolang = 12 AND
NOT p1.proisagg AND NOT p2.proisagg AND
p1.prokind != 'a' AND p2.prokind != 'a' AND
(p1.proargtypes[5] < p2.proargtypes[5])
ORDER BY 1, 2;
@ -231,7 +231,7 @@ FROM pg_proc AS p1, pg_proc AS p2
WHERE p1.oid != p2.oid AND
p1.prosrc = p2.prosrc AND
p1.prolang = 12 AND p2.prolang = 12 AND
NOT p1.proisagg AND NOT p2.proisagg AND
p1.prokind != 'a' AND p2.prokind != 'a' AND
(p1.proargtypes[6] < p2.proargtypes[6])
ORDER BY 1, 2;
@ -240,7 +240,7 @@ FROM pg_proc AS p1, pg_proc AS p2
WHERE p1.oid != p2.oid AND
p1.prosrc = p2.prosrc AND
p1.prolang = 12 AND p2.prolang = 12 AND
NOT p1.proisagg AND NOT p2.proisagg AND
p1.prokind != 'a' AND p2.prokind != 'a' AND
(p1.proargtypes[7] < p2.proargtypes[7])
ORDER BY 1, 2;
@ -307,6 +307,11 @@ FROM pg_proc as p1 LEFT JOIN pg_description as d
ON p1.tableoid = d.classoid and p1.oid = d.objoid and d.objsubid = 0
WHERE d.classoid IS NULL AND p1.oid <= 9999 order by 1;
-- Check prokind
select count(*) from pg_proc where prokind = 'a';
select count(*) from pg_proc where prokind = 'w';
select count(*) from pg_proc where prokind = 'f';
select count(*) from pg_proc where prokind = 'p';
-- **************** pg_cast ****************
@ -631,14 +636,14 @@ ORDER by 1, 2;
SELECT a.aggfnoid::oid, p.proname
FROM pg_aggregate as a, pg_proc as p
WHERE a.aggfnoid = p.oid AND
(NOT p.proisagg OR p.proretset)
(p.prokind != 'a' OR p.proretset)
ORDER by 1, 2;
-- Make sure there are no proisagg pg_proc entries without matches.
-- Make sure there are no prokind = 'a' pg_proc entries without matches.
SELECT oid, proname
FROM pg_proc as p
WHERE p.proisagg AND
WHERE p.prokind = 'a' AND
NOT EXISTS (SELECT 1 FROM pg_aggregate a WHERE a.aggfnoid = p.oid)
ORDER by 1, 2;
@ -753,7 +758,7 @@ ORDER BY 1, 2;
SELECT p1.oid::regprocedure, p2.oid::regprocedure
FROM pg_proc AS p1, pg_proc AS p2
WHERE p1.oid < p2.oid AND p1.proname = p2.proname AND
p1.proisagg AND p2.proisagg AND
p1.prokind = 'a' AND p2.prokind = 'a' AND
array_dims(p1.proargtypes) != array_dims(p2.proargtypes) AND
p1.proname != 'listagg'
ORDER BY 1;
@ -762,7 +767,7 @@ ORDER BY 1;
SELECT oid, proname
FROM pg_proc AS p
WHERE proisagg AND proargdefaults IS NOT NULL
WHERE prokind = 'a' AND proargdefaults IS NOT NULL
ORDER by 1, 2;
-- **************** pg_opfamily ****************