This is an automated email from the ASF dual-hosted git repository. reshke pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/cloudberry.git
commit b7bce83ed18ea246e4934a649211d329b9abedd2 Author: Divyesh Vanjare <[email protected]> AuthorDate: Thu May 5 16:13:25 2022 -0700 Preserve AO storage options during internal CTAS This change is an extension of the PR #13246. The commit c121bcd83c9 fixes the bug for ALTER TABLE EXPAND TABLE and ALTER TABLE SET DISTRIBUTED BY operations on AO tables with indexes. These operations on AO tables with indexes are executed with CT + IIS whereas on AO tables without indexes which are executed with CTAS The bug about not preserving storage options is also present for ALTER TABLE on AO tables without indexes case. This change fixes that bug by adding the storage options preservation logic to AT calls for AO tables which go through an internal CTAS. Co-authored-by: Soumyadeep Chakraborty <[email protected]> --- src/backend/commands/tablecmds.c | 13 +++ src/test/regress/expected/expand_table_ao.out | 118 ++++++++++++++++++++++++++ src/test/regress/sql/expand_table_ao.sql | 77 +++++++++++++++++ 3 files changed, 208 insertions(+) diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 5e79cb997a..f8b5606019 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -17912,6 +17912,19 @@ build_ctas_with_dist(Relation rel, DistributedBy *dist_clause, into->options = storage_opts; into->tableSpaceName = get_tablespace_name(tblspc); into->distributedBy = (Node *)dist_clause; + if (RelationIsAoRows(rel)) + { + /* + * In order to avoid being affected by the GUC of gp_default_storage_options, + * we should re-build storage options from original table. + * + * The reason is that when we use the default parameters to create a table, + * the configuration will not be written to pg_class.reloptions, and then if + * gp_default_storage_options is modified, the newly created table will be + * inconsistent with the original table. + */ + into->options = build_ao_rel_storage_opts(into->options, rel); + } s->intoClause = into; RawStmt *rawstmt = makeNode(RawStmt); diff --git a/src/test/regress/expected/expand_table_ao.out b/src/test/regress/expected/expand_table_ao.out index ce12c67045..57c3dd55f3 100644 --- a/src/test/regress/expected/expand_table_ao.out +++ b/src/test/regress/expected/expand_table_ao.out @@ -713,6 +713,124 @@ Select gp_segment_id, count(*) from part_t1 group by gp_segment_id; (3 rows) drop table part_t1; +-- Test expanding an AO table without index, and current gp_default_storage_options is different +-- from the table created. +select gp_debug_set_create_table_default_numsegments(2); + gp_debug_set_create_table_default_numsegments +----------------------------------------------- + 2 +(1 row) + +set gp_default_storage_options = ''; +-- Create a AO table with default row-oriented storage +create table t_9526 (a int, b text) WITH (appendoptimized=true) distributed by (a); +-- Set default storage method to column-oriented, and change the default value of blocksize, compresstype, etc. +SET gp_default_storage_options = 'blocksize=65536, compresstype=zlib, compresslevel=5, checksum=true'; +set default_table_access_method = ao_column; +-- Should successful and the table is still row-oriented +alter table t_9526 expand table; +show gp_default_storage_options; + gp_default_storage_options +----------------------------------------------------------------- + blocksize=65536,compresstype=zlib,compresslevel=5,checksum=true +(1 row) + +select localoid::regclass::name, policytype, numsegments, distkey, distclass +from gp_distribution_policy where localoid = 't_9526'::regclass::oid; + localoid | policytype | numsegments | distkey | distclass +----------+------------+-------------+---------+----------- + t_9526 | p | 3 | 1 | 10054 +(1 row) + +-- storage paramter should be same with before +select blocksize,compresslevel,checksum,compresstype,columnstore from pg_appendonly where relid='t_9526'::regclass::oid; + blocksize | compresslevel | checksum | compresstype | columnstore +-----------+---------------+----------+--------------+------------- + 32768 | 0 | t | none | f +(1 row) + +-- set back +set gp_default_storage_options = ''; +drop table t_9526; +-- Test expanding an AO table with index, and current gp_default_storage_options is different +-- from the table created. +select gp_debug_set_create_table_default_numsegments(2); + gp_debug_set_create_table_default_numsegments +----------------------------------------------- + 2 +(1 row) + +set gp_default_storage_options = ''; +-- Create a AO table with default row-oriented storage and build index for it +create table t_9527 (a int, b text) WITH (appendoptimized=true) distributed by (a); +create index idx_9527 on t_9527(b); +-- Set default storage method to column-oriented, and change the default value of blocksize, compresstype, etc. +SET gp_default_storage_options = 'blocksize=65536, compresstype=zlib, compresslevel=5, checksum=true'; +set default_table_access_method = ao_column; +-- Should successful and the table is still row-oriented +alter table t_9527 expand table; +show gp_default_storage_options; + gp_default_storage_options +----------------------------------------------------------------- + blocksize=65536,compresstype=zlib,compresslevel=5,checksum=true +(1 row) + +select localoid::regclass::name, policytype, numsegments, distkey, distclass + from gp_distribution_policy where localoid = 't_9527'::regclass::oid; + localoid | policytype | numsegments | distkey | distclass +----------+------------+-------------+---------+----------- + t_9527 | p | 3 | 1 | 10054 +(1 row) + +-- storage paramter should be same with before +select blocksize,compresslevel,checksum,compresstype,columnstore from pg_appendonly where relid='t_9527'::regclass::oid; + blocksize | compresslevel | checksum | compresstype | columnstore +-----------+---------------+----------+--------------+------------- + 32768 | 0 | t | none | f +(1 row) + +-- set back +set gp_default_storage_options = ''; +drop table t_9527; +-- Test change the distribution policy of an AO table with index, and current gp_default_storage_options is different +-- from the table created. +select gp_debug_set_create_table_default_numsegments(2); + gp_debug_set_create_table_default_numsegments +----------------------------------------------- + 2 +(1 row) + +set gp_default_storage_options = ''; +-- Create a AO table with default row-oriented storage and build index for it +create table t_9528 (a int, b text) WITH (appendoptimized=true) distributed by (a); +create index idx_9528 on t_9528(b); +SET gp_default_storage_options = 'blocksize=65536, compresstype=zlib, compresslevel=5, checksum=true'; +set default_table_access_method = ao_column; +-- Should successful and the table is still row-oriented +alter table t_9528 set distributed by (b); +show gp_default_storage_options; + gp_default_storage_options +----------------------------------------------------------------- + blocksize=65536,compresstype=zlib,compresslevel=5,checksum=true +(1 row) + +select localoid::regclass::name, policytype, numsegments, distkey, distclass + from gp_distribution_policy where localoid = 't_9528'::regclass::oid; + localoid | policytype | numsegments | distkey | distclass +----------+------------+-------------+---------+----------- + t_9528 | p | 2 | 2 | 10072 +(1 row) + +-- storage paramter should be same with before +select blocksize,compresslevel,checksum,compresstype,columnstore from pg_appendonly where relid='t_9528'::regclass::oid; + blocksize | compresslevel | checksum | compresstype | columnstore +-----------+---------------+----------+--------------+------------- + 32768 | 0 | t | none | f +(1 row) + +-- set back +set gp_default_storage_options = ''; +drop table t_9528; -- start_ignore -- We need to do a cluster expansion which will check if there are partial -- tables, we need to drop the partial tables to keep the cluster expansion diff --git a/src/test/regress/sql/expand_table_ao.sql b/src/test/regress/sql/expand_table_ao.sql index b49feec16a..ebee0d9bb3 100644 --- a/src/test/regress/sql/expand_table_ao.sql +++ b/src/test/regress/sql/expand_table_ao.sql @@ -335,6 +335,83 @@ Select gp_segment_id, count(*) from part_t1 group by gp_segment_id; drop table part_t1; +-- Test expanding an AO table without index, and current gp_default_storage_options is different +-- from the table created. +select gp_debug_set_create_table_default_numsegments(2); +set gp_default_storage_options = ''; + +-- Create a AO table with default row-oriented storage +create table t_9526 (a int, b text) WITH (appendoptimized=true) distributed by (a); + +-- Set default storage method to column-oriented, and change the default value of blocksize, compresstype, etc. +SET gp_default_storage_options = 'blocksize=65536, compresstype=zlib, compresslevel=5, checksum=true'; +set default_table_access_method = ao_column; + +-- Should successful and the table is still row-oriented +alter table t_9526 expand table; + +show gp_default_storage_options; +select localoid::regclass::name, policytype, numsegments, distkey, distclass +from gp_distribution_policy where localoid = 't_9526'::regclass::oid; +-- storage paramter should be same with before +select blocksize,compresslevel,checksum,compresstype,columnstore from pg_appendonly where relid='t_9526'::regclass::oid; + +-- set back +set gp_default_storage_options = ''; +drop table t_9526; + +-- Test expanding an AO table with index, and current gp_default_storage_options is different +-- from the table created. +select gp_debug_set_create_table_default_numsegments(2); +set gp_default_storage_options = ''; + +-- Create a AO table with default row-oriented storage and build index for it +create table t_9527 (a int, b text) WITH (appendoptimized=true) distributed by (a); +create index idx_9527 on t_9527(b); + +-- Set default storage method to column-oriented, and change the default value of blocksize, compresstype, etc. +SET gp_default_storage_options = 'blocksize=65536, compresstype=zlib, compresslevel=5, checksum=true'; +set default_table_access_method = ao_column; + +-- Should successful and the table is still row-oriented +alter table t_9527 expand table; + +show gp_default_storage_options; +select localoid::regclass::name, policytype, numsegments, distkey, distclass + from gp_distribution_policy where localoid = 't_9527'::regclass::oid; +-- storage paramter should be same with before +select blocksize,compresslevel,checksum,compresstype,columnstore from pg_appendonly where relid='t_9527'::regclass::oid; + +-- set back +set gp_default_storage_options = ''; +drop table t_9527; + +-- Test change the distribution policy of an AO table with index, and current gp_default_storage_options is different +-- from the table created. +select gp_debug_set_create_table_default_numsegments(2); +set gp_default_storage_options = ''; + +-- Create a AO table with default row-oriented storage and build index for it +create table t_9528 (a int, b text) WITH (appendoptimized=true) distributed by (a); +create index idx_9528 on t_9528(b); + +SET gp_default_storage_options = 'blocksize=65536, compresstype=zlib, compresslevel=5, checksum=true'; +set default_table_access_method = ao_column; + +-- Should successful and the table is still row-oriented +alter table t_9528 set distributed by (b); + +show gp_default_storage_options; +select localoid::regclass::name, policytype, numsegments, distkey, distclass + from gp_distribution_policy where localoid = 't_9528'::regclass::oid; +-- storage paramter should be same with before +select blocksize,compresslevel,checksum,compresstype,columnstore from pg_appendonly where relid='t_9528'::regclass::oid; + +-- set back +set gp_default_storage_options = ''; +drop table t_9528; + + -- start_ignore -- We need to do a cluster expansion which will check if there are partial -- tables, we need to drop the partial tables to keep the cluster expansion --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
