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

Commit14f67a8

Browse files
committed
On attach, consider skipping validation of subpartitions individually.
If the table attached as a partition is itself partitioned, individualpartitions might have constraints strong enough to skip scanning thetable even if the table actually attached does not. This is prettycheap to check, and possibly a big win if it works out.Amit Langote, with test case changes by me.Discussion:http://postgr.es/m/1f08b844-0078-aa8d-452e-7af3bf77d05f@lab.ntt.co.jp
1 parentc31e9d4 commit14f67a8

File tree

3 files changed

+43
-0
lines changed

3 files changed

+43
-0
lines changed

‎src/backend/commands/tablecmds.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13683,6 +13683,21 @@ ValidatePartitionConstraints(List **wqueue, Relation scanrel,
1368313683
/* There can never be a whole-row reference here */
1368413684
if (found_whole_row)
1368513685
elog(ERROR,"unexpected whole-row reference found in partition key");
13686+
13687+
/* Can we skip scanning this part_rel? */
13688+
if (PartConstraintImpliedByRelConstraint(part_rel,my_partconstr))
13689+
{
13690+
if (!validate_default)
13691+
ereport(INFO,
13692+
(errmsg("partition constraint for table \"%s\" is implied by existing constraints",
13693+
RelationGetRelationName(part_rel))));
13694+
else
13695+
ereport(INFO,
13696+
(errmsg("updated partition constraint for default partition \"%s\" is implied by existing constraints",
13697+
RelationGetRelationName(part_rel))));
13698+
heap_close(part_rel,NoLock);
13699+
continue;
13700+
}
1368613701
}
1368713702

1368813703
/* Grab a work queue entry. */

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3474,6 +3474,20 @@ 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.
3480+
CREATE TABLE quuux (a int, b text) PARTITION BY LIST (a);
3481+
CREATE TABLE quuux_default PARTITION OF quuux DEFAULT PARTITION BY LIST (b);
3482+
CREATE TABLE quuux_default1 PARTITION OF quuux_default (
3483+
CONSTRAINT check_1 CHECK (a IS NOT NULL AND a = 1)
3484+
) FOR VALUES IN ('b');
3485+
CREATE TABLE quuux1 (a int, b text);
3486+
ALTER TABLE quuux ATTACH PARTITION quuux1 FOR VALUES IN (1); -- validate!
3487+
CREATE TABLE quuux2 (a int, b text);
3488+
ALTER TABLE quuux ATTACH PARTITION quuux2 FOR VALUES IN (2); -- skip validation
3489+
INFO: updated partition constraint for default partition "quuux_default1" is implied by existing constraints
3490+
DROP TABLE quuux;
34773491
--
34783492
-- DETACH PARTITION
34793493
--

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2285,6 +2285,20 @@ 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.
2291+
CREATETABLEquuux (aint, btext) PARTITION BY LIST (a);
2292+
CREATETABLEquuux_default PARTITION OF quuux DEFAULT PARTITION BY LIST (b);
2293+
CREATETABLEquuux_default1 PARTITION OF quuux_default (
2294+
CONSTRAINT check_1CHECK (aIS NOT NULLAND a=1)
2295+
) FORVALUESIN ('b');
2296+
CREATETABLEquuux1 (aint, btext);
2297+
ALTERTABLE quuux ATTACH PARTITION quuux1 FORVALUESIN (1);-- validate!
2298+
CREATETABLEquuux2 (aint, btext);
2299+
ALTERTABLE quuux ATTACH PARTITION quuux2 FORVALUESIN (2);-- skip validation
2300+
DROPTABLE quuux;
2301+
22882302
--
22892303
-- DETACH PARTITION
22902304
--

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp