Skip to content

Commit

Permalink
Fix cherry-pick issues.
Browse files Browse the repository at this point in the history
  • Loading branch information
reshke committed Jan 25, 2025
1 parent 386b74f commit f375254
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 50 deletions.
18 changes: 12 additions & 6 deletions src/backend/access/common/reloptions_gp.c
Original file line number Diff line number Diff line change
Expand Up @@ -1670,7 +1670,7 @@ find_crsd(const char *column, List *stenc)
List *
transformColumnEncoding(const TableAmRoutine *tam, Relation rel, List *colDefs,
List *stenc, List *withOptions, List *parentenc,
bool explicitOnly, bool createDefaultOne)
bool explicitOnly, bool createDefaultOne, bool appendonly)
{
ColumnReferenceStorageDirective *deflt = NULL;
ListCell *lc;
Expand Down Expand Up @@ -1713,7 +1713,10 @@ transformColumnEncoding(const TableAmRoutine *tam, Relation rel, List *colDefs,

deflt = copyObject(c);

deflt->encoding = tam->transform_column_encoding_clauses(rel, deflt->encoding, true, false);
if (appendonly)
deflt->encoding = tam->transform_column_encoding_clauses(rel, deflt->encoding, true, false);
else
deflt->encoding = transformStorageEncodingClause(deflt->encoding, true);

/*
* The default encoding and the with clause better not
Expand Down Expand Up @@ -1742,8 +1745,10 @@ transformColumnEncoding(const TableAmRoutine *tam, Relation rel, List *colDefs,
* if current am not inmplement transform_column_encoding_clauses
* then tmpenc not null but no need fill with options.
*/
if (tam->transform_column_encoding_clauses)
if (tam->transform_column_encoding_clauses && appendonly)
deflt->encoding = tam->transform_column_encoding_clauses(rel, tmpenc, false, false);
else
deflt->encoding = transformStorageEncodingClause(tmpenc, false);
}
}

Expand Down Expand Up @@ -1781,9 +1786,10 @@ transformColumnEncoding(const TableAmRoutine *tam, Relation rel, List *colDefs,
ColumnReferenceStorageDirective *s = find_crsd(d->colname, stenc);

if (s) {
encoding = tam->transform_column_encoding_clauses(rel, s->encoding, true, false);
if (tam->transform_column_encoding_clauses)
encoding = tam->transform_column_encoding_clauses(rel, s->encoding, true, false);
} else {
if (deflt)
if (deflt && deflt->encoding != NULL)
encoding = copyObject(deflt->encoding);
else if (!explicitOnly)
{
Expand All @@ -1796,7 +1802,7 @@ transformColumnEncoding(const TableAmRoutine *tam, Relation rel, List *colDefs,
else if (d->typeName) {
/* get encoding by type, still need do transform and validate */
encoding = get_type_encoding(d->typeName);
if (tam->transform_column_encoding_clauses)
if (tam->transform_column_encoding_clauses && appendonly)
encoding = tam->transform_column_encoding_clauses(rel, encoding, true, true);
}
if (!encoding && createDefaultOne) {
Expand Down
22 changes: 10 additions & 12 deletions src/backend/commands/tablecmds.c
Original file line number Diff line number Diff line change
Expand Up @@ -584,7 +584,7 @@ static bool prebuild_temp_table(Relation rel, RangeVar *tmpname, DistributedBy *


static void checkATSetDistributedByStandalone(AlteredTableInfo *tab, Relation rel);
static void populate_rel_col_encodings(Relation rel, List *stenc, List *withOptions);
static void populate_rel_col_encodings(Relation rel, List *stenc, List *withOptions, Oid newAm);
static void clear_rel_opts(Relation rel);


Expand Down Expand Up @@ -1147,7 +1147,8 @@ DefineRelation(CreateStmt *stmt, char relkind, Oid ownerId,
stmt->options,
parentenc,
relkind == RELKIND_PARTITIONED_TABLE,
AMHandlerIsAoCols(amHandlerOid) /* createDefaultOne*/);
AMHandlerIsAoCols(amHandlerOid) /* createDefaultOne*/, true);

if (!AMHandlerSupportEncodingClause(tam) && relkind != RELKIND_PARTITIONED_TABLE)
stmt->attr_encodings = NIL;
}
Expand Down Expand Up @@ -1334,7 +1335,7 @@ DefineRelation(CreateStmt *stmt, char relkind, Oid ownerId,
false,
accessMethodId != AO_COLUMN_TABLE_AM_OID
&& !stmt->partbound && !stmt->partspec
/* errorOnEncodingClause */);
/* errorOnEncodingClause */, true);

AddRelationAttributeEncodings(rel, part_attr_encodings);
}
Expand Down Expand Up @@ -4823,7 +4824,7 @@ AlterTable(AlterTableStmt *stmt, LOCKMODE lockmode,
/*
* Populate the column encoding option for each column in the relation.
*/
static void populate_rel_col_encodings(Relation rel, List *stenc, List *withOptions)
static void populate_rel_col_encodings(Relation rel, List *stenc, List *withOptions, Oid newAccessMethod)
{
int attno;
List *colDefs = NIL;
Expand All @@ -4841,15 +4842,16 @@ static void populate_rel_col_encodings(Relation rel, List *stenc, List *withOpti
colDefs = lappend(colDefs, cd);
}

tam = GetTableAmRoutineByAmId(rel->rd_rel->relam);
tam = GetTableAmRoutineByAmId(newAccessMethod);

List *attr_encodings = transformColumnEncoding(tam /* TableAmRoutine */, rel,
colDefs /*column clauses*/,
stenc /*encoding clauses*/,
withOptions /*withOptions*/,
NULL,
false,
RelationIsAoCols(rel));
newAccessMethod == AO_COLUMN_TABLE_AM_OID, RelationIsAppendOptimized(rel));


AddRelationAttributeEncodings(rel, attr_encodings);
}
Expand Down Expand Up @@ -6217,7 +6219,7 @@ ATExecCmd(List **wqueue, AlteredTableInfo *tab,

/* If we are changing AM to AOCO, add pg_attribute_encoding entries for each column. */
if (tab->newAccessMethod == AO_COLUMN_TABLE_AM_OID)
populate_rel_col_encodings(rel, NULL, (List*)cmd->def);
populate_rel_col_encodings(rel, NULL, (List*)cmd->def, tab->newAccessMethod);

break;
case AT_SetTableSpace: /* SET TABLESPACE */
Expand Down Expand Up @@ -8719,7 +8721,7 @@ ATExecAddColumn(List **wqueue, AlteredTableInfo *tab, Relation rel,
NULL /* withOptions */,
NULL /* parentenc */,
false /* explicitOnly */,
RelationIsAoCols(rel) /* createDefaultOne */);
RelationIsAoCols(rel) /* createDefaultOne */, true);
/*
* Store the encoding clause for AO/CO tables.
*/
Expand Down Expand Up @@ -16122,10 +16124,6 @@ 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 */
Expand Down
2 changes: 1 addition & 1 deletion src/include/access/reloptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ extern void validate_and_adjust_options(StdRdOptions *result, relopt_value *opti
extern void validateAOCOColumnEncodingClauses(List *aocoColumnEncoding);
extern List *transformColumnEncoding(const TableAmRoutine *tam, Relation rel, List *colDefs,
List *stenc, List *withOptions, List *parentenc,
bool explicitOnly, bool createDefaultOne);
bool explicitOnly, bool createDefaultOne, bool appendonly);

List* transfromColumnEncodingAocoRootPartition(List *colDefs, List *stenc, List *withOptions, bool errorOnEncodingClause);

Expand Down
58 changes: 29 additions & 29 deletions src/test/regress/expected/alter_table_set_am.out
Original file line number Diff line number Diff line change
Expand Up @@ -755,8 +755,8 @@ SELECT c.relname, a.attnum, a.attoptions FROM pg_attribute_encoding a, pg_class
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
---------+-----------+---------------------------------------------------------
ao2co | ao_column |
ao2co2 | ao_column |
ao2co | ao_column | {blocksize=65536,compresslevel=5}
ao2co2 | ao_column | {blocksize=65536,compresslevel=5}
ao2co3 | ao_column | {blocksize=32768,compresstype=rle_type,compresslevel=3}
ao2co4 | ao_column | {blocksize=32768,compresstype=rle_type,compresslevel=3}
(4 rows)
Expand All @@ -766,8 +766,8 @@ SELECT c.relname,a.blocksize,a.compresslevel,a.checksum,a.compresstype,a.columns
FROM pg_appendonly a, pg_class c WHERE a.relid = c.oid AND relname like ('ao2co%');
relname | blocksize | compresslevel | checksum | compresstype | columnstore
---------+-----------+---------------+----------+--------------+-------------
ao2co | 32768 | 0 | t | | t
ao2co2 | 32768 | 0 | t | | t
ao2co | 65536 | 5 | t | zlib | t
ao2co2 | 65536 | 5 | t | zlib | t
ao2co3 | 32768 | 3 | t | rle_type | t
ao2co4 | 32768 | 3 | t | rle_type | t
(4 rows)
Expand Down Expand Up @@ -812,14 +812,14 @@ SELECT relname, relfrozenxid FROM pg_class WHERE relname LIKE 'co2heap%';
SELECT c.relname, a.attnum, attoptions FROM pg_attribute_encoding a, pg_class c WHERE a.attrelid=c.oid AND c.relname LIKE 'co2heap%';
relname | attnum | attoptions
----------+--------+-----------------------------------------------------
co2heap | 1 | {compresstype=zlib,blocksize=65536,compresslevel=5}
co2heap | 2 | {compresstype=zlib,blocksize=65536,compresslevel=5}
co2heap2 | 1 | {compresstype=zlib,blocksize=65536,compresslevel=5}
co2heap2 | 2 | {compresstype=zlib,blocksize=65536,compresslevel=5}
co2heap3 | 1 | {compresstype=zlib,blocksize=65536,compresslevel=5}
co2heap3 | 2 | {compresstype=zlib,blocksize=65536,compresslevel=5}
co2heap4 | 1 | {compresstype=zlib,blocksize=65536,compresslevel=5}
co2heap4 | 2 | {compresstype=zlib,blocksize=65536,compresslevel=5}
co2heap | 1 | {compresstype=zlib,compresslevel=5,blocksize=65536}
co2heap | 2 | {compresstype=zlib,compresslevel=5,blocksize=65536}
co2heap2 | 1 | {compresstype=zlib,compresslevel=5,blocksize=65536}
co2heap2 | 2 | {compresstype=zlib,compresslevel=5,blocksize=65536}
co2heap3 | 1 | {compresstype=zlib,compresslevel=5,blocksize=65536}
co2heap3 | 2 | {compresstype=zlib,compresslevel=5,blocksize=65536}
co2heap4 | 1 | {compresstype=zlib,compresslevel=5,blocksize=65536}
co2heap4 | 2 | {compresstype=zlib,compresslevel=5,blocksize=65536}
(8 rows)

CREATE TEMP TABLE relfilebeforeco2heap AS
Expand Down Expand Up @@ -934,8 +934,8 @@ DROP TABLE co2heap2;
DROP TABLE co2heap3;
DROP TABLE co2heap4;
-- Scenario 7: AOCO to AO
CREATE TABLE co2ao(a int, b int) WITH (appendonly=true, orientation=column, compresstype=rle_type, compresslevel=3);
CREATE TABLE co2ao2(a int, b int) WITH (appendonly=true, orientation=column, compresstype=rle_type, compresslevel=3);
CREATE TABLE co2ao(a int, b int) WITH (appendonly=true, orientation=column, compresstype=zlib, compresslevel=3);
CREATE TABLE co2ao2(a int, b int) WITH (appendonly=true, orientation=column, compresstype=zlib, compresslevel=3);
CREATE TABLE co2ao3(a int, b int) WITH (appendonly=true, orientation=column, compresstype=rle_type, compresslevel=3);
CREATE TABLE co2ao4(a int, b int) WITH (appendonly=true, orientation=column, compresstype=rle_type, compresslevel=3);
CREATE INDEX aoi ON co2ao(b);
Expand All @@ -949,8 +949,8 @@ INSERT INTO co2ao4 SELECT i,i FROM generate_series(1,5) i;
SELECT relname, reloptions FROM pg_class WHERE relname LIKE 'co2ao%';
relname | reloptions
---------+---------------------------------------------------------
co2ao | {compresstype=rle_type,compresslevel=3,blocksize=65536}
co2ao2 | {compresstype=rle_type,compresslevel=3,blocksize=65536}
co2ao | {compresstype=zlib,compresslevel=3,blocksize=65536}
co2ao2 | {compresstype=zlib,compresslevel=3,blocksize=65536}
co2ao3 | {compresstype=rle_type,compresslevel=3,blocksize=65536}
co2ao4 | {compresstype=rle_type,compresslevel=3,blocksize=65536}
(4 rows)
Expand All @@ -959,8 +959,8 @@ SELECT relname, reloptions FROM pg_class WHERE relname LIKE 'co2ao%';
SELECT c.relname, p.compresstype, p.compresslevel, p.blocksize FROM pg_class c, pg_appendonly p WHERE c.relname LIKE 'co2ao%' AND c.oid = p.relid;
relname | compresstype | compresslevel | blocksize
---------+--------------+---------------+-----------
co2ao | rle_type | 3 | 65536
co2ao2 | rle_type | 3 | 65536
co2ao | zlib | 3 | 65536
co2ao2 | zlib | 3 | 65536
co2ao3 | rle_type | 3 | 65536
co2ao4 | rle_type | 3 | 65536
(4 rows)
Expand All @@ -969,10 +969,10 @@ SELECT c.relname, p.compresstype, p.compresslevel, p.blocksize FROM pg_class c,
SELECT c.relname, a.attnum, attoptions FROM pg_attribute_encoding a, pg_class c WHERE a.attrelid=c.oid AND c.relname LIKE 'co2ao%';
relname | attnum | attoptions
---------+--------+---------------------------------------------------------
co2ao | 1 | {compresstype=rle_type,compresslevel=3,blocksize=65536}
co2ao | 2 | {compresstype=rle_type,compresslevel=3,blocksize=65536}
co2ao2 | 1 | {compresstype=rle_type,compresslevel=3,blocksize=65536}
co2ao2 | 2 | {compresstype=rle_type,compresslevel=3,blocksize=65536}
co2ao | 1 | {compresstype=zlib,compresslevel=3,blocksize=65536}
co2ao | 2 | {compresstype=zlib,compresslevel=3,blocksize=65536}
co2ao2 | 1 | {compresstype=zlib,compresslevel=3,blocksize=65536}
co2ao2 | 2 | {compresstype=zlib,compresslevel=3,blocksize=65536}
co2ao3 | 1 | {compresstype=rle_type,compresslevel=3,blocksize=65536}
co2ao3 | 2 | {compresstype=rle_type,compresslevel=3,blocksize=65536}
co2ao4 | 1 | {compresstype=rle_type,compresslevel=3,blocksize=65536}
Expand Down Expand Up @@ -1056,7 +1056,7 @@ SELECT count(*) FROM co2ao4;
SELECT * FROM gp_toolkit.__gp_aoseg('co2ao');
segment_id | segno | eof | tupcount | varblockcount | eof_uncompressed | modcount | formatversion | state
------------+-------+-----+----------+---------------+------------------+----------+---------------+-------
0 | 0 | 88 | 3 | 1 | 88 | 1 | 3 | 1
0 | 0 | 72 | 3 | 1 | 88 | 1 | 3 | 1
1 | 0 | 40 | 1 | 1 | 40 | 1 | 3 | 1
2 | 0 | 40 | 1 | 1 | 40 | 1 | 3 | 1
(3 rows)
Expand Down Expand Up @@ -1103,8 +1103,8 @@ SELECT gp_segment_id, (gp_toolkit.__gp_aoblkdir('co2ao3')).* FROM gp_dist_random
SELECT c.relname, p.compresstype, p.compresslevel, p.blocksize FROM pg_class c, pg_appendonly p WHERE c.relname LIKE 'co2ao%' AND c.oid = p.relid;
relname | compresstype | compresslevel | blocksize
---------+--------------+---------------+-----------
co2ao | | 0 | 32768
co2ao2 | | 0 | 32768
co2ao | zlib | 3 | 65536
co2ao2 | zlib | 3 | 65536
co2ao3 | zlib | 7 | 32768
co2ao4 | zlib | 7 | 32768
(4 rows)
Expand All @@ -1121,10 +1121,10 @@ SELECT c.relname, a.amname FROM pg_class c JOIN pg_am a ON c.relam = a.oid WHERE

-- Only the new tables altered w/ reloptions supplies should have reloptions.
SELECT relname, reloptions FROM pg_class WHERE relname LIKE 'co2ao%';
relname | reloptions
---------+-------------------------------------
co2ao |
co2ao2 |
relname | reloptions
---------+-----------------------------------------------------
co2ao | {compresstype=zlib,compresslevel=3,blocksize=65536}
co2ao2 | {compresstype=zlib,compresslevel=3,blocksize=65536}
co2ao3 | {compresstype=zlib,compresslevel=7}
co2ao4 | {compresstype=zlib,compresslevel=7}
(4 rows)
Expand Down
4 changes: 2 additions & 2 deletions src/test/regress/sql/alter_table_set_am.sql
Original file line number Diff line number Diff line change
Expand Up @@ -507,8 +507,8 @@ DROP TABLE co2heap3;
DROP TABLE co2heap4;

-- Scenario 7: AOCO to AO
CREATE TABLE co2ao(a int, b int) WITH (appendonly=true, orientation=column, compresstype=rle_type, compresslevel=3);
CREATE TABLE co2ao2(a int, b int) WITH (appendonly=true, orientation=column, compresstype=rle_type, compresslevel=3);
CREATE TABLE co2ao(a int, b int) WITH (appendonly=true, orientation=column, compresstype=zlib, compresslevel=3);
CREATE TABLE co2ao2(a int, b int) WITH (appendonly=true, orientation=column, compresstype=zlib, compresslevel=3);
CREATE TABLE co2ao3(a int, b int) WITH (appendonly=true, orientation=column, compresstype=rle_type, compresslevel=3);
CREATE TABLE co2ao4(a int, b int) WITH (appendonly=true, orientation=column, compresstype=rle_type, compresslevel=3);
CREATE INDEX aoi ON co2ao(b);
Expand Down

0 comments on commit f375254

Please sign in to comment.