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

Commit8b4d582

Browse files
Allow partitioned tables to be dropped without CASCADE
Record partitioned table dependencies as DEPENDENCY_AUTOrather than DEPENDENCY_NORMAL, so that DROP TABLE just works.Remove all the tests for partitioned tables where earlierwork had deliberately avoided using CASCADE.Amit Langote, reviewed by Ashutosh Bapat and myself
1 parentdbca84f commit8b4d582

File tree

11 files changed

+44
-73
lines changed

11 files changed

+44
-73
lines changed

‎src/backend/commands/tablecmds.c

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -289,9 +289,11 @@ static List *MergeAttributes(List *schema, List *supers, char relpersistence,
289289
staticboolMergeCheckConstraint(List*constraints,char*name,Node*expr);
290290
staticvoidMergeAttributesIntoExisting(Relationchild_rel,Relationparent_rel);
291291
staticvoidMergeConstraintsIntoExisting(Relationchild_rel,Relationparent_rel);
292-
staticvoidStoreCatalogInheritance(OidrelationId,List*supers);
292+
staticvoidStoreCatalogInheritance(OidrelationId,List*supers,
293+
boolchild_is_partition);
293294
staticvoidStoreCatalogInheritance1(OidrelationId,OidparentOid,
294-
int16seqNumber,RelationinhRelation);
295+
int16seqNumber,RelationinhRelation,
296+
boolchild_is_partition);
295297
staticintfindAttrByName(constchar*attributeName,List*schema);
296298
staticvoidAlterIndexNamespaces(RelationclassRel,Relationrel,
297299
OidoldNspOid,OidnewNspOid,ObjectAddresses*objsMoved);
@@ -725,7 +727,7 @@ DefineRelation(CreateStmt *stmt, char relkind, Oid ownerId,
725727
typaddress);
726728

727729
/* Store inheritance information for new rel. */
728-
StoreCatalogInheritance(relationId,inheritOids);
730+
StoreCatalogInheritance(relationId,inheritOids,stmt->partbound!=NULL);
729731

730732
/*
731733
* We must bump the command counter to make the newly-created relation
@@ -2248,7 +2250,8 @@ MergeCheckConstraint(List *constraints, char *name, Node *expr)
22482250
* supers is a list of the OIDs of the new relation's direct ancestors.
22492251
*/
22502252
staticvoid
2251-
StoreCatalogInheritance(OidrelationId,List*supers)
2253+
StoreCatalogInheritance(OidrelationId,List*supers,
2254+
boolchild_is_partition)
22522255
{
22532256
Relationrelation;
22542257
int16seqNumber;
@@ -2278,7 +2281,8 @@ StoreCatalogInheritance(Oid relationId, List *supers)
22782281
{
22792282
OidparentOid=lfirst_oid(entry);
22802283

2281-
StoreCatalogInheritance1(relationId,parentOid,seqNumber,relation);
2284+
StoreCatalogInheritance1(relationId,parentOid,seqNumber,relation,
2285+
child_is_partition);
22822286
seqNumber++;
22832287
}
22842288

@@ -2291,7 +2295,8 @@ StoreCatalogInheritance(Oid relationId, List *supers)
22912295
*/
22922296
staticvoid
22932297
StoreCatalogInheritance1(OidrelationId,OidparentOid,
2294-
int16seqNumber,RelationinhRelation)
2298+
int16seqNumber,RelationinhRelation,
2299+
boolchild_is_partition)
22952300
{
22962301
TupleDescdesc=RelationGetDescr(inhRelation);
22972302
Datumvalues[Natts_pg_inherits];
@@ -2325,7 +2330,14 @@ StoreCatalogInheritance1(Oid relationId, Oid parentOid,
23252330
childobject.objectId=relationId;
23262331
childobject.objectSubId=0;
23272332

2328-
recordDependencyOn(&childobject,&parentobject,DEPENDENCY_NORMAL);
2333+
/*
2334+
* Partition tables are expected to be dropped when the parent partitioned
2335+
* table gets dropped.
2336+
*/
2337+
if (child_is_partition)
2338+
recordDependencyOn(&childobject,&parentobject,DEPENDENCY_AUTO);
2339+
else
2340+
recordDependencyOn(&childobject,&parentobject,DEPENDENCY_NORMAL);
23292341

23302342
/*
23312343
* Post creation hook of this inheritance. Since object_access_hook
@@ -10753,7 +10765,9 @@ CreateInheritance(Relation child_rel, Relation parent_rel)
1075310765
StoreCatalogInheritance1(RelationGetRelid(child_rel),
1075410766
RelationGetRelid(parent_rel),
1075510767
inhseqno+1,
10756-
catalogRelation);
10768+
catalogRelation,
10769+
parent_rel->rd_rel->relkind==
10770+
RELKIND_PARTITIONED_TABLE);
1075710771

1075810772
/* Now we're done with pg_inherits */
1075910773
heap_close(catalogRelation,RowExclusiveLock);

‎src/test/regress/expected/alter_table.out

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3339,10 +3339,8 @@ ALTER TABLE list_parted2 DROP COLUMN b;
33393339
ERROR: cannot drop column named in partition key
33403340
ALTER TABLE list_parted2 ALTER COLUMN b TYPE text;
33413341
ERROR: cannot alter type of column named in partition key
3342-
-- cleanup: avoid using CASCADE
3343-
DROP TABLE list_parted, part_1;
3344-
DROP TABLE list_parted2, part_2, part_5, part_5_a;
3345-
DROP TABLE range_parted, part1, part2;
3342+
-- cleanup
3343+
DROP TABLE list_parted, list_parted2, range_parted;
33463344
-- more tests for certain multi-level partitioning scenarios
33473345
create table p (a int, b int) partition by range (a, b);
33483346
create table p1 (b int, a int not null) partition by range (b);
@@ -3371,5 +3369,5 @@ insert into p1 (a, b) values (2, 3);
33713369
-- check that partition validation scan correctly detects violating rows
33723370
alter table p attach partition p1 for values from (1, 2) to (1, 10);
33733371
ERROR: partition constraint is violated by some row
3374-
-- cleanup: avoid using CASCADE
3375-
drop table p, p1, p11;
3372+
-- cleanup
3373+
drop table p;

‎src/test/regress/expected/create_table.out

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -667,10 +667,5 @@ Check constraints:
667667
"check_a" CHECK (length(a) > 0)
668668
Number of partitions: 3 (Use \d+ to list them.)
669669

670-
-- cleanup: avoid using CASCADE
671-
DROP TABLE parted, part_a, part_b, part_c, part_c_1_10;
672-
DROP TABLE list_parted, part_1, part_2, part_null;
673-
DROP TABLE range_parted;
674-
DROP TABLE list_parted2, part_ab, part_null_z;
675-
DROP TABLE range_parted2, part0, part1, part2, part3;
676-
DROP TABLE range_parted3, part00, part10, part11, part12;
670+
-- cleanup
671+
DROP TABLE parted, list_parted, range_parted, list_parted2, range_parted2, range_parted3;

‎src/test/regress/expected/inherit.out

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1843,23 +1843,5 @@ explain (costs off) select * from range_list_parted where a >= 30;
18431843
Filter: (a >= 30)
18441844
(11 rows)
18451845

1846-
drop table list_parted cascade;
1847-
NOTICE: drop cascades to 3 other objects
1848-
DETAIL: drop cascades to table part_ab_cd
1849-
drop cascades to table part_ef_gh
1850-
drop cascades to table part_null_xy
1851-
drop table range_list_parted cascade;
1852-
NOTICE: drop cascades to 13 other objects
1853-
DETAIL: drop cascades to table part_1_10
1854-
drop cascades to table part_1_10_ab
1855-
drop cascades to table part_1_10_cd
1856-
drop cascades to table part_10_20
1857-
drop cascades to table part_10_20_ab
1858-
drop cascades to table part_10_20_cd
1859-
drop cascades to table part_21_30
1860-
drop cascades to table part_21_30_ab
1861-
drop cascades to table part_21_30_cd
1862-
drop cascades to table part_40_inf
1863-
drop cascades to table part_40_inf_ab
1864-
drop cascades to table part_40_inf_cd
1865-
drop cascades to table part_40_inf_null
1846+
drop table list_parted;
1847+
drop table range_list_parted;

‎src/test/regress/expected/insert.out

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -314,10 +314,7 @@ select tableoid::regclass::text, a, min(b) as min_b, max(b) as max_b from list_p
314314
(9 rows)
315315

316316
-- cleanup
317-
drop table part1, part2, part3, part4, range_parted;
318-
drop table part_ee_ff3_1, part_ee_ff3_2, part_ee_ff1, part_ee_ff2, part_ee_ff3;
319-
drop table part_ee_ff, part_gg2_2, part_gg2_1, part_gg2, part_gg1, part_gg;
320-
drop table part_aa_bb, part_cc_dd, part_null, list_parted;
317+
drop table range_parted, list_parted;
321318
-- more tests for certain multi-level partitioning scenarios
322319
create table p (a int, b int) partition by range (a, b);
323320
create table p1 (b int not null, a int not null) partition by range ((b+0));
@@ -417,4 +414,4 @@ revoke all on key_desc_1 from someone_else;
417414
drop role someone_else;
418415
drop table key_desc, key_desc_1;
419416
-- cleanup
420-
drop table p, p1, p11, p12, p2, p3, p4;
417+
drop table p;

‎src/test/regress/expected/update.out

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -219,9 +219,4 @@ DETAIL: Failing row contains (b, 9).
219219
-- ok
220220
update range_parted set b = b + 1 where b = 10;
221221
-- cleanup
222-
drop table range_parted cascade;
223-
NOTICE: drop cascades to 4 other objects
224-
DETAIL: drop cascades to table part_a_1_a_10
225-
drop cascades to table part_a_10_a_20
226-
drop cascades to table part_b_1_b_10
227-
drop cascades to table part_b_10_b_20
222+
drop table range_parted;

‎src/test/regress/sql/alter_table.sql

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2199,10 +2199,8 @@ ALTER TABLE part_2 INHERIT inh_test;
21992199
ALTERTABLE list_parted2 DROP COLUMN b;
22002200
ALTERTABLE list_parted2 ALTER COLUMN b TYPEtext;
22012201

2202-
-- cleanup: avoid using CASCADE
2203-
DROPTABLE list_parted, part_1;
2204-
DROPTABLE list_parted2, part_2, part_5, part_5_a;
2205-
DROPTABLE range_parted, part1, part2;
2202+
-- cleanup
2203+
DROPTABLE list_parted, list_parted2, range_parted;
22062204

22072205
-- more tests for certain multi-level partitioning scenarios
22082206
createtablep (aint, bint) partition by range (a, b);
@@ -2227,5 +2225,5 @@ insert into p1 (a, b) values (2, 3);
22272225
-- check that partition validation scan correctly detects violating rows
22282226
altertable p attach partition p1 forvaluesfrom (1,2) to (1,10);
22292227

2230-
-- cleanup: avoid using CASCADE
2231-
droptable p, p1, p11;
2228+
-- cleanup
2229+
droptable p;

‎src/test/regress/sql/create_table.sql

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -595,10 +595,5 @@ CREATE TABLE part_c_1_10 PARTITION OF part_c FOR VALUES FROM (1) TO (10);
595595
-- returned.
596596
\d parted
597597

598-
-- cleanup: avoid using CASCADE
599-
DROPTABLE parted, part_a, part_b, part_c, part_c_1_10;
600-
DROPTABLE list_parted, part_1, part_2, part_null;
601-
DROPTABLE range_parted;
602-
DROPTABLE list_parted2, part_ab, part_null_z;
603-
DROPTABLE range_parted2, part0, part1, part2, part3;
604-
DROPTABLE range_parted3, part00, part10, part11, part12;
598+
-- cleanup
599+
DROPTABLE parted, list_parted, range_parted, list_parted2, range_parted2, range_parted3;

‎src/test/regress/sql/inherit.sql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -612,5 +612,5 @@ explain (costs off) select * from range_list_parted where b is null;
612612
explain (costs off)select*from range_list_partedwhere ais not nulland a<67;
613613
explain (costs off)select*from range_list_partedwhere a>=30;
614614

615-
droptable list_parted cascade;
616-
droptable range_list_parted cascade;
615+
droptable list_parted;
616+
droptable range_list_parted;

‎src/test/regress/sql/insert.sql

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -186,10 +186,7 @@ insert into list_parted (b) values (1);
186186
select tableoid::regclass::text, a,min(b)as min_b,max(b)as max_bfrom list_partedgroup by1,2order by1;
187187

188188
-- cleanup
189-
droptable part1, part2, part3, part4, range_parted;
190-
droptable part_ee_ff3_1, part_ee_ff3_2, part_ee_ff1, part_ee_ff2, part_ee_ff3;
191-
droptable part_ee_ff, part_gg2_2, part_gg2_1, part_gg2, part_gg1, part_gg;
192-
droptable part_aa_bb, part_cc_dd, part_null, list_parted;
189+
droptable range_parted, list_parted;
193190

194191
-- more tests for certain multi-level partitioning scenarios
195192
createtablep (aint, bint) partition by range (a, b);
@@ -271,4 +268,4 @@ drop role someone_else;
271268
droptable key_desc, key_desc_1;
272269

273270
-- cleanup
274-
droptable p, p1, p11, p12, p2, p3, p4;
271+
droptable p;

‎src/test/regress/sql/update.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,4 +126,4 @@ update range_parted set b = b - 1 where b = 10;
126126
update range_partedset b= b+1where b=10;
127127

128128
-- cleanup
129-
droptable range_parted cascade;
129+
droptable range_parted;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp