Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ADBDEV-3174: New GUC to inherit storage options with ALTER TABLE ADD PARTITION #618

Open
wants to merge 50 commits into
base: adb-6.x-dev
Choose a base branch
from

Conversation

RekGRpth
Copy link
Member

@RekGRpth RekGRpth commented Sep 13, 2023

AO table inherit storage options with ALTER TABLE ADD PARTITION

Add the gp_add_partition_inherits_table_setting GUC for AO tables. Its default
value is false. When the GUC is set to true, the ALTER TABLE ADD PARTITION
query will add new partitions with storage options (appendonly, orientation,
compresstype, compresslevel, blocksize and checksum) inherited from the parent
table (unless these options are explicitly specified in the DDL or subpartition
template).

@BenderArenadata
Copy link

Allure report https://allure-ee.adsw.io/launch/54185

@BenderArenadata
Copy link

Allure report https://allure-ee.adsw.io/launch/54272

@RekGRpth RekGRpth changed the title ADBDEV-3174: adding gp_add_partition_inherits_table_setting GUC ADBDEV-3174: New GUC for inheriting storage options with ALTER TABLE ADD PARTITION Sep 14, 2023
@RekGRpth RekGRpth changed the title ADBDEV-3174: New GUC for inheriting storage options with ALTER TABLE ADD PARTITION ADBDEV-3174: New GUC to inherit storage options with ALTER TABLE ADD PARTITION Sep 14, 2023
@BenderArenadata
Copy link

Allure report https://allure-ee.adsw.io/launch/54329

When a new partitioned table is created, its partitions inherit storage options
(appendonly, orientation, compresstype, compresslevel and blocksize)
from the parent table.
But when adding partitions using the ALTER TABLE ADD PARTITION command,
new partitions are added with storage options as specified in
gp_default_storage_options (unless these options are explicitly specified
in the DDL or subpartition template).

This patch adds a new GUC gp_add_partition_inherits_table_setting
with the default value false.
When set to true, the ALTER TABLE ADD PARTITION command will add new partitions
with storage options inherited from the parent table (unless these options
are explicitly specified in the DDL or subpartition template).
@RekGRpth RekGRpth marked this pull request as ready for review September 15, 2023 04:46
@BenderArenadata
Copy link

Allure report https://allure-ee.adsw.io/launch/54369

@andr-sokolov andr-sokolov self-requested a review September 15, 2023 09:21
@andr-sokolov
Copy link
Member

@RekGRpth , what about making changes in the transformAlterTable_all_PartitionStmt function? The function name begins with "transform", so I think it is more suitable place. The patch below is a draft.

diff --git a/src/backend/parser/parse_utilcmd.c b/src/backend/parser/parse_utilcmd.c
index b95ff4bb70..8018bc58a6 100644
--- a/src/backend/parser/parse_utilcmd.c
+++ b/src/backend/parser/parse_utilcmd.c
@@ -4884,6 +4884,24 @@ transformAlterTable_all_PartitionStmt(
                        heap_close(rel, AccessShareLock);
        } /* end if alter */
 
+       if (atc1->subtype == AT_PartAdd)
+       {
+               PartitionElem *pelem = (PartitionElem *) pc->arg1;
+               if (gp_add_partition_inherits_table_setting && pelem->storeAttr == NULL)
+               {
+                       AlterPartitionCmd *storenode = makeNode(AlterPartitionCmd);
+                       if (RelationIsAoRows(pCxt->rel) || RelationIsAoCols(pCxt->rel))
+                       {
+                               storenode->arg1 = (Node *)build_ao_rel_storage_opts(
+                                               list_make1(makeDefElem("appendonly", (Node *) makeString("true"))),
+                                               pCxt->rel);
+                       }
+
+                       storenode->location = -1;
+                       pelem->storeAttr = (Node *)storenode;
+               }
+       }
+
        switch (atc1->subtype)
        {
                case AT_PartAdd:                                /* Add */

@RekGRpth
Copy link
Member Author

what about making changes in the transformAlterTable_all_PartitionStmt function? The function name begins with "transform", so I think it is more suitable place.

moved

@BenderArenadata
Copy link

Allure report https://allure-ee.adsw.io/launch/55091

@BenderArenadata
Copy link

Allure report https://allure-ee.adsw.io/launch/55093

@andr-sokolov
Copy link
Member

@RekGRpth In the current version after this queries

SET gp_add_partition_inherits_table_setting = on;

CREATE TABLE ao_alter_add_part(a int, b int) WITH (appendonly=true, orientation=row, compresstype=zstd) DISTRIBUTED BY (a) PARTITION BY RANGE (b)
  (PARTITION "10" START (1) INCLUSIVE END (10) EXCLUSIVE,
   PARTITION "20" START (11) INCLUSIVE END (20) EXCLUSIVE);

ALTER TABLE ao_alter_add_part ADD PARTITION "30" START (20) INCLUSIVE END (30) EXCLUSIVE;

the added partition has more options than the table and these options are arranged in a different order

postgres=# \d+ ao_alter_add_part*
            Append-Only Table "public.ao_alter_add_part"
 Column |  Type   | Modifiers | Storage | Stats target | Description 
--------+---------+-----------+---------+--------------+-------------
 a      | integer |           | plain   |              | 
 b      | integer |           | plain   |              | 
Compression Type: zstd
Compression Level: 1
Block Size: 32768
Checksum: t
Child tables: ao_alter_add_part_1_prt_10,
              ao_alter_add_part_1_prt_20,
              ao_alter_add_part_1_prt_30
Distributed by: (a)
Partition by: (b)
Options: appendonly=true, orientation=row, compresstype=zstd

        Append-Only Table "public.ao_alter_add_part_1_prt_10"
 Column |  Type   | Modifiers | Storage | Stats target | Description 
--------+---------+-----------+---------+--------------+-------------
 a      | integer |           | plain   |              | 
 b      | integer |           | plain   |              | 
Compression Type: zstd
Compression Level: 1
Block Size: 32768
Checksum: t
Check constraints:
    "ao_alter_add_part_1_prt_10_check" CHECK (b >= 1 AND b < 10)
Inherits: ao_alter_add_part
Distributed by: (a)
Options: appendonly=true, orientation=row, compresstype=zstd

        Append-Only Table "public.ao_alter_add_part_1_prt_20"
 Column |  Type   | Modifiers | Storage | Stats target | Description 
--------+---------+-----------+---------+--------------+-------------
 a      | integer |           | plain   |              | 
 b      | integer |           | plain   |              | 
Compression Type: zstd
Compression Level: 1
Block Size: 32768
Checksum: t
Check constraints:
    "ao_alter_add_part_1_prt_20_check" CHECK (b >= 11 AND b < 20)
Inherits: ao_alter_add_part
Distributed by: (a)
Options: appendonly=true, orientation=row, compresstype=zstd

        Append-Only Table "public.ao_alter_add_part_1_prt_30"
 Column |  Type   | Modifiers | Storage | Stats target | Description 
--------+---------+-----------+---------+--------------+-------------
 a      | integer |           | plain   |              | 
 b      | integer |           | plain   |              | 
Compression Type: zstd
Compression Level: 1
Block Size: 32768
Checksum: t
Check constraints:
    "ao_alter_add_part_1_prt_30_check" CHECK (b >= 20 AND b < 30)
Inherits: ao_alter_add_part
Distributed by: (a)
Options: appendonly=true, blocksize=32768, compresslevel=1, checksum=true, compresstype=zstd, orientation=row

postgres=# 

What about this patch to fix the problem?

diff --git a/src/backend/cdb/cdbpartition.c b/src/backend/cdb/cdbpartition.c
index fc9fec0993..7bac71ddcb 100644
--- a/src/backend/cdb/cdbpartition.c
+++ b/src/backend/cdb/cdbpartition.c
@@ -6773,6 +6773,8 @@ atpxPartAddList(Relation rel,
 
 	if (pelem->storeAttr)
 		ct->options = (List *) ((AlterPartitionCmd *) pelem->storeAttr)->arg1;
+	else if (gp_add_partition_inherits_table_setting)
+		ct->options = reloptions_list(RelationGetRelid(rel));
 
 	ct->tableElts = list_concat(ct->tableElts, list_copy(colencs));
 
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 680516a758..f5d669dd80 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -14447,7 +14447,7 @@ drop_parent_dependency(Oid relid, Oid refclassid, Oid refobjid, bool is_partitio
 /*
  * deparse pg_class.reloptions into a list.
  */
-static List *
+List *
 reloptions_list(Oid relid)
 {
 	Datum		reloptions;
diff --git a/src/include/commands/tablecmds.h b/src/include/commands/tablecmds.h
index 6adee26dfd..be01f932b3 100644
--- a/src/include/commands/tablecmds.h
+++ b/src/include/commands/tablecmds.h
@@ -137,4 +137,5 @@ extern void RangeVarCallbackOwnsRelation(const RangeVar *relation,
 							 Oid relId, Oid oldRelId, void *noCatalogs);
 
 extern List * rel_get_column_encodings(Relation rel);
+extern List * reloptions_list(Oid relid);
 #endif   /* TABLECMDS_H */

@RekGRpth
Copy link
Member Author

What about this patch to fix the problem?

Applied.

@BenderArenadata
Copy link

Allure report https://allure-ee.adsw.io/launch/56366

@BenderArenadata
Copy link

Allure report https://allure-ee.adsw.io/launch/56370

@BenderArenadata
Copy link

Failed job Resource group isolation tests on x86_64: https://gitlab.adsw.io/arenadata/github_mirroring/gpdb/-/jobs/696864

@BenderArenadata
Copy link

Allure report https://allure-ee.adsw.io/launch/57991

@BenderArenadata
Copy link

Failed job Resource group isolation tests on x86_64: https://gitlab.adsw.io/arenadata/github_mirroring/gpdb/-/jobs/765914

@BenderArenadata
Copy link

Failed job Resource group isolation tests on ppc64le: https://gitlab.adsw.io/arenadata/github_mirroring/gpdb/-/jobs/765915

@RekGRpth
Copy link
Member Author

bender build

@BenderArenadata
Copy link

Allure report https://allure.adsw.io/launch/83263

@BenderArenadata
Copy link

Allure report https://allure.adsw.io/launch/83532

@BenderArenadata
Copy link

Allure report https://allure.adsw.io/launch/84210

@BenderArenadata
Copy link

Allure report https://allure.adsw.io/launch/84214

@BenderArenadata
Copy link

Allure report https://allure.adsw.io/launch/84218

@BenderArenadata
Copy link

Allure report https://allure.adsw.io/launch/84227

@BenderArenadata
Copy link

Allure report https://allure.adsw.io/launch/84235

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants