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

Commit182db07

Browse files
committed
Fix test about ignoring extension dependencies during extension scripts.
Commit08dd23c introduced an exception to the rule that extension memberobjects can only be dropped as part of dropping the whole extension,intending to allow such drops while running the extension's own creation orupdate scripts. However, the exception was only applied at the outermostrecursion level, because it was modeled on a pre-existing check to ignoredependencies on objects listed in pendingObjects. Bug #14434 from PhilippeBeaudoin shows that this is inadequate: in some cases we can reach anextension member object by recursion from another one. (The bug concernsthe serial-sequence case; I'm not sure if there are other cases, but theremight well be.)To fix, revert08dd23c's changes to findDependentObjects() and insteadapply the creating_extension exception regardless of stack level.Having seen this example, I'm a bit suspicious that the pendingObjectslogic is also wrong and such cases should likewise be allowed at anyrecursion level. However, changing that would interact in subtle wayswith the recursion logic (at least it would need to be moved to after therecursing-from check). Given that the code's been like that a long time,I'll refrain from touching it without a clear example showing it's wrong.Back-patch to all active branches. In HEAD and 9.6, where suitabletest infrastructure exists, add a regression test case based on thebug report.Report: <20161125151448.6529.33039@wrigleys.postgresql.org>Discussion: <13224.1480177514@sss.pgh.pa.us>
1 parent2732705 commit182db07

File tree

7 files changed

+87
-29
lines changed

7 files changed

+87
-29
lines changed

‎src/backend/catalog/dependency.c

Lines changed: 25 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -594,29 +594,43 @@ findDependentObjects(const ObjectAddress *object,
594594
caseDEPENDENCY_AUTO_EXTENSION:
595595
/* no problem */
596596
break;
597-
caseDEPENDENCY_INTERNAL:
597+
598598
caseDEPENDENCY_EXTENSION:
599599

600+
/*
601+
* If the other object is the extension currently being
602+
* created/altered, ignore this dependency and continue with
603+
* the deletion. This allows dropping of an extension's
604+
* objects within the extension's scripts, as well as corner
605+
* cases such as dropping a transient object created within
606+
* such a script.
607+
*/
608+
if (creating_extension&&
609+
otherObject.classId==ExtensionRelationId&&
610+
otherObject.objectId==CurrentExtensionObject)
611+
break;
612+
613+
/* Otherwise, treat this like an internal dependency */
614+
/* FALL THRU */
615+
616+
caseDEPENDENCY_INTERNAL:
617+
600618
/*
601619
* This object is part of the internal implementation of
602620
* another object, or is part of the extension that is the
603621
* other object. We have three cases:
604622
*
605-
* 1. At the outermost recursion level, we normally disallow
606-
* the DROP. (We just ereport here, rather than proceeding,
607-
* since no other dependencies are likely to be interesting.)
608-
* However, there are exceptions.
623+
* 1. At the outermost recursion level, disallow the DROP. (We
624+
* just ereport here, rather than proceeding, since no other
625+
* dependencies are likely to be interesting.)However, if
626+
* the owning object is listed in pendingObjects, just release
627+
* the caller's lock and return; we'll eventually complete the
628+
* DROP when we reach that entry in the pending list.
609629
*/
610630
if (stack==NULL)
611631
{
612632
char*otherObjDesc;
613633

614-
/*
615-
* Exception 1a: if the owning object is listed in
616-
* pendingObjects, just release the caller's lock and
617-
* return. We'll eventually complete the DROP when we
618-
* reach that entry in the pending list.
619-
*/
620634
if (pendingObjects&&
621635
object_address_present(&otherObject,pendingObjects))
622636
{
@@ -625,21 +639,6 @@ findDependentObjects(const ObjectAddress *object,
625639
ReleaseDeletionLock(object);
626640
return;
627641
}
628-
629-
/*
630-
* Exception 1b: if the owning object is the extension
631-
* currently being created/altered, it's okay to continue
632-
* with the deletion. This allows dropping of an
633-
* extension's objects within the extension's scripts, as
634-
* well as corner cases such as dropping a transient
635-
* object created within such a script.
636-
*/
637-
if (creating_extension&&
638-
otherObject.classId==ExtensionRelationId&&
639-
otherObject.objectId==CurrentExtensionObject)
640-
break;
641-
642-
/* No exception applies, so throw the error */
643642
otherObjDesc=getObjectDescription(&otherObject);
644643
ereport(ERROR,
645644
(errcode(ERRCODE_DEPENDENT_OBJECTS_STILL_EXIST),

‎src/test/modules/test_extensions/Makefile

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@ MODULE = test_extensions
44
PGFILEDESC = "test_extensions - regression testing for EXTENSION support"
55

66
EXTENSION = test_ext1 test_ext2 test_ext3 test_ext4 test_ext5 test_ext6\
7-
test_ext_cyclic1 test_ext_cyclic2
7+
test_ext7test_ext_cyclic1 test_ext_cyclic2
88
DATA = test_ext1--1.0.sql test_ext2--1.0.sql test_ext3--1.0.sql\
9-
test_ext4--1.0.sql test_ext5--1.0.sql test_ext6--1.0.sql\
10-
test_ext_cyclic1--1.0.sql test_ext_cyclic2--1.0.sql
9+
test_ext4--1.0.sql test_ext5--1.0.sql test_ext6--1.0.sql\
10+
test_ext7--1.0.sql test_ext7--1.0--2.0.sql\
11+
test_ext_cyclic1--1.0.sql test_ext_cyclic2--1.0.sql
1112

1213
REGRESS = test_extensions test_extdepend
1314

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

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,28 @@ drop cascades to extension test_ext1
3838
CREATE EXTENSION test_ext6;
3939
DROP EXTENSION test_ext6;
4040
CREATE EXTENSION test_ext6;
41+
-- test dropping of member tables that own extensions:
42+
-- this table will be absorbed into test_ext7
43+
create table old_table1 (col1 serial primary key);
44+
create extension test_ext7;
45+
\dx+ test_ext7
46+
Objects in extension "test_ext7"
47+
Object Description
48+
-------------------------------
49+
sequence ext7_table1_col1_seq
50+
sequence ext7_table2_col2_seq
51+
sequence old_table1_col1_seq
52+
table ext7_table1
53+
table ext7_table2
54+
table old_table1
55+
(6 rows)
56+
57+
alter extension test_ext7 update to '2.0';
58+
\dx+ test_ext7
59+
Objects in extension "test_ext7"
60+
Object Description
61+
-------------------------------
62+
sequence ext7_table2_col2_seq
63+
table ext7_table2
64+
(2 rows)
65+

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,11 @@ DROP SCHEMA test_ext CASCADE;
1717
CREATE EXTENSION test_ext6;
1818
DROP EXTENSION test_ext6;
1919
CREATE EXTENSION test_ext6;
20+
21+
-- test dropping of member tables that own extensions:
22+
-- this table will be absorbed into test_ext7
23+
createtableold_table1 (col1serialprimary key);
24+
create extension test_ext7;
25+
\dx+ test_ext7
26+
alter extension test_ext7update to'2.0';
27+
\dx+ test_ext7
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/* src/test/modules/test_extensions/test_ext7--1.0--2.0.sql*/
2+
3+
-- complain if script is sourced in psql, rather than via ALTER EXTENSION
4+
\echo Use"ALTER EXTENSION test_ext7 UPDATE TO '2.0'" to load this file. \quit
5+
6+
-- drop some tables with serial columns
7+
droptable ext7_table1;
8+
droptable old_table1;
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/* src/test/modules/test_extensions/test_ext7--1.0.sql*/
2+
3+
-- complain if script is sourced in psql, rather than via CREATE EXTENSION
4+
\echo Use"CREATE EXTENSION test_ext7" to load this file. \quit
5+
6+
-- link some existing serial-owning table to the extension
7+
alter extension test_ext7 add table old_table1;
8+
alter extension test_ext7 add sequence old_table1_col1_seq;
9+
10+
-- ordinary member tables with serial columns
11+
createtableext7_table1 (col1serialprimary key);
12+
13+
createtableext7_table2 (col2serialprimary key);
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
comment = 'Test extension 7'
2+
default_version = '1.0'
3+
schema = 'public'
4+
relocatable = false

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp