This is an automated email from the ASF dual-hosted git repository.

yjhjstz pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/cloudberry.git

commit 5330213a81f4da148d03d007fa2f6b23d70793e6
Author: Huansong Fu <[email protected]>
AuthorDate: Wed Oct 19 13:39:48 2022 -0700

    Add tests for ALTER TABLE ONLY ... SET TABLESPACE
    
    Historically in GPDB6, when executing ALTER TABLE SET TABLESPACE
    on a partition root, we will recurse into its child tables. This
    behavior differs from the upstream where it is not recursed. We
    have decided to keep this behavior for 7X, but to also support
    the ONLY keyword so that users can choose to alter just the
    partition root. Similar to other ALTER TABLE ONLY statements,
    the syntax is e.g.:
    
    ALTER TABLE ONLY foopart SET TABLESPACE myts
    
    Discussion: 
https://groups.google.com/a/greenplum.org/g/gpdb-dev/c/ImJrvQEECwA
---
 src/test/regress/input/tablespace.source  | 19 +++++++++++++++++++
 src/test/regress/output/tablespace.source | 25 +++++++++++++++++++++++++
 2 files changed, 44 insertions(+)

diff --git a/src/test/regress/input/tablespace.source 
b/src/test/regress/input/tablespace.source
index ed7c56d65f..18f1736399 100644
--- a/src/test/regress/input/tablespace.source
+++ b/src/test/regress/input/tablespace.source
@@ -446,3 +446,22 @@ DROP SCHEMA testschema CASCADE;
 
 DROP ROLE regress_tablespace_user1;
 DROP ROLE regress_tablespace_user2;
+
+-- Test that altering tablespace of a partition table should recurse into its 
child tables unless ONLY is specified.
+CREATE TABLE tablespace_part(a int, b int) PARTITION BY RANGE(a) (partition t1 
START (1) END (100));
+CREATE TABLESPACE myts LOCATION '@testtablespace@';
+ALTER TABLE tablespace_part SET TABLESPACE myts;
+
+-- Both parent and child tables use the new tablespace
+SELECT c.relname, t.spcname FROM pg_class c LEFT JOIN pg_tablespace t ON 
c.reltablespace = t.oid WHERE relname LIKE 'tablespace_part%';
+
+DROP TABLE tablespace_part;
+
+CREATE TABLE tablespace_part(a int, b int) PARTITION BY RANGE(a) (partition t1 
START (1) END (100));
+ALTER TABLE ONLY tablespace_part SET TABLESPACE myts;
+
+-- Only the parent table uses the new tablespace
+SELECT c.relname, t.spcname FROM pg_class c LEFT JOIN pg_tablespace t ON 
c.reltablespace = t.oid WHERE relname LIKE 'tablespace_part%';
+
+DROP TABLE tablespace_part;
+DROP TABLESPACE myts;
diff --git a/src/test/regress/output/tablespace.source 
b/src/test/regress/output/tablespace.source
index 7f8a955420..071a880620 100644
--- a/src/test/regress/output/tablespace.source
+++ b/src/test/regress/output/tablespace.source
@@ -984,3 +984,28 @@ drop cascades to table testschema.atable
 drop cascades to table testschema.tablespace_acl
 DROP ROLE regress_tablespace_user1;
 DROP ROLE regress_tablespace_user2;
+-- Test that altering tablespace of a partition table should recurse into its 
child tables unless ONLY is specified.
+CREATE TABLE tablespace_part(a int, b int) PARTITION BY RANGE(a) (partition t1 
START (1) END (100));
+CREATE TABLESPACE myts LOCATION '@testtablespace@';
+ALTER TABLE tablespace_part SET TABLESPACE myts;
+-- Both parent and child tables use the new tablespace
+SELECT c.relname, t.spcname FROM pg_class c LEFT JOIN pg_tablespace t ON 
c.reltablespace = t.oid WHERE relname LIKE 'tablespace_part%';
+         relname          | spcname 
+--------------------------+---------
+ tablespace_part          | myts
+ tablespace_part_1_prt_t1 | myts
+(2 rows)
+
+DROP TABLE tablespace_part;
+CREATE TABLE tablespace_part(a int, b int) PARTITION BY RANGE(a) (partition t1 
START (1) END (100));
+ALTER TABLE ONLY tablespace_part SET TABLESPACE myts;
+-- Only the parent table uses the new tablespace
+SELECT c.relname, t.spcname FROM pg_class c LEFT JOIN pg_tablespace t ON 
c.reltablespace = t.oid WHERE relname LIKE 'tablespace_part%';
+         relname          | spcname 
+--------------------------+---------
+ tablespace_part          | myts
+ tablespace_part_1_prt_t1 | 
+(2 rows)
+
+DROP TABLE tablespace_part;
+DROP TABLESPACE myts;


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to