pg_upgrade code contains a number of lines like
AssertVariableIsOfType(&process_rel_infos, UpgradeTaskProcessCB);
This is presumably to ensure that the function signature is fitting for
being used with upgrade_task_add_step(). But the signature of
upgrade_task_add_step() already checks that itself, so these additional
assertions are redundant, and I find them confusing. So I propose to
remove them.
In the original thread
<https://www.postgresql.org/message-id/flat/20240516211638.GA1688936%40nathanxps13>
I found that this pattern was introduced between patch versions v9 and
v10, but there was no further explanation.From 27088b0c1af67564d706da7fad41995fdabdab53 Mon Sep 17 00:00:00 2001
From: Peter Eisentraut <[email protected]>
Date: Tue, 20 Jan 2026 10:51:15 +0100
Subject: [PATCH] Remove redundant AssertVariableIsOfType uses
The uses of AssertVariableIsOfType in pg_upgrade are unnecessary
because the calls to upgrade_task_add_step() already check the
compatibility of the callback functions. Having these additional
assertions is an unusual style and confusing without further
explanation.
---
src/bin/pg_upgrade/check.c | 23 -----------------------
src/bin/pg_upgrade/function.c | 2 --
src/bin/pg_upgrade/info.c | 5 -----
src/bin/pg_upgrade/version.c | 2 --
4 files changed, 32 deletions(-)
diff --git a/src/bin/pg_upgrade/check.c b/src/bin/pg_upgrade/check.c
index 64805fef0eb..a8d20a92a98 100644
--- a/src/bin/pg_upgrade/check.c
+++ b/src/bin/pg_upgrade/check.c
@@ -400,8 +400,6 @@ process_data_type_check(DbInfo *dbinfo, PGresult *res, void
*arg)
int i_attname = PQfnumber(res, "attname");
FILE *script = NULL;
- AssertVariableIsOfType(&process_data_type_check, UpgradeTaskProcessCB);
-
if (ntups == 0)
return;
@@ -1279,9 +1277,6 @@ process_isn_and_int8_passing_mismatch(DbInfo *dbinfo,
PGresult *res, void *arg)
int i_proname = PQfnumber(res, "proname");
UpgradeTaskReport *report = (UpgradeTaskReport *) arg;
- AssertVariableIsOfType(&process_isn_and_int8_passing_mismatch,
- UpgradeTaskProcessCB);
-
if (ntups == 0)
return;
@@ -1368,9 +1363,6 @@ process_user_defined_postfix_ops(DbInfo *dbinfo, PGresult
*res, void *arg)
int i_typnsp = PQfnumber(res, "typnsp");
int i_typname = PQfnumber(res, "typname");
- AssertVariableIsOfType(&process_user_defined_postfix_ops,
- UpgradeTaskProcessCB);
-
if (ntups == 0)
return;
@@ -1459,9 +1451,6 @@ process_incompat_polymorphics(DbInfo *dbinfo, PGresult
*res, void *arg)
int i_objkind = PQfnumber(res, "objkind");
int i_objname = PQfnumber(res, "objname");
- AssertVariableIsOfType(&process_incompat_polymorphics,
- UpgradeTaskProcessCB);
-
if (ntups == 0)
return;
@@ -1592,8 +1581,6 @@ process_with_oids_check(DbInfo *dbinfo, PGresult *res,
void *arg)
int i_nspname = PQfnumber(res, "nspname");
int i_relname = PQfnumber(res, "relname");
- AssertVariableIsOfType(&process_with_oids_check, UpgradeTaskProcessCB);
-
if (ntups == 0)
return;
@@ -1663,9 +1650,6 @@ process_inconsistent_notnull(DbInfo *dbinfo, PGresult
*res, void *arg)
int i_relname = PQfnumber(res, "relname");
int i_attname = PQfnumber(res, "attname");
- AssertVariableIsOfType(&process_inconsistent_notnull,
- UpgradeTaskProcessCB);
-
if (ntups == 0)
return;
@@ -1751,8 +1735,6 @@ process_gist_inet_ops_check(DbInfo *dbinfo, PGresult
*res, void *arg)
int i_nspname = PQfnumber(res, "nspname");
int i_relname = PQfnumber(res, "relname");
- AssertVariableIsOfType(&process_gist_inet_ops_check,
UpgradeTaskProcessCB);
-
if (ntups == 0)
return;
@@ -1886,9 +1868,6 @@ process_user_defined_encoding_conversions(DbInfo *dbinfo,
PGresult *res, void *a
int i_conname = PQfnumber(res, "conname");
int i_nspname = PQfnumber(res, "nspname");
- AssertVariableIsOfType(&process_user_defined_encoding_conversions,
- UpgradeTaskProcessCB);
-
if (ntups == 0)
return;
@@ -2398,8 +2377,6 @@ process_old_sub_state_check(DbInfo *dbinfo, PGresult
*res, void *arg)
int i_nspname = PQfnumber(res, "nspname");
int i_relname = PQfnumber(res, "relname");
- AssertVariableIsOfType(&process_old_sub_state_check,
UpgradeTaskProcessCB);
-
if (ntups == 0)
return;
diff --git a/src/bin/pg_upgrade/function.c b/src/bin/pg_upgrade/function.c
index a6ad2f07d6e..850c9238c11 100644
--- a/src/bin/pg_upgrade/function.c
+++ b/src/bin/pg_upgrade/function.c
@@ -61,8 +61,6 @@ process_loadable_libraries(DbInfo *dbinfo, PGresult *res,
void *arg)
{
struct loadable_libraries_state *state = (struct
loadable_libraries_state *) arg;
- AssertVariableIsOfType(&process_loadable_libraries,
UpgradeTaskProcessCB);
-
state->ress[dbinfo - old_cluster.dbarr.dbs] = res;
state->totaltups += PQntuples(res);
}
diff --git a/src/bin/pg_upgrade/info.c b/src/bin/pg_upgrade/info.c
index 2de0ee4d030..47e8d1039a2 100644
--- a/src/bin/pg_upgrade/info.c
+++ b/src/bin/pg_upgrade/info.c
@@ -601,8 +601,6 @@ process_rel_infos(DbInfo *dbinfo, PGresult *res, void *arg)
char *last_namespace = NULL;
char *last_tablespace = NULL;
- AssertVariableIsOfType(&process_rel_infos, UpgradeTaskProcessCB);
-
for (int relnum = 0; relnum < ntups; relnum++)
{
RelInfo *curr = &relinfos[num_rels++];
@@ -727,9 +725,6 @@ process_old_cluster_logical_slot_infos(DbInfo *dbinfo,
PGresult *res, void *arg)
LogicalSlotInfo *slotinfos = NULL;
int num_slots = PQntuples(res);
- AssertVariableIsOfType(&process_old_cluster_logical_slot_infos,
- UpgradeTaskProcessCB);
-
if (num_slots)
{
int i_slotname;
diff --git a/src/bin/pg_upgrade/version.c b/src/bin/pg_upgrade/version.c
index 55a8958eef6..e709262837e 100644
--- a/src/bin/pg_upgrade/version.c
+++ b/src/bin/pg_upgrade/version.c
@@ -152,8 +152,6 @@ process_extension_updates(DbInfo *dbinfo, PGresult *res,
void *arg)
UpgradeTaskReport *report = (UpgradeTaskReport *) arg;
PQExpBufferData connectbuf;
- AssertVariableIsOfType(&process_extension_updates,
UpgradeTaskProcessCB);
-
if (ntups == 0)
return;
--
2.52.0