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

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

commit 652633a29ff24149246f3ce4cfbbd92f23aa9bd3
Author: Georgy Shelkovy <[email protected]>
AuthorDate: Mon Jul 25 12:17:33 2022 +0500

    ADBDEV-2872: ALTER TABLE erase pg_appendonly values
    
    Ensure reorganize keep default compresstype, compresslevel and blocksize 
table options.
    
    This is need for use for append-optimized column-oriented tables
    with compresstype, compresslevel and blocksize options
    when new column without compresstype, compresslevel and blocksize options
    is added after table reorganize to inherit these options from table
---
 src/backend/commands/tablecmds.c               |  9 +--------
 src/test/regress/expected/alter_table_aocs.out | 24 ++++++++++++++++++++++++
 src/test/regress/sql/alter_table_aocs.sql      | 14 ++++++++++++++
 3 files changed, 39 insertions(+), 8 deletions(-)

diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index c2bf035cd9..850c08cb08 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -17919,10 +17919,6 @@ prebuild_temp_table(Relation rel, RangeVar *tmpname, 
DistributedBy *distro,
                        rel->rd_rel->relhasindex)
                        cs->buildAoBlkdir = true;
 
-               /* 
-                * For AO/CO tables, need to remove table level compression 
settings 
-                * for the AO_COLUMN case since they're set at the column level.
-                */
                if (RelationIsAoCols(rel))
                {
                        ListCell *lc;
@@ -17931,10 +17927,7 @@ prebuild_temp_table(Relation rel, RangeVar *tmpname, 
DistributedBy *distro,
                        {
                                DefElem *de = lfirst(lc);
 
-                               if (!useExistingColumnAttributes || 
-                                               !de->defname || 
-                                               
!is_storage_encoding_directive(de->defname))
-                                       cs->options = lappend(cs->options, de);
+                               cs->options = lappend(cs->options, de);
                        }
                        if (useExistingColumnAttributes)
                                col_encs = 
RelationGetUntransformedAttributeOptions(rel);
diff --git a/src/test/regress/expected/alter_table_aocs.out 
b/src/test/regress/expected/alter_table_aocs.out
index 7fc950182f..b8fc977c6f 100644
--- a/src/test/regress/expected/alter_table_aocs.out
+++ b/src/test/regress/expected/alter_table_aocs.out
@@ -812,3 +812,27 @@ Checksum: t
 Distributed by: (a)
 
 DROP TABLE aocs_alter_add_col_no_compress;
+-- test case: ensure reorganize keep default compresstype, compresslevel and 
blocksize table options
+CREATE TABLE aocs_alter_add_col_reorganize(a int) WITH (appendonly=true, 
orientation=column, compresstype=rle_type, compresslevel=4, blocksize=65536);
+ALTER TABLE aocs_alter_add_col_reorganize SET WITH (reorganize=true);
+SET gp_default_storage_options ='compresstype=zlib, compresslevel=2';
+-- use statement encoding
+ALTER TABLE aocs_alter_add_col_reorganize ADD COLUMN b int 
ENCODING(compresstype=zlib, compresslevel=3, blocksize=16384);
+-- use table setting
+ALTER TABLE aocs_alter_add_col_reorganize ADD COLUMN c int;
+RESET gp_default_storage_options;
+-- use table setting
+ALTER TABLE aocs_alter_add_col_reorganize ADD COLUMN d int;
+\d+ aocs_alter_add_col_reorganize
+                                                 Table 
"public.aocs_alter_add_col_reorganize"
+ Column |  Type   | Collation | Nullable | Default | Storage | Stats target | 
Compression Type | Compression Level | Block Size | Description 
+--------+---------+-----------+----------+---------+---------+--------------+------------------+-------------------+------------+-------------
+ a      | integer |           |          |         | plain   |              | 
rle_type         | 4                 | 65536      | 
+ b      | integer |           |          |         | plain   |              | 
zlib             | 3                 | 16384      | 
+ c      | integer |           |          |         | plain   |              | 
rle_type         | 4                 | 65536      | 
+ d      | integer |           |          |         | plain   |              | 
rle_type         | 4                 | 65536      | 
+Checksum: t
+Distributed by: (a)
+Options: compresstype=rle_type, compresslevel=4, blocksize=65536
+
+DROP TABLE aocs_alter_add_col_reorganize;
diff --git a/src/test/regress/sql/alter_table_aocs.sql 
b/src/test/regress/sql/alter_table_aocs.sql
index 9beb9066de..46d2804906 100644
--- a/src/test/regress/sql/alter_table_aocs.sql
+++ b/src/test/regress/sql/alter_table_aocs.sql
@@ -466,3 +466,17 @@ RESET gp_default_storage_options;
 ALTER TABLE aocs_alter_add_col_no_compress ADD COLUMN d int;
 \d+ aocs_alter_add_col_no_compress 
 DROP TABLE aocs_alter_add_col_no_compress;
+
+-- test case: ensure reorganize keep default compresstype, compresslevel and 
blocksize table options
+CREATE TABLE aocs_alter_add_col_reorganize(a int) WITH (appendonly=true, 
orientation=column, compresstype=rle_type, compresslevel=4, blocksize=65536);
+ALTER TABLE aocs_alter_add_col_reorganize SET WITH (reorganize=true);
+SET gp_default_storage_options ='compresstype=zlib, compresslevel=2';
+-- use statement encoding
+ALTER TABLE aocs_alter_add_col_reorganize ADD COLUMN b int 
ENCODING(compresstype=zlib, compresslevel=3, blocksize=16384);
+-- use table setting
+ALTER TABLE aocs_alter_add_col_reorganize ADD COLUMN c int;
+RESET gp_default_storage_options;
+-- use table setting
+ALTER TABLE aocs_alter_add_col_reorganize ADD COLUMN d int;
+\d+ aocs_alter_add_col_reorganize
+DROP TABLE aocs_alter_add_col_reorganize;


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

Reply via email to