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

Commit6476b26

Browse files
committed
On CREATE TABLE, consider skipping validation of subpartitions.
This is just like commit14f67a8, butfor CREATE PARTITION rather than ATTACH PARTITION.Jeevan Ladhe, with test case changes by me.Discussion:http://postgr.es/m/CAOgcT0MWwG8WBw8frFMtRYHAgDD=tpt6U7WcsO_L2k0KYpm4Jg@mail.gmail.com
1 parent14f67a8 commit6476b26

File tree

3 files changed

+35
-6
lines changed

3 files changed

+35
-6
lines changed

‎src/backend/catalog/partition.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -953,7 +953,25 @@ check_default_allows_bound(Relation parent, Relation default_rel,
953953

954954
/* Lock already taken above. */
955955
if (part_relid!=RelationGetRelid(default_rel))
956+
{
956957
part_rel=heap_open(part_relid,NoLock);
958+
959+
/*
960+
* If the partition constraints on default partition child imply
961+
* that it will not contain any row that would belong to the new
962+
* partition, we can avoid scanning the child table.
963+
*/
964+
if (PartConstraintImpliedByRelConstraint(part_rel,
965+
def_part_constraints))
966+
{
967+
ereport(INFO,
968+
(errmsg("partition constraint for table \"%s\" is implied by existing constraints",
969+
RelationGetRelationName(part_rel))));
970+
971+
heap_close(part_rel,NoLock);
972+
continue;
973+
}
974+
}
957975
else
958976
part_rel=default_rel;
959977

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

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3474,9 +3474,10 @@ DETAIL: "part_5" is already a child of "list_parted2".
34743474
ALTER TABLE list_parted2 ATTACH PARTITION list_parted2 FOR VALUES IN (0);
34753475
ERROR: circular inheritance not allowed
34763476
DETAIL: "list_parted2" is already a child of "list_parted2".
3477-
-- If the partitioned table being attached does not have a constraint that
3478-
-- would allow validation scan to be skipped, but an individual partition
3479-
-- does, then the partition's validation scan is skipped.
3477+
-- If a partitioned table being created or an existing table being attached
3478+
-- as a paritition does not have a constraint that would allow validation scan
3479+
-- to be skipped, but an individual partition does, then the partition's
3480+
-- validation scan is skipped.
34803481
CREATE TABLE quuux (a int, b text) PARTITION BY LIST (a);
34813482
CREATE TABLE quuux_default PARTITION OF quuux DEFAULT PARTITION BY LIST (b);
34823483
CREATE TABLE quuux_default1 PARTITION OF quuux_default (
@@ -3487,6 +3488,11 @@ ALTER TABLE quuux ATTACH PARTITION quuux1 FOR VALUES IN (1); -- validate!
34873488
CREATE TABLE quuux2 (a int, b text);
34883489
ALTER TABLE quuux ATTACH PARTITION quuux2 FOR VALUES IN (2); -- skip validation
34893490
INFO: updated partition constraint for default partition "quuux_default1" is implied by existing constraints
3491+
DROP TABLE quuux1, quuux2;
3492+
-- should validate for quuux1, but not for quuux2
3493+
CREATE TABLE quuux1 PARTITION OF quuux FOR VALUES IN (1);
3494+
CREATE TABLE quuux2 PARTITION OF quuux FOR VALUES IN (2);
3495+
INFO: partition constraint for table "quuux_default1" is implied by existing constraints
34903496
DROP TABLE quuux;
34913497
--
34923498
-- DETACH PARTITION

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

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2285,9 +2285,10 @@ ALTER TABLE list_parted2 ATTACH PARTITION part_2 FOR VALUES IN (2);
22852285
ALTERTABLE part_5 ATTACH PARTITION list_parted2 FORVALUESIN ('b');
22862286
ALTERTABLE list_parted2 ATTACH PARTITION list_parted2 FORVALUESIN (0);
22872287

2288-
-- If the partitioned table being attached does not have a constraint that
2289-
-- would allow validation scan to be skipped, but an individual partition
2290-
-- does, then the partition's validation scan is skipped.
2288+
-- If a partitioned table being created or an existing table being attached
2289+
-- as a paritition does not have a constraint that would allow validation scan
2290+
-- to be skipped, but an individual partition does, then the partition's
2291+
-- validation scan is skipped.
22912292
CREATETABLEquuux (aint, btext) PARTITION BY LIST (a);
22922293
CREATETABLEquuux_default PARTITION OF quuux DEFAULT PARTITION BY LIST (b);
22932294
CREATETABLEquuux_default1 PARTITION OF quuux_default (
@@ -2297,6 +2298,10 @@ CREATE TABLE quuux1 (a int, b text);
22972298
ALTERTABLE quuux ATTACH PARTITION quuux1 FORVALUESIN (1);-- validate!
22982299
CREATETABLEquuux2 (aint, btext);
22992300
ALTERTABLE quuux ATTACH PARTITION quuux2 FORVALUESIN (2);-- skip validation
2301+
DROPTABLE quuux1, quuux2;
2302+
-- should validate for quuux1, but not for quuux2
2303+
CREATETABLEquuux1 PARTITION OF quuux FORVALUESIN (1);
2304+
CREATETABLEquuux2 PARTITION OF quuux FORVALUESIN (2);
23002305
DROPTABLE quuux;
23012306

23022307
--

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp