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 44c1e6d3f1f1a1df095d782de9a9680bbf38e32d
Author: reshke <[email protected]>
AuthorDate: Mon Jan 27 05:24:51 2025 +0000

    Resolve cherry-pick issues. Bring back toast_tuple_target logic.
---
 src/backend/access/appendonly/appendonlyam.c  |  2 +-
 src/backend/access/common/reloptions_gp.c     | 54 +++++++++++++++++++++++++++
 src/backend/access/heap/heaptoast.c           | 10 ++---
 src/backend/commands/tablecmds.c              |  4 +-
 src/include/access/heaptoast.h                |  2 +-
 src/include/access/reloptions.h               |  2 +
 src/test/regress/expected/expand_table_ao.out |  6 +--
 src/test/regress/expected/toast.out           |  2 +-
 8 files changed, 69 insertions(+), 13 deletions(-)

diff --git a/src/backend/access/appendonly/appendonlyam.c 
b/src/backend/access/appendonly/appendonlyam.c
index b4159a41bc..5fdfe51f3e 100755
--- a/src/backend/access/appendonly/appendonlyam.c
+++ b/src/backend/access/appendonly/appendonlyam.c
@@ -2897,7 +2897,7 @@ appendonly_insert(AppendOnlyInsertDesc aoInsertDesc,
         */
        if (need_toast)
                tup = memtup_toast_insert_or_update(relation, instup,
-                                                                               
        NULL, aoInsertDesc->mt_bind, 0);
+                                                                               
        NULL, aoInsertDesc->mt_bind, aoInsertDesc->toast_tuple_target, 0);
        else
                tup = instup;
 
diff --git a/src/backend/access/common/reloptions_gp.c 
b/src/backend/access/common/reloptions_gp.c
index 77f2f86bb1..a42140af4c 100644
--- a/src/backend/access/common/reloptions_gp.c
+++ b/src/backend/access/common/reloptions_gp.c
@@ -1968,3 +1968,57 @@ ao_amoptions(Datum reloptions, char relkind, bool 
validate)
                        return NULL;
        }
 }
+
+/*
+ * GPDB: Convenience function to judge a relation option whether already in 
opts
+ */
+bool
+reloptions_has_opt(List *opts, const char *name)
+{
+       ListCell *lc;
+       foreach(lc, opts)
+       {
+               DefElem *de = lfirst(lc);
+               if (pg_strcasecmp(de->defname, name) == 0)
+                       return true;
+       }
+       return false;
+}
+
+/*
+ * GPDB: Convenience function to build storage reloptions for a given 
relation, just for AO table.
+ */
+List *
+build_ao_rel_storage_opts(List *opts, Relation rel)
+{
+       bool            checksum = true;
+       int32           blocksize = -1;
+       int16           compresslevel = 0;
+       char       *compresstype = NULL;
+       NameData        compresstype_nd;
+
+       GetAppendOnlyEntryAttributes(RelationGetRelid(rel),
+                                                                &blocksize,
+                                                                NULL,
+                                                                &compresslevel,
+                                                                &checksum,
+                                                                
&compresstype_nd);
+       compresstype = NameStr(compresstype_nd);
+
+       if (!reloptions_has_opt(opts, "blocksize"))
+               opts = lappend(opts, makeDefElem("blocksize", (Node *) 
makeInteger(blocksize), -1));
+
+       if (!reloptions_has_opt(opts, "compresslevel"))
+               opts = lappend(opts, makeDefElem("compresslevel", (Node *) 
makeInteger(compresslevel), -1));
+
+       if (!reloptions_has_opt(opts, "checksum"))
+               opts = lappend(opts, makeDefElem("checksum", (Node *) 
makeInteger(checksum), -1));
+
+       if (!reloptions_has_opt(opts, "compresstype"))
+       {
+               compresstype = (compresstype && compresstype[0]) ? 
pstrdup(compresstype) : "none";
+               opts = lappend(opts, makeDefElem("compresstype", (Node *) 
makeString(compresstype), -1));
+       }
+
+       return opts;
+}
diff --git a/src/backend/access/heap/heaptoast.c 
b/src/backend/access/heap/heaptoast.c
index 5fdf704106..2ba251efc0 100644
--- a/src/backend/access/heap/heaptoast.c
+++ b/src/backend/access/heap/heaptoast.c
@@ -35,7 +35,7 @@
 
 static void *
 heap_toast_insert_or_update_generic(Relation rel, void *newtup, void *oldtup,
-                                                                       
MemTupleBinding *pbind, int options, bool ismemtuple);
+                                                                       
MemTupleBinding *pbind, int options, int toast_tuple_target, bool ismemtuple);
 
 /* ----------
  * heap_toast_delete -
@@ -100,18 +100,18 @@ heap_toast_delete(Relation rel, HeapTuple oldtup, bool 
is_speculative)
 HeapTuple
 heap_toast_insert_or_update(Relation rel, HeapTuple newtup, HeapTuple oldtup, 
int options)
 {
-       return (HeapTuple) heap_toast_insert_or_update_generic(rel, newtup, 
oldtup, NULL, options, false);
+       return (HeapTuple) heap_toast_insert_or_update_generic(rel, newtup, 
oldtup, NULL, options, TOAST_TUPLE_TARGET, false);
 }
 
 MemTuple memtup_toast_insert_or_update(Relation rel, MemTuple newtup, MemTuple 
oldtup,
-                                                                          
MemTupleBinding *pbind, int options)
+                                                                          
MemTupleBinding *pbind, int toast_tuple_target, int options)
 {
-       return (MemTuple) heap_toast_insert_or_update_generic(rel, newtup, 
oldtup, pbind, options, true);
+       return (MemTuple) heap_toast_insert_or_update_generic(rel, newtup, 
oldtup, pbind, toast_tuple_target, options, true);
 }
 
 static void *
 heap_toast_insert_or_update_generic(Relation rel, void *newtup, void *oldtup,
-                                                                       
MemTupleBinding *pbind, int options, bool ismemtuple)
+                                                                       
MemTupleBinding *pbind, int options, int toast_tuple_target, bool ismemtuple)
 {
        void            *result_gtuple;
        TupleDesc       tupleDesc;
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index f8b5606019..f3102687ca 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -17888,7 +17888,7 @@ build_ctas_with_dist(Relation rel, DistributedBy 
*dist_clause,
 
        pre_built = prebuild_temp_table(rel, tmprel, dist_clause,
                                                                        
get_am_name(rel->rd_rel->relam),
-                                                                       
storage_opts,
+                                                                       
RelationIsAppendOptimized(rel) ? build_ao_rel_storage_opts(NIL, rel) : 
storage_opts,
                                                                        
RelationIsAppendOptimized(rel),
                                                                        
useExistingColumnAttributes);
        if (pre_built)
@@ -17912,7 +17912,7 @@ build_ctas_with_dist(Relation rel, DistributedBy 
*dist_clause,
                into->options = storage_opts;
                into->tableSpaceName = get_tablespace_name(tblspc);
                into->distributedBy = (Node *)dist_clause;
-               if (RelationIsAoRows(rel))
+               if (RelationIsAppendOptimized(rel))
                {
                        /*
                         * In order to avoid being affected by the GUC of 
gp_default_storage_options,
diff --git a/src/include/access/heaptoast.h b/src/include/access/heaptoast.h
index 510af1a48c..56a792d749 100644
--- a/src/include/access/heaptoast.h
+++ b/src/include/access/heaptoast.h
@@ -104,7 +104,7 @@
  */
 extern HeapTuple heap_toast_insert_or_update(Relation rel, HeapTuple newtup, 
HeapTuple oldtup, int options);
 extern MemTuple memtup_toast_insert_or_update(Relation rel, MemTuple newtup, 
MemTuple oldtup,
-                                                                               
          MemTupleBinding *pbind, int options);
+                                                                               
          MemTupleBinding *pbind, int toast_tuple_target, int options);
 
 /* ----------
  * heap_toast_delete -
diff --git a/src/include/access/reloptions.h b/src/include/access/reloptions.h
index 719f67b0e2..82d421068f 100644
--- a/src/include/access/reloptions.h
+++ b/src/include/access/reloptions.h
@@ -312,6 +312,8 @@ List* transfromColumnEncodingAocoRootPartition(List 
*colDefs, List *stenc, List
 extern List *transformStorageEncodingClause(List *options, bool validate);
 extern List *form_default_storage_directive(List *enc);
 extern bool is_storage_encoding_directive(const char *name);
+extern bool reloptions_has_opt(List *opts, const char *name);
+extern List *build_ao_rel_storage_opts(List *opts, Relation rel);
 
 extern relopt_value *
 parseRelOptions(Datum options, bool validate, relopt_kind kind, int 
*numrelopts);
diff --git a/src/test/regress/expected/expand_table_ao.out 
b/src/test/regress/expected/expand_table_ao.out
index 57c3dd55f3..e7e8d1d666 100644
--- a/src/test/regress/expected/expand_table_ao.out
+++ b/src/test/regress/expected/expand_table_ao.out
@@ -739,7 +739,7 @@ select localoid::regclass::name, policytype, numsegments, 
distkey, distclass
 from gp_distribution_policy where localoid = 't_9526'::regclass::oid;
  localoid | policytype | numsegments | distkey | distclass 
 ----------+------------+-------------+---------+-----------
- t_9526   | p          |           3 | 1       | 10054
+ t_9526   | p          |           3 | 1       | 10020
 (1 row)
 
 -- storage paramter should be same with before
@@ -779,7 +779,7 @@ select localoid::regclass::name, policytype, numsegments, 
distkey, distclass
     from gp_distribution_policy where localoid = 't_9527'::regclass::oid;
  localoid | policytype | numsegments | distkey | distclass 
 ----------+------------+-------------+---------+-----------
- t_9527   | p          |           3 | 1       | 10054
+ t_9527   | p          |           3 | 1       | 10020
 (1 row)
 
 -- storage paramter should be same with before
@@ -818,7 +818,7 @@ select localoid::regclass::name, policytype, numsegments, 
distkey, distclass
     from gp_distribution_policy where localoid = 't_9528'::regclass::oid;
  localoid | policytype | numsegments | distkey | distclass 
 ----------+------------+-------------+---------+-----------
- t_9528   | p          |           2 | 2       | 10072
+ t_9528   | p          |           2 | 2       | 10039
 (1 row)
 
 -- storage paramter should be same with before
diff --git a/src/test/regress/expected/toast.out 
b/src/test/regress/expected/toast.out
index 6650facc0d..8f6073b0d4 100644
--- a/src/test/regress/expected/toast.out
+++ b/src/test/regress/expected/toast.out
@@ -130,7 +130,7 @@ select gp_segment_id, get_rel_toast_count('toastable_heap') 
from gp_dist_random(
 select gp_segment_id, get_rel_toast_count('toastable_ao') from 
gp_dist_random('gp_id') order by gp_segment_id;
  gp_segment_id | get_rel_toast_count 
 ---------------+---------------------
-             0 |                  13
+             0 |                  14
              1 |                   0
              2 |                   0
 (3 rows)


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to