Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 8b069ef

Browse filesBrowse files
committed
Change get_constraint_index() to use pg_constraint.conindid
It was still using a scan of pg_depend instead of using the conindid column that has been added since. Since it is now just a catalog lookup wrapper and not related to pg_depend, move from pg_depend.c to lsyscache.c. Reviewed-by: Matthias van de Meent <boekewurm+postgres@gmail.com> Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us> Reviewed-by: Michael Paquier <michael@paquier.xyz> Discussion: https://www.postgresql.org/message-id/flat/4688d55c-9a2e-9a5a-d166-5f24fe0bf8db%40enterprisedb.com
1 parent 16c302f commit 8b069ef
Copy full SHA for 8b069ef

File tree

Expand file treeCollapse file tree

7 files changed

+29
-75
lines changed
Filter options
Expand file treeCollapse file tree

7 files changed

+29
-75
lines changed

‎src/backend/catalog/pg_depend.c

Copy file name to clipboardExpand all lines: src/backend/catalog/pg_depend.c
-69Lines changed: 0 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -968,75 +968,6 @@ getIdentitySequence(Oid relid, AttrNumber attnum, bool missing_ok)
968968
return linitial_oid(seqlist);
969969
}
970970

971-
/*
972-
* get_constraint_index
973-
* Given the OID of a unique, primary-key, or exclusion constraint,
974-
* return the OID of the underlying index.
975-
*
976-
* Return InvalidOid if the index couldn't be found; this suggests the
977-
* given OID is bogus, but we leave it to caller to decide what to do.
978-
*/
979-
Oid
980-
get_constraint_index(Oid constraintId)
981-
{
982-
Oid indexId = InvalidOid;
983-
Relation depRel;
984-
ScanKeyData key[3];
985-
SysScanDesc scan;
986-
HeapTuple tup;
987-
988-
/* Search the dependency table for the dependent index */
989-
depRel = table_open(DependRelationId, AccessShareLock);
990-
991-
ScanKeyInit(&key[0],
992-
Anum_pg_depend_refclassid,
993-
BTEqualStrategyNumber, F_OIDEQ,
994-
ObjectIdGetDatum(ConstraintRelationId));
995-
ScanKeyInit(&key[1],
996-
Anum_pg_depend_refobjid,
997-
BTEqualStrategyNumber, F_OIDEQ,
998-
ObjectIdGetDatum(constraintId));
999-
ScanKeyInit(&key[2],
1000-
Anum_pg_depend_refobjsubid,
1001-
BTEqualStrategyNumber, F_INT4EQ,
1002-
Int32GetDatum(0));
1003-
1004-
scan = systable_beginscan(depRel, DependReferenceIndexId, true,
1005-
NULL, 3, key);
1006-
1007-
while (HeapTupleIsValid(tup = systable_getnext(scan)))
1008-
{
1009-
Form_pg_depend deprec = (Form_pg_depend) GETSTRUCT(tup);
1010-
1011-
/*
1012-
* We assume any internal dependency of an index on the constraint
1013-
* must be what we are looking for.
1014-
*/
1015-
if (deprec->classid == RelationRelationId &&
1016-
deprec->objsubid == 0 &&
1017-
deprec->deptype == DEPENDENCY_INTERNAL)
1018-
{
1019-
char relkind = get_rel_relkind(deprec->objid);
1020-
1021-
/*
1022-
* This is pure paranoia; there shouldn't be any other relkinds
1023-
* dependent on a constraint.
1024-
*/
1025-
if (relkind != RELKIND_INDEX &&
1026-
relkind != RELKIND_PARTITIONED_INDEX)
1027-
continue;
1028-
1029-
indexId = deprec->objid;
1030-
break;
1031-
}
1032-
}
1033-
1034-
systable_endscan(scan);
1035-
table_close(depRel, AccessShareLock);
1036-
1037-
return indexId;
1038-
}
1039-
1040971
/*
1041972
* get_index_constraint
1042973
* Given the OID of an index, return the OID of the owning unique,

‎src/backend/commands/tablecmds.c

Copy file name to clipboardExpand all lines: src/backend/commands/tablecmds.c
-1Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
#include "access/xact.h"
2727
#include "access/xlog.h"
2828
#include "catalog/catalog.h"
29-
#include "catalog/dependency.h"
3029
#include "catalog/heap.h"
3130
#include "catalog/index.h"
3231
#include "catalog/namespace.h"

‎src/backend/optimizer/util/plancat.c

Copy file name to clipboardExpand all lines: src/backend/optimizer/util/plancat.c
-1Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
#include "access/transam.h"
2727
#include "access/xlog.h"
2828
#include "catalog/catalog.h"
29-
#include "catalog/dependency.h"
3029
#include "catalog/heap.h"
3130
#include "catalog/index.h"
3231
#include "catalog/pg_am.h"

‎src/backend/utils/adt/ruleutils.c

Copy file name to clipboardExpand all lines: src/backend/utils/adt/ruleutils.c
+1-2Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
#include "access/relation.h"
2525
#include "access/sysattr.h"
2626
#include "access/table.h"
27-
#include "catalog/dependency.h"
2827
#include "catalog/pg_aggregate.h"
2928
#include "catalog/pg_am.h"
3029
#include "catalog/pg_authid.h"
@@ -2140,7 +2139,7 @@ pg_get_constraintdef_worker(Oid constraintId, bool fullCommand,
21402139

21412140
appendStringInfoChar(&buf, ')');
21422141

2143-
indexId = get_constraint_index(constraintId);
2142+
indexId = conForm->conindid;
21442143

21452144
/* Build including column list (from pg_index.indkeys) */
21462145
indtup = SearchSysCache1(INDEXRELID, ObjectIdGetDatum(indexId));

‎src/backend/utils/cache/lsyscache.c

Copy file name to clipboardExpand all lines: src/backend/utils/cache/lsyscache.c
+27Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1094,6 +1094,33 @@ get_constraint_name(Oid conoid)
10941094
return NULL;
10951095
}
10961096

1097+
/*
1098+
* get_constraint_index
1099+
* Given the OID of a unique, primary-key, or exclusion constraint,
1100+
* return the OID of the underlying index.
1101+
*
1102+
* Return InvalidOid if the index couldn't be found; this suggests the
1103+
* given OID is bogus, but we leave it to caller to decide what to do.
1104+
*/
1105+
Oid
1106+
get_constraint_index(Oid conoid)
1107+
{
1108+
HeapTuple tp;
1109+
1110+
tp = SearchSysCache1(CONSTROID, ObjectIdGetDatum(conoid));
1111+
if (HeapTupleIsValid(tp))
1112+
{
1113+
Form_pg_constraint contup = (Form_pg_constraint) GETSTRUCT(tp);
1114+
Oid result;
1115+
1116+
result = contup->conindid;
1117+
ReleaseSysCache(tp);
1118+
return result;
1119+
}
1120+
else
1121+
return InvalidOid;
1122+
}
1123+
10971124
/* ---------- LANGUAGE CACHE ---------- */
10981125

10991126
char *

‎src/include/catalog/dependency.h

Copy file name to clipboardExpand all lines: src/include/catalog/dependency.h
-2Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -235,8 +235,6 @@ extern bool sequenceIsOwned(Oid seqId, char deptype, Oid *tableId, int32 *colId)
235235
extern List *getOwnedSequences(Oid relid);
236236
extern Oid getIdentitySequence(Oid relid, AttrNumber attnum, bool missing_ok);
237237

238-
extern Oid get_constraint_index(Oid constraintId);
239-
240238
extern Oid get_index_constraint(Oid indexId);
241239

242240
extern List *get_index_ref_constraints(Oid indexId);

‎src/include/utils/lsyscache.h

Copy file name to clipboardExpand all lines: src/include/utils/lsyscache.h
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ extern Oid get_cast_oid(Oid sourcetypeid, Oid targettypeid, bool missing_ok);
9696
extern char *get_collation_name(Oid colloid);
9797
extern bool get_collation_isdeterministic(Oid colloid);
9898
extern char *get_constraint_name(Oid conoid);
99+
extern Oid get_constraint_index(Oid conoid);
99100
extern char *get_language_name(Oid langoid, bool missing_ok);
100101
extern Oid get_opclass_family(Oid opclass);
101102
extern Oid get_opclass_input_type(Oid opclass);

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.