Commit 6476b261 authored by Robert Haas's avatar Robert Haas

On CREATE TABLE, consider skipping validation of subpartitions.

This is just like commit 14f67a8e, but
for 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
parent 14f67a8e
...@@ -953,7 +953,25 @@ check_default_allows_bound(Relation parent, Relation default_rel, ...@@ -953,7 +953,25 @@ check_default_allows_bound(Relation parent, Relation default_rel,
/* Lock already taken above. */ /* Lock already taken above. */
if (part_relid != RelationGetRelid(default_rel)) if (part_relid != RelationGetRelid(default_rel))
{
part_rel = heap_open(part_relid, NoLock); part_rel = heap_open(part_relid, NoLock);
/*
* If the partition constraints on default partition child imply
* that it will not contain any row that would belong to the new
* partition, we can avoid scanning the child table.
*/
if (PartConstraintImpliedByRelConstraint(part_rel,
def_part_constraints))
{
ereport(INFO,
(errmsg("partition constraint for table \"%s\" is implied by existing constraints",
RelationGetRelationName(part_rel))));
heap_close(part_rel, NoLock);
continue;
}
}
else else
part_rel = default_rel; part_rel = default_rel;
......
...@@ -3474,9 +3474,10 @@ DETAIL: "part_5" is already a child of "list_parted2". ...@@ -3474,9 +3474,10 @@ DETAIL: "part_5" is already a child of "list_parted2".
ALTER TABLE list_parted2 ATTACH PARTITION list_parted2 FOR VALUES IN (0); ALTER TABLE list_parted2 ATTACH PARTITION list_parted2 FOR VALUES IN (0);
ERROR: circular inheritance not allowed ERROR: circular inheritance not allowed
DETAIL: "list_parted2" is already a child of "list_parted2". DETAIL: "list_parted2" is already a child of "list_parted2".
-- If the partitioned table being attached does not have a constraint that -- If a partitioned table being created or an existing table being attached
-- would allow validation scan to be skipped, but an individual partition -- as a paritition does not have a constraint that would allow validation scan
-- does, then the partition's validation scan is skipped. -- to be skipped, but an individual partition does, then the partition's
-- validation scan is skipped.
CREATE TABLE quuux (a int, b text) PARTITION BY LIST (a); CREATE TABLE quuux (a int, b text) PARTITION BY LIST (a);
CREATE TABLE quuux_default PARTITION OF quuux DEFAULT PARTITION BY LIST (b); CREATE TABLE quuux_default PARTITION OF quuux DEFAULT PARTITION BY LIST (b);
CREATE TABLE quuux_default1 PARTITION OF quuux_default ( CREATE TABLE quuux_default1 PARTITION OF quuux_default (
...@@ -3487,6 +3488,11 @@ ALTER TABLE quuux ATTACH PARTITION quuux1 FOR VALUES IN (1); -- validate! ...@@ -3487,6 +3488,11 @@ ALTER TABLE quuux ATTACH PARTITION quuux1 FOR VALUES IN (1); -- validate!
CREATE TABLE quuux2 (a int, b text); CREATE TABLE quuux2 (a int, b text);
ALTER TABLE quuux ATTACH PARTITION quuux2 FOR VALUES IN (2); -- skip validation ALTER TABLE quuux ATTACH PARTITION quuux2 FOR VALUES IN (2); -- skip validation
INFO: updated partition constraint for default partition "quuux_default1" is implied by existing constraints INFO: updated partition constraint for default partition "quuux_default1" is implied by existing constraints
DROP TABLE quuux1, quuux2;
-- should validate for quuux1, but not for quuux2
CREATE TABLE quuux1 PARTITION OF quuux FOR VALUES IN (1);
CREATE TABLE quuux2 PARTITION OF quuux FOR VALUES IN (2);
INFO: partition constraint for table "quuux_default1" is implied by existing constraints
DROP TABLE quuux; DROP TABLE quuux;
-- --
-- DETACH PARTITION -- DETACH PARTITION
......
...@@ -2285,9 +2285,10 @@ ALTER TABLE list_parted2 ATTACH PARTITION part_2 FOR VALUES IN (2); ...@@ -2285,9 +2285,10 @@ ALTER TABLE list_parted2 ATTACH PARTITION part_2 FOR VALUES IN (2);
ALTER TABLE part_5 ATTACH PARTITION list_parted2 FOR VALUES IN ('b'); ALTER TABLE part_5 ATTACH PARTITION list_parted2 FOR VALUES IN ('b');
ALTER TABLE list_parted2 ATTACH PARTITION list_parted2 FOR VALUES IN (0); ALTER TABLE list_parted2 ATTACH PARTITION list_parted2 FOR VALUES IN (0);
-- If the partitioned table being attached does not have a constraint that -- If a partitioned table being created or an existing table being attached
-- would allow validation scan to be skipped, but an individual partition -- as a paritition does not have a constraint that would allow validation scan
-- does, then the partition's validation scan is skipped. -- to be skipped, but an individual partition does, then the partition's
-- validation scan is skipped.
CREATE TABLE quuux (a int, b text) PARTITION BY LIST (a); CREATE TABLE quuux (a int, b text) PARTITION BY LIST (a);
CREATE TABLE quuux_default PARTITION OF quuux DEFAULT PARTITION BY LIST (b); CREATE TABLE quuux_default PARTITION OF quuux DEFAULT PARTITION BY LIST (b);
CREATE TABLE quuux_default1 PARTITION OF quuux_default ( CREATE TABLE quuux_default1 PARTITION OF quuux_default (
...@@ -2297,6 +2298,10 @@ CREATE TABLE quuux1 (a int, b text); ...@@ -2297,6 +2298,10 @@ CREATE TABLE quuux1 (a int, b text);
ALTER TABLE quuux ATTACH PARTITION quuux1 FOR VALUES IN (1); -- validate! ALTER TABLE quuux ATTACH PARTITION quuux1 FOR VALUES IN (1); -- validate!
CREATE TABLE quuux2 (a int, b text); CREATE TABLE quuux2 (a int, b text);
ALTER TABLE quuux ATTACH PARTITION quuux2 FOR VALUES IN (2); -- skip validation ALTER TABLE quuux ATTACH PARTITION quuux2 FOR VALUES IN (2); -- skip validation
DROP TABLE quuux1, quuux2;
-- should validate for quuux1, but not for quuux2
CREATE TABLE quuux1 PARTITION OF quuux FOR VALUES IN (1);
CREATE TABLE quuux2 PARTITION OF quuux FOR VALUES IN (2);
DROP TABLE quuux; DROP TABLE quuux;
-- --
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment