From b0e3602930556669dc272cd557b9419cbfdcfdee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Erik=20Nordstr=C3=B6m?= Date: Mon, 2 Dec 2024 18:37:36 +0100 Subject: [PATCH] Add workaround for pg_depend bug in PG < 15.4 PostgreSQL versions prior to 15.4 didn't properly update object dependencies when setting a new access method on a table. The fix for the bug is found in this commit: https://github.com/postgres/postgres/commit/97d89101045fac8cb36f4ef6c08526ea0841a596 The `hypercore_create` test failed on buggy PG versions (e.g., 15.0) due to wrong contents of pg_depend showing up in test output when converting a table from Hypercore TAM back to regular heap. This change adds a workaround that updates pg_depend with the correct information when compiling against PG versions that suffer from the bug. --- tsl/src/compression/api.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/tsl/src/compression/api.c b/tsl/src/compression/api.c index 7e25c20952a..f57460a4875 100644 --- a/tsl/src/compression/api.c +++ b/tsl/src/compression/api.c @@ -14,6 +14,7 @@ #include #include #include +#include #include #include #include @@ -777,13 +778,26 @@ set_access_method(Oid relid, const char *amname) }; bool to_hypercore = strcmp(amname, TS_HYPERCORE_TAM_NAME) == 0; Oid amoid = ts_get_rel_am(relid); + Oid new_amoid = get_am_oid(amname, false); /* Setting the same access method is a no-op */ - if (amoid == get_am_oid(amname, false)) + if (amoid == new_amoid) return relid; hypercore_alter_access_method_begin(relid, !to_hypercore); AlterTableInternal(relid, list_make1(&cmd), false); + +#if (PG_VERSION_NUM < 150004) + /* Fix for PostgreSQL bug where pg_depend was not updated to reflect the + * new dependency between AM and relation. See related PG fix here: + * https://github.com/postgres/postgres/commit/97d89101045fac8cb36f4ef6c08526ea0841a596 */ + if (changeDependencyFor(RelationRelationId, relid, AccessMethodRelationId, amoid, new_amoid) != + 1) + elog(ERROR, + "could not change access method dependency for relation \"%s.%s\"", + get_namespace_name(get_rel_namespace(relid)), + get_rel_name(relid)); +#endif hypercore_alter_access_method_finish(relid, !to_hypercore); #else