mirror of
https://github.com/postgres/postgres.git
synced 2025-08-24 09:27:52 +03:00
Add construct_array_builtin, deconstruct_array_builtin
There were many calls to construct_array() and deconstruct_array() for built-in types, for example, when dealing with system catalog columns. These all hardcoded the type attributes necessary to pass to these functions. To simplify this a bit, add construct_array_builtin(), deconstruct_array_builtin() as wrappers that centralize this hardcoded knowledge. This simplifies many call sites and reduces the amount of hardcoded stuff that is spread around. Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us> Discussion: https://www.postgresql.org/message-id/flat/2914356f-9e5f-8c59-2995-5997fc48bcba%40enterprisedb.com
This commit is contained in:
@@ -1688,10 +1688,7 @@ update_attstats(Oid relid, bool inh, int natts, VacAttrStats **vacattrstats)
|
||||
|
||||
for (n = 0; n < nnum; n++)
|
||||
numdatums[n] = Float4GetDatum(stats->stanumbers[k][n]);
|
||||
/* XXX knows more than it should about type float4: */
|
||||
arry = construct_array(numdatums, nnum,
|
||||
FLOAT4OID,
|
||||
sizeof(float4), true, TYPALIGN_INT);
|
||||
arry = construct_array_builtin(numdatums, nnum, FLOAT4OID);
|
||||
values[i++] = PointerGetDatum(arry); /* stanumbersN */
|
||||
}
|
||||
else
|
||||
|
@@ -351,8 +351,7 @@ filter_list_to_array(List *filterlist)
|
||||
pfree(result);
|
||||
}
|
||||
|
||||
return PointerGetDatum(construct_array(data, l, TEXTOID,
|
||||
-1, false, TYPALIGN_INT));
|
||||
return PointerGetDatum(construct_array_builtin(data, l, TEXTOID));
|
||||
}
|
||||
|
||||
/*
|
||||
|
@@ -2251,9 +2251,7 @@ convert_requires_to_datum(List *requires)
|
||||
datums[ndatums++] =
|
||||
DirectFunctionCall1(namein, CStringGetDatum(curreq));
|
||||
}
|
||||
a = construct_array(datums, ndatums,
|
||||
NAMEOID,
|
||||
NAMEDATALEN, false, TYPALIGN_CHAR);
|
||||
a = construct_array_builtin(datums, ndatums, NAMEOID);
|
||||
return PointerGetDatum(a);
|
||||
}
|
||||
|
||||
@@ -2433,9 +2431,7 @@ pg_extension_config_dump(PG_FUNCTION_ARGS)
|
||||
arrayLength = 0;
|
||||
arrayIndex = 1;
|
||||
|
||||
a = construct_array(&elementDatum, 1,
|
||||
OIDOID,
|
||||
sizeof(Oid), true, TYPALIGN_INT);
|
||||
a = construct_array_builtin(&elementDatum, 1, OIDOID);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -2486,9 +2482,7 @@ pg_extension_config_dump(PG_FUNCTION_ARGS)
|
||||
if (arrayLength != 0)
|
||||
elog(ERROR, "extconfig and extcondition arrays do not match");
|
||||
|
||||
a = construct_array(&elementDatum, 1,
|
||||
TEXTOID,
|
||||
-1, false, TYPALIGN_INT);
|
||||
a = construct_array_builtin(&elementDatum, 1, TEXTOID);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -2630,14 +2624,12 @@ extension_config_remove(Oid extensionoid, Oid tableoid)
|
||||
int i;
|
||||
|
||||
/* We already checked there are no nulls */
|
||||
deconstruct_array(a, OIDOID, sizeof(Oid), true, TYPALIGN_INT,
|
||||
&dvalues, NULL, &nelems);
|
||||
deconstruct_array_builtin(a, OIDOID, &dvalues, NULL, &nelems);
|
||||
|
||||
for (i = arrayIndex; i < arrayLength - 1; i++)
|
||||
dvalues[i] = dvalues[i + 1];
|
||||
|
||||
a = construct_array(dvalues, arrayLength - 1,
|
||||
OIDOID, sizeof(Oid), true, TYPALIGN_INT);
|
||||
a = construct_array_builtin(dvalues, arrayLength - 1, OIDOID);
|
||||
|
||||
repl_val[Anum_pg_extension_extconfig - 1] = PointerGetDatum(a);
|
||||
}
|
||||
@@ -2676,14 +2668,12 @@ extension_config_remove(Oid extensionoid, Oid tableoid)
|
||||
int i;
|
||||
|
||||
/* We already checked there are no nulls */
|
||||
deconstruct_array(a, TEXTOID, -1, false, TYPALIGN_INT,
|
||||
&dvalues, NULL, &nelems);
|
||||
deconstruct_array_builtin(a, TEXTOID, &dvalues, NULL, &nelems);
|
||||
|
||||
for (i = arrayIndex; i < arrayLength - 1; i++)
|
||||
dvalues[i] = dvalues[i + 1];
|
||||
|
||||
a = construct_array(dvalues, arrayLength - 1,
|
||||
TEXTOID, -1, false, TYPALIGN_INT);
|
||||
a = construct_array_builtin(dvalues, arrayLength - 1, TEXTOID);
|
||||
|
||||
repl_val[Anum_pg_extension_extcondition - 1] = PointerGetDatum(a);
|
||||
}
|
||||
|
@@ -468,10 +468,8 @@ interpret_function_parameter_list(ParseState *pstate,
|
||||
|
||||
if (outCount > 0 || varCount > 0)
|
||||
{
|
||||
*allParameterTypes = construct_array(allTypes, parameterCount, OIDOID,
|
||||
sizeof(Oid), true, TYPALIGN_INT);
|
||||
*parameterModes = construct_array(paramModes, parameterCount, CHAROID,
|
||||
1, true, TYPALIGN_CHAR);
|
||||
*allParameterTypes = construct_array_builtin(allTypes, parameterCount, OIDOID);
|
||||
*parameterModes = construct_array_builtin(paramModes, parameterCount, CHAROID);
|
||||
if (outCount > 1)
|
||||
*requiredResultType = RECORDOID;
|
||||
/* otherwise we set requiredResultType correctly above */
|
||||
@@ -489,8 +487,7 @@ interpret_function_parameter_list(ParseState *pstate,
|
||||
if (paramNames[i] == PointerGetDatum(NULL))
|
||||
paramNames[i] = CStringGetTextDatum("");
|
||||
}
|
||||
*parameterNames = construct_array(paramNames, parameterCount, TEXTOID,
|
||||
-1, false, TYPALIGN_INT);
|
||||
*parameterNames = construct_array_builtin(paramNames, parameterCount, TEXTOID);
|
||||
}
|
||||
else
|
||||
*parameterNames = NULL;
|
||||
@@ -1222,8 +1219,7 @@ CreateFunction(ParseState *pstate, CreateFunctionStmt *stmt)
|
||||
i = 0;
|
||||
foreach(lc, trftypes_list)
|
||||
arr[i++] = ObjectIdGetDatum(lfirst_oid(lc));
|
||||
trftypes = construct_array(arr, list_length(trftypes_list),
|
||||
OIDOID, sizeof(Oid), true, TYPALIGN_INT);
|
||||
trftypes = construct_array_builtin(arr, list_length(trftypes_list), OIDOID);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@@ -500,8 +500,7 @@ RemoveRoleFromObjectPolicy(Oid roleid, Oid classid, Oid policy_id)
|
||||
memset(isnull, 0, sizeof(isnull));
|
||||
|
||||
/* This is the array for the new tuple */
|
||||
role_ids = construct_array(role_oids, num_roles, OIDOID,
|
||||
sizeof(Oid), true, TYPALIGN_INT);
|
||||
role_ids = construct_array_builtin(role_oids, num_roles, OIDOID);
|
||||
|
||||
replaces[Anum_pg_policy_polroles - 1] = true;
|
||||
values[Anum_pg_policy_polroles - 1] = PointerGetDatum(role_ids);
|
||||
@@ -617,8 +616,7 @@ CreatePolicy(CreatePolicyStmt *stmt)
|
||||
|
||||
/* Collect role ids */
|
||||
role_oids = policy_role_list_to_array(stmt->roles, &nitems);
|
||||
role_ids = construct_array(role_oids, nitems, OIDOID,
|
||||
sizeof(Oid), true, TYPALIGN_INT);
|
||||
role_ids = construct_array_builtin(role_oids, nitems, OIDOID);
|
||||
|
||||
/* Parse the supplied clause */
|
||||
qual_pstate = make_parsestate(NULL);
|
||||
@@ -801,8 +799,7 @@ AlterPolicy(AlterPolicyStmt *stmt)
|
||||
if (stmt->roles != NULL)
|
||||
{
|
||||
role_oids = policy_role_list_to_array(stmt->roles, &nitems);
|
||||
role_ids = construct_array(role_oids, nitems, OIDOID,
|
||||
sizeof(Oid), true, TYPALIGN_INT);
|
||||
role_ids = construct_array_builtin(role_oids, nitems, OIDOID);
|
||||
}
|
||||
|
||||
/* Get id of table. Also handles permissions checks. */
|
||||
|
@@ -722,8 +722,6 @@ build_regtype_array(Oid *param_types, int num_params)
|
||||
for (i = 0; i < num_params; i++)
|
||||
tmp_ary[i] = ObjectIdGetDatum(param_types[i]);
|
||||
|
||||
/* XXX: this hardcodes assumptions about the regtype type */
|
||||
result = construct_array(tmp_ary, num_params, REGTYPEOID,
|
||||
4, true, TYPALIGN_INT);
|
||||
result = construct_array_builtin(tmp_ary, num_params, REGTYPEOID);
|
||||
return PointerGetDatum(result);
|
||||
}
|
||||
|
@@ -467,7 +467,7 @@ CreateStatistics(CreateStatsStmt *stmt)
|
||||
if (build_expressions)
|
||||
types[ntypes++] = CharGetDatum(STATS_EXT_EXPRESSIONS);
|
||||
Assert(ntypes > 0 && ntypes <= lengthof(types));
|
||||
stxkind = construct_array(types, ntypes, CHAROID, 1, true, TYPALIGN_CHAR);
|
||||
stxkind = construct_array_builtin(types, ntypes, CHAROID);
|
||||
|
||||
/* convert the expressions (if any) to a text datum */
|
||||
if (stxexprs != NIL)
|
||||
|
@@ -494,8 +494,7 @@ publicationListToArray(List *publist)
|
||||
|
||||
MemoryContextSwitchTo(oldcxt);
|
||||
|
||||
arr = construct_array(datums, list_length(publist),
|
||||
TEXTOID, -1, false, TYPALIGN_INT);
|
||||
arr = construct_array_builtin(datums, list_length(publist), TEXTOID);
|
||||
|
||||
MemoryContextDelete(memcxt);
|
||||
|
||||
|
@@ -1893,12 +1893,9 @@ makeMultirangeConstructors(const char *name, Oid namespace,
|
||||
/* n-arg constructor - vararg */
|
||||
argtypes = buildoidvector(&rangeArrayOid, 1);
|
||||
allParamTypes = ObjectIdGetDatum(rangeArrayOid);
|
||||
allParameterTypes = construct_array(&allParamTypes,
|
||||
1, OIDOID,
|
||||
sizeof(Oid), true, TYPALIGN_INT);
|
||||
allParameterTypes = construct_array_builtin(&allParamTypes, 1, OIDOID);
|
||||
paramModes = CharGetDatum(FUNC_PARAM_VARIADIC);
|
||||
parameterModes = construct_array(¶mModes, 1, CHAROID,
|
||||
1, true, TYPALIGN_CHAR);
|
||||
parameterModes = construct_array_builtin(¶mModes, 1, CHAROID);
|
||||
myself = ProcedureCreate(name, /* name: same as multirange type */
|
||||
namespace,
|
||||
false, /* replace */
|
||||
|
Reference in New Issue
Block a user