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 374d05728a00a447af9099bbfc710e86008f8ea8 Author: Huansong Fu <[email protected]> AuthorDate: Wed Aug 17 14:57:57 2022 -0700 Fix an issue with rle_type when changing table from AO to AOCO It is found that when changing from AO to AOCO we cannot specify `compresstype=rle_type` which would complain that it is not applicable to AO table, despite that it should be a valid usage. This is because during setting new reloptions, we miss the information about the new AM being AOCO, and the code behavior is to validate the reloptions as AO tables. Fixing it by passing the new AM into ATExecSetRelOptions() based on which we can validate the reloptions. If there is no AM change, an InvalidOid will be passed in and we will use the current table AM to validate the reloptions. --- src/backend/commands/tablecmds.c | 6 ++++- src/test/regress/expected/alter_table_set_am.out | 28 ++++++++++++------------ src/test/regress/sql/alter_table_set_am.sql | 4 ++-- 3 files changed, 21 insertions(+), 17 deletions(-) diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 55f6604264..227fac7caa 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16104,7 +16104,7 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen * * GPDB specific arguments: * aoopt_changed: whether any AO storage options have been changed in this function. - * valid_as_ao: whether we validate teh reloptions as AO tables. + * newam: the new AM if we will change the table AM. It's InvalidOid if no change is needed. */ static void ATExecSetRelOptions(Relation rel, List *defList, AlterTableType operation, @@ -16122,6 +16122,10 @@ ATExecSetRelOptions(Relation rel, List *defList, AlterTableType operation, bool repl_repl[Natts_pg_class]; const TableAmRoutine * newAM; static char *validnsps[] = HEAP_RELOPT_NAMESPACES; + Oid tableam; + + /* Get the new table AM if applicable. Otherwise get the one from the reltion. */ + tableam = (newam != InvalidOid) ? newam : rel->rd_rel->relam; if (defList == NIL && operation != AT_ReplaceRelOptions) return; /* nothing to do */ diff --git a/src/test/regress/expected/alter_table_set_am.out b/src/test/regress/expected/alter_table_set_am.out index a8da1c39f7..9fc7ee3dab 100644 --- a/src/test/regress/expected/alter_table_set_am.out +++ b/src/test/regress/expected/alter_table_set_am.out @@ -659,8 +659,8 @@ SELECT c.relname, a.amname, c.reloptions FROM pg_class c JOIN pg_am a ON c.relam -- Altering AO to AOCO with various syntaxes, reloptions: ALTER TABLE ao2co SET ACCESS METHOD ao_column; ALTER TABLE ao2co2 SET WITH (appendoptimized=true, orientation=column); -ALTER TABLE ao2co3 SET ACCESS METHOD ao_column WITH (blocksize=32768, compresslevel=3); -ALTER TABLE ao2co4 SET WITH (appendoptimized=true, orientation=column, blocksize=32768, compresslevel=3); +ALTER TABLE ao2co3 SET ACCESS METHOD ao_column WITH (blocksize=32768, compresstype=rle_type, compresslevel=3); +ALTER TABLE ao2co4 SET WITH (appendoptimized=true, orientation=column, blocksize=32768, compresstype=rle_type, compresslevel=3); -- The tables are rewritten CREATE TEMP TABLE relfileafterao AS SELECT -1 segid, relname, relfilenode FROM pg_class WHERE relname LIKE 'ao2co%' @@ -739,26 +739,26 @@ SELECT * FROM gp_toolkit.__gp_aoblkdir('ao2co3'); -- pg_attribute_encoding should have columns for the AOCO table SELECT c.relname, a.attnum, a.attoptions FROM pg_attribute_encoding a, pg_class c WHERE a.attrelid = c.oid AND c.relname LIKE 'ao2co%'; - relname | attnum | attoptions ----------+--------+----------------------------------------------------- + relname | attnum | attoptions +---------+--------+--------------------------------------------------------- ao2co | 1 | {compresstype=zlib,blocksize=65536,compresslevel=5} ao2co | 2 | {compresstype=zlib,blocksize=65536,compresslevel=5} ao2co2 | 1 | {compresstype=zlib,blocksize=65536,compresslevel=5} ao2co2 | 2 | {compresstype=zlib,blocksize=65536,compresslevel=5} - ao2co3 | 1 | {blocksize=32768,compresslevel=3,compresstype=zlib} - ao2co3 | 2 | {blocksize=32768,compresslevel=3,compresstype=zlib} - ao2co4 | 1 | {blocksize=32768,compresslevel=3,compresstype=zlib} - ao2co4 | 2 | {blocksize=32768,compresslevel=3,compresstype=zlib} + ao2co3 | 1 | {blocksize=32768,compresstype=rle_type,compresslevel=3} + ao2co3 | 2 | {blocksize=32768,compresstype=rle_type,compresslevel=3} + ao2co4 | 1 | {blocksize=32768,compresstype=rle_type,compresslevel=3} + ao2co4 | 2 | {blocksize=32768,compresstype=rle_type,compresslevel=3} (8 rows) -- AM and reloptions changed accordingly SELECT c.relname, a.amname, c.reloptions FROM pg_class c JOIN pg_am a ON c.relam = a.oid WHERE c.relname LIKE 'ao2co%'; - relname | amname | reloptions ----------+-----------+----------------------------------- + relname | amname | reloptions +---------+-----------+--------------------------------------------------------- ao2co | ao_column | ao2co2 | ao_column | - ao2co3 | ao_column | {blocksize=32768,compresslevel=3} - ao2co4 | ao_column | {blocksize=32768,compresslevel=3} + ao2co3 | ao_column | {blocksize=32768,compresstype=rle_type,compresslevel=3} + ao2co4 | ao_column | {blocksize=32768,compresstype=rle_type,compresslevel=3} (4 rows) -- pg_appendonly should reflect the changes in reloptions @@ -768,8 +768,8 @@ FROM pg_appendonly a, pg_class c WHERE a.relid = c.oid AND relname like ('ao2co% ---------+-----------+---------------+----------+--------------+------------- ao2co | 32768 | 0 | t | | t ao2co2 | 32768 | 0 | t | | t - ao2co3 | 32768 | 3 | t | zlib | t - ao2co4 | 32768 | 3 | t | zlib | t + ao2co3 | 32768 | 3 | t | rle_type | t + ao2co4 | 32768 | 3 | t | rle_type | t (4 rows) DROP TABLE ao2co; diff --git a/src/test/regress/sql/alter_table_set_am.sql b/src/test/regress/sql/alter_table_set_am.sql index e97903b2ed..52e3b127c7 100644 --- a/src/test/regress/sql/alter_table_set_am.sql +++ b/src/test/regress/sql/alter_table_set_am.sql @@ -379,8 +379,8 @@ SELECT c.relname, a.amname, c.reloptions FROM pg_class c JOIN pg_am a ON c.relam -- Altering AO to AOCO with various syntaxes, reloptions: ALTER TABLE ao2co SET ACCESS METHOD ao_column; ALTER TABLE ao2co2 SET WITH (appendoptimized=true, orientation=column); -ALTER TABLE ao2co3 SET ACCESS METHOD ao_column WITH (blocksize=32768, compresslevel=3); -ALTER TABLE ao2co4 SET WITH (appendoptimized=true, orientation=column, blocksize=32768, compresslevel=3); +ALTER TABLE ao2co3 SET ACCESS METHOD ao_column WITH (blocksize=32768, compresstype=rle_type, compresslevel=3); +ALTER TABLE ao2co4 SET WITH (appendoptimized=true, orientation=column, blocksize=32768, compresstype=rle_type, compresslevel=3); -- The tables are rewritten CREATE TEMP TABLE relfileafterao AS --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
