Hi hackers,
Foreign key constraints created during CREATE EXTENSION
lack a pg_depend entry with deptype='e'.
Looking at the code, I found that CreateConstraintEntry() in
src/backend/catalog/pg_constraint.c does not call
recordDependencyOnCurrentExtension(), unlike most other CREATE functions.
This seems to affect all constraint types created through CreateConstraintEntry.
I stumbled upon this issue when trying to query all database objects
belonging to an extension using:
SELECT * FROM pg_depend WHERE deptype = 'e' AND refobjid = <ext_oid> AND
refclassid = 'pg_extension'::regclass
Is this omission intentional? I couldn't find any documentation or code
comments explaining why constraints should not be extension members.
Currently, it seems impossible to distinguish between:
- Constraints created by CREATE EXTENSION
- Constraints added manually to extension tables after extension creation
Would it make sense to add recordDependencyOnCurrentExtension() to
CreateConstraintEntry()? Or is there a specific reason why constraints
should be handled differently from other extension objects?
/Joel
diff --git a/src/backend/catalog/pg_constraint.c
b/src/backend/catalog/pg_constraint.c
index 2d5ac1ea813..59ae9befff4 100644
--- a/src/backend/catalog/pg_constraint.c
+++ b/src/backend/catalog/pg_constraint.c
@@ -28,6 +28,7 @@
#include "catalog/pg_operator.h"
#include "catalog/pg_type.h"
#include "commands/defrem.h"
+#include "commands/extension.h"
#include "common/int.h"
#include "utils/array.h"
#include "utils/builtins.h"
@@ -393,6 +394,13 @@ CreateConstraintEntry(const char *constraintName,
InvokeObjectPostCreateHookArg(ConstraintRelationId, conOid, 0,
is_internal);
+ /*
+ * If the constraint is being created as part of an extension script,
+ * mark it as a member of the extension.
+ */
+ if (!is_internal)
+ recordDependencyOnCurrentExtension(&conobject, false);
+
return conOid;
}