You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudberry.apache.org by re...@apache.org on 2025/01/25 16:01:38 UTC
(cloudberry) 08/08: Fix cherry-pick issues.
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 f3752542bceb8fda891aa779332b452dc36df6b4
Author: reshke <re...@gmail.com>
AuthorDate: Wed Jan 22 06:49:21 2025 +0000
Fix cherry-pick issues.
---
src/backend/access/common/reloptions_gp.c | 18 +++++---
src/backend/commands/tablecmds.c | 22 ++++-----
src/include/access/reloptions.h | 2 +-
src/test/regress/expected/alter_table_set_am.out | 58 ++++++++++++------------
src/test/regress/sql/alter_table_set_am.sql | 4 +-
5 files changed, 54 insertions(+), 50 deletions(-)
diff --git a/src/backend/access/common/reloptions_gp.c b/src/backend/access/common/reloptions_gp.c
index b6022e1ccc..77f2f86bb1 100644
--- a/src/backend/access/common/reloptions_gp.c
+++ b/src/backend/access/common/reloptions_gp.c
@@ -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;
@@ -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
@@ -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);
}
}
@@ -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)
{
@@ -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) {
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 227fac7caa..5e79cb997a 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -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);
@@ -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;
}
@@ -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);
}
@@ -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;
@@ -4841,7 +4842,7 @@ 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*/,
@@ -4849,7 +4850,8 @@ static void populate_rel_col_encodings(Relation rel, List *stenc, List *withOpti
withOptions /*withOptions*/,
NULL,
false,
- RelationIsAoCols(rel));
+ newAccessMethod == AO_COLUMN_TABLE_AM_OID, RelationIsAppendOptimized(rel));
+
AddRelationAttributeEncodings(rel, attr_encodings);
}
@@ -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 */
@@ -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.
*/
@@ -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 */
diff --git a/src/include/access/reloptions.h b/src/include/access/reloptions.h
index a52b526d6a..719f67b0e2 100644
--- a/src/include/access/reloptions.h
+++ b/src/include/access/reloptions.h
@@ -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);
diff --git a/src/test/regress/expected/alter_table_set_am.out b/src/test/regress/expected/alter_table_set_am.out
index f809c9cb14..f165717612 100644
--- a/src/test/regress/expected/alter_table_set_am.out
+++ b/src/test/regress/expected/alter_table_set_am.out
@@ -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)
@@ -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)
@@ -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
@@ -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);
@@ -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)
@@ -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)
@@ -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}
@@ -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)
@@ -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)
@@ -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)
diff --git a/src/test/regress/sql/alter_table_set_am.sql b/src/test/regress/sql/alter_table_set_am.sql
index cc572c2fc1..f3c1a235c9 100644
--- a/src/test/regress/sql/alter_table_set_am.sql
+++ b/src/test/regress/sql/alter_table_set_am.sql
@@ -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);
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cloudberry.apache.org
For additional commands, e-mail: commits-help@cloudberry.apache.org