You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudberry.apache.org by av...@apache.org on 2025/01/09 02:02:52 UTC

(cloudberry) 08/17: FIX BUG: apply get_ao_compression_ratio() to a root partitioned table with AO children (7X) (#15390)

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

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

commit f9ec484db1c934a408dd1dd68e529f01d68af93f
Author: Yongtao Huang <99...@users.noreply.github.com>
AuthorDate: Fri Apr 21 09:07:27 2023 +0800

    FIX BUG: apply get_ao_compression_ratio() to a root partitioned table with AO children (7X) (#15390)
    
    This commit can fix the bug reported in [issue 14876](https://github.com/greenplum-db/gpdb/issues/14876).
    
    When the input of function get_ao_compression_ratio() is a  root partitioned table with ao children, GPDB7 should keep the same behavior as GPDB6, return `-1`  rather than `ERROR:  'foo_partition' is not an append-only relation`.
    
    **Solution** :
    -- step 1:
    Check the relaiton is AO/AOCS or not.
    If not, return error directly.
    -- step 2:
    Check the relaiton is PARTITIONED_TABLE or not.
    If so, return -1.
    
    **Signed-off-by**:
    Yongtao Huang <yo...@vmware.com>
    Xing Guo <gu...@vmware.com>
---
 src/backend/access/appendonly/aosegfiles.c     | 10 ++++++--
 src/test/regress/expected/AOCO_Compression.out | 32 ++++++++++++++++++++++++++
 src/test/regress/sql/AOCO_Compression.sql      | 25 ++++++++++++++++++++
 3 files changed, 65 insertions(+), 2 deletions(-)

diff --git a/src/backend/access/appendonly/aosegfiles.c b/src/backend/access/appendonly/aosegfiles.c
index 4c21354b36..5e9d3d48cf 100644
--- a/src/backend/access/appendonly/aosegfiles.c
+++ b/src/backend/access/appendonly/aosegfiles.c
@@ -1525,7 +1525,7 @@ get_ao_compression_ratio(PG_FUNCTION_ARGS)
 {
 	Oid			relid = PG_GETARG_OID(0);
 	Relation	parentrel;
-	float8		result;
+	float8		result = -1.0;
 
 	if (Gp_role == GP_ROLE_EXECUTE)
 		ereport(ERROR,
@@ -1534,12 +1534,18 @@ get_ao_compression_ratio(PG_FUNCTION_ARGS)
 	/* open the parent (main) relation */
 	parentrel = table_open(relid, AccessShareLock);
 
-	if (!RelationIsAppendOptimized(parentrel))
+	if (!(RelationIsAoRows(parentrel) || RelationIsAoCols(parentrel)))
 		ereport(ERROR,
 				(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
 				 errmsg("'%s' is not an append-only relation",
 						RelationGetRelationName(parentrel))));
 
+	if (parentrel->rd_rel->relkind == RELKIND_PARTITIONED_TABLE)
+	{
+		table_close(parentrel, AccessShareLock);
+		PG_RETURN_FLOAT8(result);
+	}
+
 	if (RelationIsAoRows(parentrel))
 		result = aorow_compression_ratio_internal(parentrel);
 	else
diff --git a/src/test/regress/expected/AOCO_Compression.out b/src/test/regress/expected/AOCO_Compression.out
index bd93a8fc9b..7fcfa10564 100644
--- a/src/test/regress/expected/AOCO_Compression.out
+++ b/src/test/regress/expected/AOCO_Compression.out
@@ -3676,3 +3676,35 @@ SELECT * FROM pg_compression WHERE compname='rle_type';
  rle_type | gp_rle_type_constructor | gp_rle_type_destructor | gp_rle_type_compress | gp_rle_type_decompress | gp_rle_type_validator |        10
 (1 row)
 
+-- Check ALTER TYPE SET DEFAULT ENCODING propagates to the dependent array type
+DROP type if exists mood_encoded cascade;
+CREATE TYPE mood_encoded AS ENUM ('sad', 'ok', 'happy');
+ALTER TYPE public.mood_encoded SET DEFAULT ENCODING (compresstype=zlib, blocksize=65536, compresslevel=4);
+SELECT t.typname, te.typoptions
+FROM pg_type t
+LEFT JOIN pg_type_encoding te ON (t.oid=te.typid)
+WHERE t.typname in ('mood_encoded', '_mood_encoded');
+    typname    |                     typoptions                      
+---------------+-----------------------------------------------------
+ _mood_encoded | {compresstype=zlib,blocksize=65536,compresslevel=4}
+ mood_encoded  | {compresstype=zlib,blocksize=65536,compresslevel=4}
+(2 rows)
+
+-- get_ao_compression_ratio when the relation is a partitioned table with ao table children.
+-- please refer to https://github.com/greenplum-db/gpdb/issues/14876
+CREATE TABLE public.partitioned_table_14876
+(id SERIAL, value TEXT, sales_date date)
+WITH (appendoptimized=true, orientation=column, compresstype=zlib, compresslevel=5)
+DISTRIBUTED BY (id)
+PARTITION BY RANGE (sales_date)
+(
+  -- monthly
+  START (date '2020-12-01') INCLUSIVE END (date '2021-01-01') EXCLUSIVE  EVERY (INTERVAL '1 month')
+);
+SELECT get_ao_compression_ratio('public.partitioned_table_14876');
+ get_ao_compression_ratio 
+------------
+                       -1
+(1 row)
+
+DROP TABLE public.partitioned_table_14876;
diff --git a/src/test/regress/sql/AOCO_Compression.sql b/src/test/regress/sql/AOCO_Compression.sql
index 524ffc9420..740369ddfb 100644
--- a/src/test/regress/sql/AOCO_Compression.sql
+++ b/src/test/regress/sql/AOCO_Compression.sql
@@ -1806,3 +1806,28 @@ create table a_aoco_table_with_rle_type_and_invalid_compression_level(col int) W
 
 -- Check that callbacks are registered
 SELECT * FROM pg_compression WHERE compname='rle_type';
+
+-- Check ALTER TYPE SET DEFAULT ENCODING propagates to the dependent array type
+DROP type if exists mood_encoded cascade;
+
+CREATE TYPE mood_encoded AS ENUM ('sad', 'ok', 'happy');
+ALTER TYPE public.mood_encoded SET DEFAULT ENCODING (compresstype=zlib, blocksize=65536, compresslevel=4);
+
+SELECT t.typname, te.typoptions
+FROM pg_type t
+LEFT JOIN pg_type_encoding te ON (t.oid=te.typid)
+WHERE t.typname in ('mood_encoded', '_mood_encoded');
+
+-- get_ao_compression_ratio when the relation is a partitioned table with ao table children.
+-- please refer to https://github.com/greenplum-db/gpdb/issues/14876
+CREATE TABLE public.partitioned_table_14876
+(id SERIAL, value TEXT, sales_date date)
+WITH (appendoptimized=true, orientation=column, compresstype=zlib, compresslevel=5)
+DISTRIBUTED BY (id)
+PARTITION BY RANGE (sales_date)
+(
+  -- monthly
+  START (date '2020-12-01') INCLUSIVE END (date '2021-01-01') EXCLUSIVE  EVERY (INTERVAL '1 month')
+);
+SELECT get_ao_compression_ratio('public.partitioned_table_14876');
+DROP TABLE public.partitioned_table_14876;


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cloudberry.apache.org
For additional commands, e-mail: commits-help@cloudberry.apache.org