Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
MasaoFujii committed Jul 15, 2024
1 parent 069d0ff commit eece17e
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 3 deletions.
6 changes: 4 additions & 2 deletions doc/src/sgml/ref/alter_table.sgml
Original file line number Diff line number Diff line change
Expand Up @@ -1163,7 +1163,8 @@ WITH ( MODULUS <replaceable class="parameter">numeric_literal</replaceable>, REM
New partitions will have the same table access method as the parent.
If the parent table is persistent then new partitions are created
persistent. If the parent table is temporary then new partitions
are also created temporary.
are also created temporary. New partitions will also be created in
the same tablespace as the parent.
</para>
<note>
<para>
Expand Down Expand Up @@ -1235,7 +1236,8 @@ WITH ( MODULUS <replaceable class="parameter">numeric_literal</replaceable>, REM
The new partition will have the same table access method as the parent.
If the parent table is persistent then the new partition is created
persistent. If the parent table is temporary then the new partition
is also created temporary.
is also created temporary. The new partition will also be created in
the same tablespace as the parent.
</para>
<note>
<para>
Expand Down
2 changes: 1 addition & 1 deletion src/backend/commands/tablecmds.c
Original file line number Diff line number Diff line change
Expand Up @@ -20340,7 +20340,7 @@ createPartitionTable(RangeVar *newPartName, Relation modelRel,
createStmt->constraints = NIL;
createStmt->options = NIL;
createStmt->oncommit = ONCOMMIT_NOOP;
createStmt->tablespacename = NULL;
createStmt->tablespacename = get_tablespace_name(modelRel->rd_rel->reltablespace);
createStmt->if_not_exists = false;
createStmt->accessMethod = get_am_name(modelRel->rd_rel->relam);

Expand Down
23 changes: 23 additions & 0 deletions src/test/regress/expected/partition_merge.out
Original file line number Diff line number Diff line change
Expand Up @@ -861,6 +861,29 @@ SET search_path = partitions_merge_schema, pg_temp, public;
-- Can't merge temporary partitions into a persistent partition
ALTER TABLE t MERGE PARTITIONS (tp_0_1, tp_1_2) INTO tp_0_2;
ROLLBACK;
-- Check the new partition inherits parent's tablespace
CREATE TABLE t (i int PRIMARY KEY USING INDEX TABLESPACE regress_tblspace)
PARTITION BY RANGE (i) TABLESPACE regress_tblspace;
CREATE TABLE tp_0_1 PARTITION OF t FOR VALUES FROM (0) TO (1);
CREATE TABLE tp_1_2 PARTITION OF t FOR VALUES FROM (1) TO (2);
ALTER TABLE t MERGE PARTITIONS (tp_0_1, tp_1_2) INTO tp_0_2;
SELECT tablename, tablespace FROM pg_tables
WHERE tablename IN ('t', 'tp_0_2') ORDER BY tablename, tablespace;
tablename | tablespace
-----------+------------------
t | regress_tblspace
tp_0_2 | regress_tblspace
(2 rows)

SELECT tablename, indexname, tablespace FROM pg_indexes
WHERE tablename IN ('t', 'tp_0_2') ORDER BY tablename, indexname, tablespace;
tablename | indexname | tablespace
-----------+-------------+------------------
t | t_pkey | regress_tblspace
tp_0_2 | tp_0_2_pkey | regress_tblspace
(2 rows)

DROP TABLE t;
-- Check the new partition inherits parent's table access method
SET search_path = partitions_merge_schema, public;
CREATE ACCESS METHOD partitions_merge_heap TYPE TABLE HANDLER heap_tableam_handler;
Expand Down
26 changes: 26 additions & 0 deletions src/test/regress/expected/partition_split.out
Original file line number Diff line number Diff line change
Expand Up @@ -1493,6 +1493,32 @@ SELECT c.oid::pg_catalog.regclass, pg_catalog.pg_get_expr(c.relpartbound, c.oid)
tp_1_2 | FOR VALUES FROM (1) TO (2) | t
(2 rows)

DROP TABLE t;
-- Check the new partitions inherit parent's tablespace
CREATE TABLE t (i int PRIMARY KEY USING INDEX TABLESPACE regress_tblspace)
PARTITION BY RANGE (i) TABLESPACE regress_tblspace;
CREATE TABLE tp_0_2 PARTITION OF t FOR VALUES FROM (0) TO (2);
ALTER TABLE t SPLIT PARTITION tp_0_2 INTO
(PARTITION tp_0_1 FOR VALUES FROM (0) TO (1),
PARTITION tp_1_2 FOR VALUES FROM (1) TO (2));
SELECT tablename, tablespace FROM pg_tables
WHERE tablename IN ('t', 'tp_0_1', 'tp_1_2') ORDER BY tablename, tablespace;
tablename | tablespace
-----------+------------------
t | regress_tblspace
tp_0_1 | regress_tblspace
tp_1_2 | regress_tblspace
(3 rows)

SELECT tablename, indexname, tablespace FROM pg_indexes
WHERE tablename IN ('t', 'tp_0_1', 'tp_1_2') ORDER BY tablename, indexname, tablespace;
tablename | indexname | tablespace
-----------+-------------+------------------
t | t_pkey | regress_tblspace
tp_0_1 | tp_0_1_pkey | regress_tblspace
tp_1_2 | tp_1_2_pkey | regress_tblspace
(3 rows)

DROP TABLE t;
-- Check new partitions inherits parent's table access method
CREATE ACCESS METHOD partition_split_heap TYPE TABLE HANDLER heap_tableam_handler;
Expand Down
12 changes: 12 additions & 0 deletions src/test/regress/sql/partition_merge.sql
Original file line number Diff line number Diff line change
Expand Up @@ -536,6 +536,18 @@ SET search_path = partitions_merge_schema, pg_temp, public;
ALTER TABLE t MERGE PARTITIONS (tp_0_1, tp_1_2) INTO tp_0_2;
ROLLBACK;

-- Check the new partition inherits parent's tablespace
CREATE TABLE t (i int PRIMARY KEY USING INDEX TABLESPACE regress_tblspace)
PARTITION BY RANGE (i) TABLESPACE regress_tblspace;
CREATE TABLE tp_0_1 PARTITION OF t FOR VALUES FROM (0) TO (1);
CREATE TABLE tp_1_2 PARTITION OF t FOR VALUES FROM (1) TO (2);
ALTER TABLE t MERGE PARTITIONS (tp_0_1, tp_1_2) INTO tp_0_2;
SELECT tablename, tablespace FROM pg_tables
WHERE tablename IN ('t', 'tp_0_2') ORDER BY tablename, tablespace;
SELECT tablename, indexname, tablespace FROM pg_indexes
WHERE tablename IN ('t', 'tp_0_2') ORDER BY tablename, indexname, tablespace;
DROP TABLE t;

-- Check the new partition inherits parent's table access method
SET search_path = partitions_merge_schema, public;
CREATE ACCESS METHOD partitions_merge_heap TYPE TABLE HANDLER heap_tableam_handler;
Expand Down
13 changes: 13 additions & 0 deletions src/test/regress/sql/partition_split.sql
Original file line number Diff line number Diff line change
Expand Up @@ -880,6 +880,19 @@ SELECT c.oid::pg_catalog.regclass, pg_catalog.pg_get_expr(c.relpartbound, c.oid)

DROP TABLE t;

-- Check the new partitions inherit parent's tablespace
CREATE TABLE t (i int PRIMARY KEY USING INDEX TABLESPACE regress_tblspace)
PARTITION BY RANGE (i) TABLESPACE regress_tblspace;
CREATE TABLE tp_0_2 PARTITION OF t FOR VALUES FROM (0) TO (2);
ALTER TABLE t SPLIT PARTITION tp_0_2 INTO
(PARTITION tp_0_1 FOR VALUES FROM (0) TO (1),
PARTITION tp_1_2 FOR VALUES FROM (1) TO (2));
SELECT tablename, tablespace FROM pg_tables
WHERE tablename IN ('t', 'tp_0_1', 'tp_1_2') ORDER BY tablename, tablespace;
SELECT tablename, indexname, tablespace FROM pg_indexes
WHERE tablename IN ('t', 'tp_0_1', 'tp_1_2') ORDER BY tablename, indexname, tablespace;
DROP TABLE t;

-- Check new partitions inherits parent's table access method
CREATE ACCESS METHOD partition_split_heap TYPE TABLE HANDLER heap_tableam_handler;
CREATE TABLE t (i int) PARTITION BY RANGE (i) USING partition_split_heap;
Expand Down

0 comments on commit eece17e

Please sign in to comment.