Skip to content

Commit c48c2b2

Browse files
feodorarssher
authored andcommitted
PGPRO-3087 Prevent double expand partitioned table by built-in
inheritance and pg_pathman's one
1 parent c14d2ad commit c48c2b2

File tree

3 files changed

+35
-3
lines changed

3 files changed

+35
-3
lines changed

Diff for: expected/pathman_basic.out

+19-1
Original file line numberDiff line numberDiff line change
@@ -1804,7 +1804,25 @@ ORDER BY partition;
18041804

18051805
DROP TABLE test.provided_part_names CASCADE;
18061806
NOTICE: drop cascades to 2 other objects
1807+
/* test preventing of double expand of inherited tables */
1808+
CREATE TABLE test.mixinh_parent (id INT PRIMARY KEY);
1809+
CREATE TABLE test.mixinh_child1 () INHERITS (test.mixinh_parent);
1810+
SELECT create_range_partitions('test.mixinh_child1', 'id', 1, 10, 1);
1811+
create_range_partitions
1812+
-------------------------
1813+
1
1814+
(1 row)
1815+
1816+
INSERT INTO test.mixinh_child1 VALUES (1);
1817+
SELECT * FROM test.mixinh_child1;
1818+
id
1819+
----
1820+
1
1821+
(1 row)
1822+
1823+
SELECT * FROM test.mixinh_parent;
1824+
ERROR: could not expand partitioned table "mixinh_child1"
18071825
DROP SCHEMA test CASCADE;
1808-
NOTICE: drop cascades to 28 other objects
1826+
NOTICE: drop cascades to 32 other objects
18091827
DROP EXTENSION pg_pathman CASCADE;
18101828
DROP SCHEMA pathman CASCADE;

Diff for: sql/pathman_basic.sql

+8
Original file line numberDiff line numberDiff line change
@@ -546,6 +546,14 @@ ORDER BY partition;
546546

547547
DROP TABLE test.provided_part_names CASCADE;
548548

549+
/* test preventing of double expand of inherited tables */
550+
CREATE TABLE test.mixinh_parent (id INT PRIMARY KEY);
551+
CREATE TABLE test.mixinh_child1 () INHERITS (test.mixinh_parent);
552+
SELECT create_range_partitions('test.mixinh_child1', 'id', 1, 10, 1);
553+
INSERT INTO test.mixinh_child1 VALUES (1);
554+
SELECT * FROM test.mixinh_child1;
555+
SELECT * FROM test.mixinh_parent;
556+
549557
DROP SCHEMA test CASCADE;
550558
DROP EXTENSION pg_pathman CASCADE;
551559
DROP SCHEMA pathman CASCADE;

Diff for: src/hooks.c

+8-2
Original file line numberDiff line numberDiff line change
@@ -406,10 +406,16 @@ pathman_rel_pathlist_hook(PlannerInfo *root,
406406
* and added its children to the plan.
407407
*/
408408
if (appinfo->child_relid == rti &&
409-
child_oid == parent_oid &&
410409
OidIsValid(appinfo->parent_reloid))
411410
{
412-
goto cleanup;
411+
if (child_oid == parent_oid)
412+
goto cleanup;
413+
else if (!has_pathman_relation_info(parent_oid))
414+
ereport(ERROR,
415+
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
416+
errmsg("could not expand partitioned table \"%s\"",
417+
get_rel_name(child_oid)),
418+
errhint("Do not use inheritance and pg_pathman partitions together")));
413419
}
414420
}
415421
}

0 commit comments

Comments
 (0)