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

Commitc086896

Browse files
committed
Fix tablespace handling in MERGE/SPLIT partition commands.
As commitca41030 stated, new partitions without a specified tablespaceshould inherit the parent relation's tablespace. However, previously,ALTER TABLE MERGE PARTITIONS and ALTER TABLE SPLIT PARTITION commandsalways created new partitions in the default tablespace, ignoringthe parent's tablespace. This commit ensures new partitions inheritthe parent's tablespace.Backpatch to v17 where these commands were introduced.Author: Fujii MasaoReviewed-by: Masahiko SawadaDiscussion:https://postgr.es/m/abaf390b-3320-40a5-8815-ef476db5cfe7@oss.nttdata.com
1 parent069d0ff commitc086896

File tree

6 files changed

+79
-3
lines changed

6 files changed

+79
-3
lines changed

‎doc/src/sgml/ref/alter_table.sgml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1163,7 +1163,8 @@ WITH ( MODULUS <replaceable class="parameter">numeric_literal</replaceable>, REM
11631163
New partitions will have the same table access method as the parent.
11641164
If the parent table is persistent then new partitions are created
11651165
persistent. If the parent table is temporary then new partitions
1166-
are also created temporary.
1166+
are also created temporary. New partitions will also be created in
1167+
the same tablespace as the parent.
11671168
</para>
11681169
<note>
11691170
<para>
@@ -1235,7 +1236,8 @@ WITH ( MODULUS <replaceable class="parameter">numeric_literal</replaceable>, REM
12351236
The new partition will have the same table access method as the parent.
12361237
If the parent table is persistent then the new partition is created
12371238
persistent. If the parent table is temporary then the new partition
1238-
is also created temporary.
1239+
is also created temporary. The new partition will also be created in
1240+
the same tablespace as the parent.
12391241
</para>
12401242
<note>
12411243
<para>

‎src/backend/commands/tablecmds.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20340,7 +20340,7 @@ createPartitionTable(RangeVar *newPartName, Relation modelRel,
2034020340
createStmt->constraints = NIL;
2034120341
createStmt->options = NIL;
2034220342
createStmt->oncommit = ONCOMMIT_NOOP;
20343-
createStmt->tablespacename =NULL;
20343+
createStmt->tablespacename =get_tablespace_name(modelRel->rd_rel->reltablespace);
2034420344
createStmt->if_not_exists = false;
2034520345
createStmt->accessMethod = get_am_name(modelRel->rd_rel->relam);
2034620346

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

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -861,6 +861,29 @@ SET search_path = partitions_merge_schema, pg_temp, public;
861861
-- Can't merge temporary partitions into a persistent partition
862862
ALTER TABLE t MERGE PARTITIONS (tp_0_1, tp_1_2) INTO tp_0_2;
863863
ROLLBACK;
864+
-- Check the new partition inherits parent's tablespace
865+
CREATE TABLE t (i int PRIMARY KEY USING INDEX TABLESPACE regress_tblspace)
866+
PARTITION BY RANGE (i) TABLESPACE regress_tblspace;
867+
CREATE TABLE tp_0_1 PARTITION OF t FOR VALUES FROM (0) TO (1);
868+
CREATE TABLE tp_1_2 PARTITION OF t FOR VALUES FROM (1) TO (2);
869+
ALTER TABLE t MERGE PARTITIONS (tp_0_1, tp_1_2) INTO tp_0_2;
870+
SELECT tablename, tablespace FROM pg_tables
871+
WHERE tablename IN ('t', 'tp_0_2') ORDER BY tablename, tablespace;
872+
tablename | tablespace
873+
-----------+------------------
874+
t | regress_tblspace
875+
tp_0_2 | regress_tblspace
876+
(2 rows)
877+
878+
SELECT tablename, indexname, tablespace FROM pg_indexes
879+
WHERE tablename IN ('t', 'tp_0_2') ORDER BY tablename, indexname, tablespace;
880+
tablename | indexname | tablespace
881+
-----------+-------------+------------------
882+
t | t_pkey | regress_tblspace
883+
tp_0_2 | tp_0_2_pkey | regress_tblspace
884+
(2 rows)
885+
886+
DROP TABLE t;
864887
-- Check the new partition inherits parent's table access method
865888
SET search_path = partitions_merge_schema, public;
866889
CREATE ACCESS METHOD partitions_merge_heap TYPE TABLE HANDLER heap_tableam_handler;

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

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1493,6 +1493,32 @@ SELECT c.oid::pg_catalog.regclass, pg_catalog.pg_get_expr(c.relpartbound, c.oid)
14931493
tp_1_2 | FOR VALUES FROM (1) TO (2) | t
14941494
(2 rows)
14951495

1496+
DROP TABLE t;
1497+
-- Check the new partitions inherit parent's tablespace
1498+
CREATE TABLE t (i int PRIMARY KEY USING INDEX TABLESPACE regress_tblspace)
1499+
PARTITION BY RANGE (i) TABLESPACE regress_tblspace;
1500+
CREATE TABLE tp_0_2 PARTITION OF t FOR VALUES FROM (0) TO (2);
1501+
ALTER TABLE t SPLIT PARTITION tp_0_2 INTO
1502+
(PARTITION tp_0_1 FOR VALUES FROM (0) TO (1),
1503+
PARTITION tp_1_2 FOR VALUES FROM (1) TO (2));
1504+
SELECT tablename, tablespace FROM pg_tables
1505+
WHERE tablename IN ('t', 'tp_0_1', 'tp_1_2') ORDER BY tablename, tablespace;
1506+
tablename | tablespace
1507+
-----------+------------------
1508+
t | regress_tblspace
1509+
tp_0_1 | regress_tblspace
1510+
tp_1_2 | regress_tblspace
1511+
(3 rows)
1512+
1513+
SELECT tablename, indexname, tablespace FROM pg_indexes
1514+
WHERE tablename IN ('t', 'tp_0_1', 'tp_1_2') ORDER BY tablename, indexname, tablespace;
1515+
tablename | indexname | tablespace
1516+
-----------+-------------+------------------
1517+
t | t_pkey | regress_tblspace
1518+
tp_0_1 | tp_0_1_pkey | regress_tblspace
1519+
tp_1_2 | tp_1_2_pkey | regress_tblspace
1520+
(3 rows)
1521+
14961522
DROP TABLE t;
14971523
-- Check new partitions inherits parent's table access method
14981524
CREATE ACCESS METHOD partition_split_heap TYPE TABLE HANDLER heap_tableam_handler;

‎src/test/regress/sql/partition_merge.sql

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -536,6 +536,18 @@ SET search_path = partitions_merge_schema, pg_temp, public;
536536
ALTERTABLE t MERGE PARTITIONS (tp_0_1, tp_1_2) INTO tp_0_2;
537537
ROLLBACK;
538538

539+
-- Check the new partition inherits parent's tablespace
540+
CREATETABLEt (iintPRIMARY KEY USING INDEX TABLESPACE regress_tblspace)
541+
PARTITION BY RANGE (i) TABLESPACE regress_tblspace;
542+
CREATETABLEtp_0_1 PARTITION OF t FORVALUESFROM (0) TO (1);
543+
CREATETABLEtp_1_2 PARTITION OF t FORVALUESFROM (1) TO (2);
544+
ALTERTABLE t MERGE PARTITIONS (tp_0_1, tp_1_2) INTO tp_0_2;
545+
SELECT tablename, tablespaceFROM pg_tables
546+
WHERE tablenameIN ('t','tp_0_2')ORDER BY tablename, tablespace;
547+
SELECT tablename, indexname, tablespaceFROM pg_indexes
548+
WHERE tablenameIN ('t','tp_0_2')ORDER BY tablename, indexname, tablespace;
549+
DROPTABLE t;
550+
539551
-- Check the new partition inherits parent's table access method
540552
SET search_path= partitions_merge_schema, public;
541553
CREATE ACCESS METHOD partitions_merge_heap TYPE TABLE HANDLER heap_tableam_handler;

‎src/test/regress/sql/partition_split.sql

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -880,6 +880,19 @@ SELECT c.oid::pg_catalog.regclass, pg_catalog.pg_get_expr(c.relpartbound, c.oid)
880880

881881
DROPTABLE t;
882882

883+
-- Check the new partitions inherit parent's tablespace
884+
CREATETABLEt (iintPRIMARY KEY USING INDEX TABLESPACE regress_tblspace)
885+
PARTITION BY RANGE (i) TABLESPACE regress_tblspace;
886+
CREATETABLEtp_0_2 PARTITION OF t FORVALUESFROM (0) TO (2);
887+
ALTERTABLE t SPLIT PARTITION tp_0_2 INTO
888+
(PARTITION tp_0_1 FORVALUESFROM (0) TO (1),
889+
PARTITION tp_1_2 FORVALUESFROM (1) TO (2));
890+
SELECT tablename, tablespaceFROM pg_tables
891+
WHERE tablenameIN ('t','tp_0_1','tp_1_2')ORDER BY tablename, tablespace;
892+
SELECT tablename, indexname, tablespaceFROM pg_indexes
893+
WHERE tablenameIN ('t','tp_0_1','tp_1_2')ORDER BY tablename, indexname, tablespace;
894+
DROPTABLE t;
895+
883896
-- Check new partitions inherits parent's table access method
884897
CREATE ACCESS METHOD partition_split_heap TYPE TABLE HANDLER heap_tableam_handler;
885898
CREATETABLEt (iint) PARTITION BY RANGE (i) USING partition_split_heap;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp