mirror of
https://github.com/postgres/postgres.git
synced 2025-07-07 00:36:50 +03:00
Fix tablespace handling for partitioned tables
When partitioned tables were introduced, we failed to realize that by
copying the tablespace handling for other relation kinds with no
physical storage we were causing the secondary effect that their
partitions would not automatically inherit the tablespace setting. This
is surprising and unhelpful, so change it to adopt the behavior
introduced in pg11 (commit 33e6c34c32
) for partitioned indexes: the
parent relation remembers the tablespace specification, which is then
used for any new partitions that don't declare one.
Because this commit changes behavior of the TABLESPACE clause for
partitioned tables (it's no longer a no-op), it is not backpatched.
Author: David Rowley, Álvaro Herrera
Reviewed-by: Michael Paquier
Discussion: https://postgr.es/m/CAKJS1f9SxVzqDrGD1teosFd6jBMM0UEaa14_8mRvcWE19Tu0hA@mail.gmail.com
This commit is contained in:
@ -44,6 +44,18 @@ CREATE INDEX foo_idx on testschema.foo(i) TABLESPACE regress_tblspace;
|
||||
SELECT relname, spcname FROM pg_catalog.pg_tablespace t, pg_catalog.pg_class c
|
||||
where c.reltablespace = t.oid AND c.relname = 'foo_idx';
|
||||
|
||||
-- partitioned table
|
||||
CREATE TABLE testschema.part (a int) PARTITION BY LIST (a);
|
||||
CREATE TABLE testschema.part12 PARTITION OF testschema.part FOR VALUES IN(1,2) PARTITION BY LIST (a) TABLESPACE regress_tblspace;
|
||||
CREATE TABLE testschema.part12_1 PARTITION OF testschema.part12 FOR VALUES IN (1);
|
||||
ALTER TABLE testschema.part12 SET TABLESPACE pg_default;
|
||||
CREATE TABLE testschema.part12_2 PARTITION OF testschema.part12 FOR VALUES IN (2);
|
||||
-- Ensure part12_1 defaulted to regress_tblspace and part12_2 defaulted to pg_default.
|
||||
SELECT relname, spcname FROM pg_catalog.pg_class c
|
||||
LEFT JOIN pg_catalog.pg_tablespace t ON c.reltablespace = t.oid
|
||||
where c.relname LIKE 'part%' order by relname;
|
||||
DROP TABLE testschema.part;
|
||||
|
||||
-- partitioned index
|
||||
CREATE TABLE testschema.part (a int) PARTITION BY LIST (a);
|
||||
CREATE TABLE testschema.part1 PARTITION OF testschema.part FOR VALUES IN (1);
|
||||
|
@ -61,6 +61,25 @@ SELECT relname, spcname FROM pg_catalog.pg_tablespace t, pg_catalog.pg_class c
|
||||
foo_idx | regress_tblspace
|
||||
(1 row)
|
||||
|
||||
-- partitioned table
|
||||
CREATE TABLE testschema.part (a int) PARTITION BY LIST (a);
|
||||
CREATE TABLE testschema.part12 PARTITION OF testschema.part FOR VALUES IN(1,2) PARTITION BY LIST (a) TABLESPACE regress_tblspace;
|
||||
CREATE TABLE testschema.part12_1 PARTITION OF testschema.part12 FOR VALUES IN (1);
|
||||
ALTER TABLE testschema.part12 SET TABLESPACE pg_default;
|
||||
CREATE TABLE testschema.part12_2 PARTITION OF testschema.part12 FOR VALUES IN (2);
|
||||
-- Ensure part12_1 defaulted to regress_tblspace and part12_2 defaulted to pg_default.
|
||||
SELECT relname, spcname FROM pg_catalog.pg_class c
|
||||
LEFT JOIN pg_catalog.pg_tablespace t ON c.reltablespace = t.oid
|
||||
where c.relname LIKE 'part%' order by relname;
|
||||
relname | spcname
|
||||
----------+------------------
|
||||
part |
|
||||
part12 |
|
||||
part12_1 | regress_tblspace
|
||||
part12_2 |
|
||||
(4 rows)
|
||||
|
||||
DROP TABLE testschema.part;
|
||||
-- partitioned index
|
||||
CREATE TABLE testschema.part (a int) PARTITION BY LIST (a);
|
||||
CREATE TABLE testschema.part1 PARTITION OF testschema.part FOR VALUES IN (1);
|
||||
|
Reference in New Issue
Block a user