aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/backend/catalog/pg_depend.c69
-rw-r--r--src/backend/commands/tablecmds.c1
-rw-r--r--src/backend/optimizer/util/plancat.c1
-rw-r--r--src/backend/utils/adt/ruleutils.c3
-rw-r--r--src/backend/utils/cache/lsyscache.c27
-rw-r--r--src/include/catalog/dependency.h2
-rw-r--r--src/include/utils/lsyscache.h1
7 files changed, 29 insertions, 75 deletions
diff --git a/src/backend/catalog/pg_depend.c b/src/backend/catalog/pg_depend.c
index 25290c821fd..429791694f0 100644
--- a/src/backend/catalog/pg_depend.c
+++ b/src/backend/catalog/pg_depend.c
@@ -969,75 +969,6 @@ getIdentitySequence(Oid relid, AttrNumber attnum, bool missing_ok)
}
/*
- * get_constraint_index
- * Given the OID of a unique, primary-key, or exclusion constraint,
- * return the OID of the underlying index.
- *
- * Return InvalidOid if the index couldn't be found; this suggests the
- * given OID is bogus, but we leave it to caller to decide what to do.
- */
-Oid
-get_constraint_index(Oid constraintId)
-{
- Oid indexId = InvalidOid;
- Relation depRel;
- ScanKeyData key[3];
- SysScanDesc scan;
- HeapTuple tup;
-
- /* Search the dependency table for the dependent index */
- depRel = table_open(DependRelationId, AccessShareLock);
-
- ScanKeyInit(&key[0],
- Anum_pg_depend_refclassid,
- BTEqualStrategyNumber, F_OIDEQ,
- ObjectIdGetDatum(ConstraintRelationId));
- ScanKeyInit(&key[1],
- Anum_pg_depend_refobjid,
- BTEqualStrategyNumber, F_OIDEQ,
- ObjectIdGetDatum(constraintId));
- ScanKeyInit(&key[2],
- Anum_pg_depend_refobjsubid,
- BTEqualStrategyNumber, F_INT4EQ,
- Int32GetDatum(0));
-
- scan = systable_beginscan(depRel, DependReferenceIndexId, true,
- NULL, 3, key);
-
- while (HeapTupleIsValid(tup = systable_getnext(scan)))
- {
- Form_pg_depend deprec = (Form_pg_depend) GETSTRUCT(tup);
-
- /*
- * We assume any internal dependency of an index on the constraint
- * must be what we are looking for.
- */
- if (deprec->classid == RelationRelationId &&
- deprec->objsubid == 0 &&
- deprec->deptype == DEPENDENCY_INTERNAL)
- {
- char relkind = get_rel_relkind(deprec->objid);
-
- /*
- * This is pure paranoia; there shouldn't be any other relkinds
- * dependent on a constraint.
- */
- if (relkind != RELKIND_INDEX &&
- relkind != RELKIND_PARTITIONED_INDEX)
- continue;
-
- indexId = deprec->objid;
- break;
- }
- }
-
- systable_endscan(scan);
- table_close(depRel, AccessShareLock);
-
- return indexId;
-}
-
-/*
* get_index_constraint
* Given the OID of an index, return the OID of the owning unique,
* primary-key, or exclusion constraint, or InvalidOid if there
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 46f1637e774..1fa9f19f08c 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -26,7 +26,6 @@
#include "access/xact.h"
#include "access/xlog.h"
#include "catalog/catalog.h"
-#include "catalog/dependency.h"
#include "catalog/heap.h"
#include "catalog/index.h"
#include "catalog/namespace.h"
diff --git a/src/backend/optimizer/util/plancat.c b/src/backend/optimizer/util/plancat.c
index 3e94256d34a..daf17596233 100644
--- a/src/backend/optimizer/util/plancat.c
+++ b/src/backend/optimizer/util/plancat.c
@@ -26,7 +26,6 @@
#include "access/transam.h"
#include "access/xlog.h"
#include "catalog/catalog.h"
-#include "catalog/dependency.h"
#include "catalog/heap.h"
#include "catalog/index.h"
#include "catalog/pg_am.h"
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index c2c6df2a4f7..ad582f99a5a 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -24,7 +24,6 @@
#include "access/relation.h"
#include "access/sysattr.h"
#include "access/table.h"
-#include "catalog/dependency.h"
#include "catalog/pg_aggregate.h"
#include "catalog/pg_am.h"
#include "catalog/pg_authid.h"
@@ -2140,7 +2139,7 @@ pg_get_constraintdef_worker(Oid constraintId, bool fullCommand,
appendStringInfoChar(&buf, ')');
- indexId = get_constraint_index(constraintId);
+ indexId = conForm->conindid;
/* Build including column list (from pg_index.indkeys) */
indtup = SearchSysCache1(INDEXRELID, ObjectIdGetDatum(indexId));
diff --git a/src/backend/utils/cache/lsyscache.c b/src/backend/utils/cache/lsyscache.c
index ae232991623..47a83658492 100644
--- a/src/backend/utils/cache/lsyscache.c
+++ b/src/backend/utils/cache/lsyscache.c
@@ -1094,6 +1094,33 @@ get_constraint_name(Oid conoid)
return NULL;
}
+/*
+ * get_constraint_index
+ * Given the OID of a unique, primary-key, or exclusion constraint,
+ * return the OID of the underlying index.
+ *
+ * Return InvalidOid if the index couldn't be found; this suggests the
+ * given OID is bogus, but we leave it to caller to decide what to do.
+ */
+Oid
+get_constraint_index(Oid conoid)
+{
+ HeapTuple tp;
+
+ tp = SearchSysCache1(CONSTROID, ObjectIdGetDatum(conoid));
+ if (HeapTupleIsValid(tp))
+ {
+ Form_pg_constraint contup = (Form_pg_constraint) GETSTRUCT(tp);
+ Oid result;
+
+ result = contup->conindid;
+ ReleaseSysCache(tp);
+ return result;
+ }
+ else
+ return InvalidOid;
+}
+
/* ---------- LANGUAGE CACHE ---------- */
char *
diff --git a/src/include/catalog/dependency.h b/src/include/catalog/dependency.h
index 901d5019cdf..1fcc4a39ec4 100644
--- a/src/include/catalog/dependency.h
+++ b/src/include/catalog/dependency.h
@@ -235,8 +235,6 @@ extern bool sequenceIsOwned(Oid seqId, char deptype, Oid *tableId, int32 *colId)
extern List *getOwnedSequences(Oid relid);
extern Oid getIdentitySequence(Oid relid, AttrNumber attnum, bool missing_ok);
-extern Oid get_constraint_index(Oid constraintId);
-
extern Oid get_index_constraint(Oid indexId);
extern List *get_index_ref_constraints(Oid indexId);
diff --git a/src/include/utils/lsyscache.h b/src/include/utils/lsyscache.h
index fecfe1f4f6e..c97e12dde8a 100644
--- a/src/include/utils/lsyscache.h
+++ b/src/include/utils/lsyscache.h
@@ -96,6 +96,7 @@ extern Oid get_cast_oid(Oid sourcetypeid, Oid targettypeid, bool missing_ok);
extern char *get_collation_name(Oid colloid);
extern bool get_collation_isdeterministic(Oid colloid);
extern char *get_constraint_name(Oid conoid);
+extern Oid get_constraint_index(Oid conoid);
extern char *get_language_name(Oid langoid, bool missing_ok);
extern Oid get_opclass_family(Oid opclass);
extern Oid get_opclass_input_type(Oid opclass);