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

Commit3dfd2d6

Browse files
committed
Avoid duplicates in ALTER ... DEPENDS ON EXTENSION
If the command is attempted for an extension that the object alreadydepends on, silently do nothing.In particular, this means that if a database containing multiple suchentries is dumped, the restore will silently do the right thing andrecord just the first one. (At least, in a world where pg_dump doesdump such entries -- which it doesn't currently, but it will.)Backpatch to 9.6, where this kind of dependency was introduced.Reviewed-by: Ibrar Ahmed, Tom Lane (offlist)Discussion:https://postgr.es/m/20200217225333.GA30974@alvherre.pgsql
1 parent475b061 commit3dfd2d6

File tree

5 files changed

+54
-1
lines changed

5 files changed

+54
-1
lines changed

‎src/backend/catalog/pg_depend.c

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -485,6 +485,49 @@ getExtensionOfObject(Oid classId, Oid objectId)
485485
returnresult;
486486
}
487487

488+
/*
489+
* Return (possibly NIL) list of extensions that the given object depends on
490+
* in DEPENDENCY_AUTO_EXTENSION mode.
491+
*/
492+
List*
493+
getAutoExtensionsOfObject(OidclassId,OidobjectId)
494+
{
495+
List*result=NIL;
496+
RelationdepRel;
497+
ScanKeyDatakey[2];
498+
SysScanDescscan;
499+
HeapTupletup;
500+
501+
depRel=heap_open(DependRelationId,AccessShareLock);
502+
503+
ScanKeyInit(&key[0],
504+
Anum_pg_depend_classid,
505+
BTEqualStrategyNumber,F_OIDEQ,
506+
ObjectIdGetDatum(classId));
507+
ScanKeyInit(&key[1],
508+
Anum_pg_depend_objid,
509+
BTEqualStrategyNumber,F_OIDEQ,
510+
ObjectIdGetDatum(objectId));
511+
512+
scan=systable_beginscan(depRel,DependDependerIndexId, true,
513+
NULL,2,key);
514+
515+
while (HeapTupleIsValid((tup=systable_getnext(scan))))
516+
{
517+
Form_pg_dependdepform= (Form_pg_depend)GETSTRUCT(tup);
518+
519+
if (depform->refclassid==ExtensionRelationId&&
520+
depform->deptype==DEPENDENCY_AUTO_EXTENSION)
521+
result=lappend_oid(result,depform->refobjid);
522+
}
523+
524+
systable_endscan(scan);
525+
526+
heap_close(depRel,AccessShareLock);
527+
528+
returnresult;
529+
}
530+
488531
/*
489532
* Detect whether a sequence is marked as "owned" by a column
490533
*

‎src/backend/commands/alter.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -425,6 +425,7 @@ ExecAlterObjectDependsStmt(AlterObjectDependsStmt *stmt, ObjectAddress *refAddre
425425
ObjectAddressaddress;
426426
ObjectAddressrefAddr;
427427
Relationrel;
428+
List*currexts;
428429

429430
address=
430431
get_object_address_rv(stmt->objectType,stmt->relation, (List*)stmt->object,
@@ -454,7 +455,11 @@ ExecAlterObjectDependsStmt(AlterObjectDependsStmt *stmt, ObjectAddress *refAddre
454455
if (refAddress)
455456
*refAddress=refAddr;
456457

457-
recordDependencyOn(&address,&refAddr,DEPENDENCY_AUTO_EXTENSION);
458+
/* Avoid duplicates */
459+
currexts=getAutoExtensionsOfObject(address.classId,
460+
address.objectId);
461+
if (!list_member_oid(currexts,refAddr.objectId))
462+
recordDependencyOn(&address,&refAddr,DEPENDENCY_AUTO_EXTENSION);
458463

459464
returnaddress;
460465
}

‎src/include/catalog/dependency.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,7 @@ extern long changeDependencyFor(Oid classId, Oid objectId,
237237
OidnewRefObjectId);
238238

239239
externOidgetExtensionOfObject(OidclassId,OidobjectId);
240+
externList*getAutoExtensionsOfObject(OidclassId,OidobjectId);
240241

241242
externboolsequenceIsOwned(OidseqId,chardeptype,Oid*tableId,int32*colId);
242243
externList*getOwnedSequences(Oidrelid,AttrNumberattnum);

‎src/test/modules/test_extensions/expected/test_extdepend.out

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ SELECT * FROM test_extdep_commands \gexec
4747
CREATE INDEX e ON a (a1)
4848
ALTER INDEX e DEPENDS ON EXTENSION test_ext5
4949
RESET search_path
50+
-- A dependent object made dependent again has no effect
51+
ALTER FUNCTION test_ext.b() DEPENDS ON EXTENSION test_ext5;
5052
-- make sure we have the right dependencies on the extension
5153
SELECT deptype, p.*
5254
FROM pg_depend, pg_identify_object(classid, objid, objsubid) AS p

‎src/test/modules/test_extensions/sql/test_extdepend.sql

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ COPY test_extdep_commands FROM stdin;
2727
SELECT*FROM test_extdep_commands;
2828
-- First, test that dependent objects go away when the extension is dropped.
2929
SELECT*FROM test_extdep_commands \gexec
30+
-- A dependent object made dependent again has no effect
31+
ALTERFUNCTIONtest_ext.b() DEPENDSON EXTENSION test_ext5;
3032
-- make sure we have the right dependencies on the extension
3133
SELECT deptype, p.*
3234
FROM pg_depend, pg_identify_object(classid, objid, objsubid)AS p

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp