Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

Commit8b069ef

Browse files
committed
Change get_constraint_index() to use pg_constraint.conindid
It was still using a scan of pg_depend instead of using the conindidcolumn that has been added since.Since it is now just a catalog lookup wrapper and not related topg_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 parent16c302f commit8b069ef

File tree

7 files changed

+29
-75
lines changed

7 files changed

+29
-75
lines changed

‎src/backend/catalog/pg_depend.c

Lines 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
returnlinitial_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(OidconstraintId)
981-
{
982-
OidindexId=InvalidOid;
983-
RelationdepRel;
984-
ScanKeyDatakey[3];
985-
SysScanDescscan;
986-
HeapTupletup;
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_dependdeprec= (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-
charrelkind=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-
returnindexId;
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

Lines 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

Lines 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

Lines 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

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1094,6 +1094,33 @@ get_constraint_name(Oid conoid)
10941094
returnNULL;
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(Oidconoid)
1107+
{
1108+
HeapTupletp;
1109+
1110+
tp=SearchSysCache1(CONSTROID,ObjectIdGetDatum(conoid));
1111+
if (HeapTupleIsValid(tp))
1112+
{
1113+
Form_pg_constraintcontup= (Form_pg_constraint)GETSTRUCT(tp);
1114+
Oidresult;
1115+
1116+
result=contup->conindid;
1117+
ReleaseSysCache(tp);
1118+
returnresult;
1119+
}
1120+
else
1121+
returnInvalidOid;
1122+
}
1123+
10971124
/*---------- LANGUAGE CACHE ---------- */
10981125

10991126
char*

‎src/include/catalog/dependency.h

Lines 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
externList*getOwnedSequences(Oidrelid);
236236
externOidgetIdentitySequence(Oidrelid,AttrNumberattnum,boolmissing_ok);
237237

238-
externOidget_constraint_index(OidconstraintId);
239-
240238
externOidget_index_constraint(OidindexId);
241239

242240
externList*get_index_ref_constraints(OidindexId);

‎src/include/utils/lsyscache.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ extern Oidget_cast_oid(Oid sourcetypeid, Oid targettypeid, bool missing_ok);
9696
externchar*get_collation_name(Oidcolloid);
9797
externboolget_collation_isdeterministic(Oidcolloid);
9898
externchar*get_constraint_name(Oidconoid);
99+
externOidget_constraint_index(Oidconoid);
99100
externchar*get_language_name(Oidlangoid,boolmissing_ok);
100101
externOidget_opclass_family(Oidopclass);
101102
externOidget_opclass_input_type(Oidopclass);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp