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

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


The following commit(s) were added to refs/heads/main by this push:
     new ec0c86e5a1 Enhance the code style and some fixes of IVM (#829)
ec0c86e5a1 is described below

commit ec0c86e5a1af42187ff277ba1663a5c318623400
Author: Yongtao Huang <[email protected]>
AuthorDate: Thu Jan 2 11:14:04 2025 +0800

    Enhance the code style and some fixes of IVM (#829)
    
    * Function make_delta_ts_name() and func make_delta_enr_name() are 
identical, make it an extern function.
    * Fix a wrong placeholder. Reduce the scope of var *pDump, and value 
processed is reassigned
    * Reassigned operation is introduced at commit 2bf926fe. No need the 
previous code and comments.
    * Fix the argument order diff between declaration and definition. This 
mistake is from pg_ivm.
---
 src/backend/commands/matview.c | 49 +++++++++---------------------------------
 src/backend/commands/trigger.c | 11 +++++-----
 src/include/commands/trigger.h |  2 ++
 3 files changed, 17 insertions(+), 45 deletions(-)

diff --git a/src/backend/commands/matview.c b/src/backend/commands/matview.c
index 75ecfe5039..5065f063a1 100644
--- a/src/backend/commands/matview.c
+++ b/src/backend/commands/matview.c
@@ -184,7 +184,6 @@ static Query *get_matview_query(Relation matviewRel);
 static Query *rewrite_query_for_preupdate_state(Query *query, List *tables,
                                                                  ParseState 
*pstate, Oid matviewid);
 static void register_delta_ENRs(ParseState *pstate, Query *query, List 
*tables);
-static char *make_delta_enr_name(const char *prefix, Oid relid, int count);
 static RangeTblEntry *get_prestate_rte(RangeTblEntry *rte, MV_TriggerTable 
*table,
                                 QueryEnvironment *queryEnv, Oid matviewid);
 static RangeTblEntry *replace_rte_with_delta(RangeTblEntry *rte, 
MV_TriggerTable *table, bool is_new,
@@ -829,16 +828,6 @@ refresh_matview_datafill(DestReceiver *dest, Query *query,
        /* run the plan */
        ExecutorRun(queryDesc, ForwardScanDirection, 0L, true);
 
-       /*
-        * GPDB: The total processed tuples here is always 0 on QD since we get 
it
-        * before we fetch the total processed tuples from segments(which is 
done by
-        * ExecutorEnd).
-        * In upstream, the number is used to update pgstat, but in GPDB we do 
the
-        * pgstat update on segments.
-        * Since the processed is not used, no need to get correct value here.
-        */
-       processed = queryDesc->estate->es_processed;
-
        /* and clean up */
        ExecutorFinish(queryDesc);
        ExecutorEnd(queryDesc);
@@ -2089,7 +2078,7 @@ register_delta_ENRs(ParseState *pstate, Query *query, 
List *tables)
                        if (freezed || shared_name)
                                enr->md.name = pstrdup(shared_name);
                        else
-                               enr->md.name = make_delta_enr_name("old", 
table->table_id, gp_command_count);
+                               enr->md.name = MakeDeltaName("old", 
table->table_id, gp_command_count);
                        enr->md.reliddesc = table->table_id;
                        enr->md.tupdesc = 
CreateTupleDescCopy(table->rel->rd_att);
                        enr->md.enrtype = ENR_NAMED_TUPLESTORE;
@@ -2127,7 +2116,7 @@ register_delta_ENRs(ParseState *pstate, Query *query, 
List *tables)
                        if (freezed || shared_name)
                                enr->md.name = pstrdup(shared_name);
                        else
-                               enr->md.name = make_delta_enr_name("new", 
table->table_id, gp_command_count);
+                               enr->md.name = MakeDeltaName("new", 
table->table_id, gp_command_count);
                        enr->md.reliddesc = table->table_id;
                        enr->md.tupdesc = 
CreateTupleDescCopy(table->rel->rd_att);
                        enr->md.enrtype = ENR_NAMED_TUPLESTORE;
@@ -2294,24 +2283,6 @@ get_prestate_rte(RangeTblEntry *rte, MV_TriggerTable 
*table,
        return rte;
 }
 
-/*
- * make_delta_enr_name
- *
- * Make a name for ENR of a transition table from the base table's oid.
- * prefix will be "new" or "old" depending on its transition table kind..
- */
-static char*
-make_delta_enr_name(const char *prefix, Oid relid, int count)
-{
-       char buf[NAMEDATALEN];
-       char *name;
-
-       snprintf(buf, NAMEDATALEN, "__ivm_%s_%u_%u", prefix, relid, count);
-       name = pstrdup(buf);
-
-       return name;
-}
-
 /*
  * replace_rte_with_delta
  *
@@ -2443,7 +2414,7 @@ calc_delta_old(Tuplestorestate *ts, Relation matviewRel, 
MV_TriggerTable *table,
        {
                /* Replace the modified table with the old delta table and 
calculate the old view delta. */
                replace_rte_with_delta(rte, table, false, queryEnv);
-               enrname = make_delta_enr_name(OLD_DELTA_ENRNAME, 
RelationGetRelid(matviewRel), gp_command_count);
+               enrname = MakeDeltaName(OLD_DELTA_ENRNAME, 
RelationGetRelid(matviewRel), gp_command_count);
                es_processed = refresh_matview_memoryfill(dest_old, query, 
queryEnv,
                                                                        
tupdesc_old, enrname, matviewRel);
                if (ts)
@@ -2469,7 +2440,7 @@ calc_delta_new(Tuplestorestate *ts, Relation matviewRel, 
MV_TriggerTable *table,
        {
                /* Replace the modified table with the new delta table and 
calculate the new view delta*/
                replace_rte_with_delta(rte, table, true, queryEnv);
-               enrname = make_delta_enr_name(NEW_DELTA_ENRNAME, 
RelationGetRelid(matviewRel), gp_command_count);
+               enrname = MakeDeltaName(NEW_DELTA_ENRNAME, 
RelationGetRelid(matviewRel), gp_command_count);
                es_processed = refresh_matview_memoryfill(dest_new, query, 
queryEnv,
                                                                        
tupdesc_new, enrname, matviewRel);
                if (ts)
@@ -2670,8 +2641,8 @@ apply_delta(char *old_enr, char *new_enr, MV_TriggerTable 
*table, Oid matviewOid
                /* apply new delta */
                if (use_count)
                        apply_new_delta_with_count(matviewname, enr->md.name,
-                                                                               
keys, aggs_set_new,
-                                                                               
&target_list_buf, count_colname);
+                                                                               
keys, &target_list_buf,
+                                                                               
aggs_set_new, count_colname);
                else
                        apply_new_delta(matviewname, enr->md.name, 
&target_list_buf);
        }
@@ -2989,7 +2960,7 @@ apply_old_delta_with_count(const char *matviewname, Oid 
matviewRelid, const char
                                        matviewname);
 #else
        /* CBDB_IVM_FIXME: use tuplestore to replace temp table. */
-       tempTableName = make_delta_enr_name("temp_old_delta", matviewRelid, 
gp_command_count);
+       tempTableName = MakeDeltaName("temp_old_delta", matviewRelid, 
gp_command_count);
 
        initStringInfo(&tselect);
        initStringInfo(&querybuf);
@@ -3109,7 +3080,7 @@ apply_old_delta(const char *matviewname, const char 
*deltaname_old,
  */
 static void
 apply_new_delta_with_count(const char *matviewname, const char* deltaname_new,
-                               List *keys, StringInfo aggs_set, StringInfo 
target_list,
+                               List *keys, StringInfo target_list, StringInfo 
aggs_set,
                                const char* count_colname)
 {
        StringInfoData  querybuf;
@@ -3431,10 +3402,10 @@ clean_up_IVM_hash_entry(MV_TriggerHashEntry *entry, 
bool is_abort)
 static void
 clean_up_ivm_dsm_entry(MV_TriggerHashEntry *entry)
 {
-       SnapshotDumpEntry       *pDump;
        if (entry->snapname && entry->snapname[0] != '\0' && Gp_is_writer)
        {
-               bool found;
+               bool                            found;
+               SnapshotDumpEntry       *pDump;
                LWLockAcquire(GPIVMResLock, LW_EXCLUSIVE);
                pDump = (SnapshotDumpEntry *) hash_search(mv_trigger_snapshot,
                                                                                
                        (void *)entry->snapname,
diff --git a/src/backend/commands/trigger.c b/src/backend/commands/trigger.c
index 1d2c0eed5c..2ba6c066ca 100644
--- a/src/backend/commands/trigger.c
+++ b/src/backend/commands/trigger.c
@@ -101,7 +101,6 @@ static void AfterTriggerSaveEvent(EState *estate, 
ResultRelInfo *relinfo,
 static void AfterTriggerEnlargeQueryState(void);
 static bool before_stmt_triggers_fired(Oid relid, CmdType cmdType);
 
-static char* make_delta_ts_name(const char *prefix, Oid relid, int count);
 /*
  * Create a trigger.  Returns the address of the created trigger.
  *
@@ -4486,13 +4485,13 @@ SetTransitionTableName(Oid relid, CmdType cmdType, Oid 
mvoid)
                {
                        if (table->new_tuplestore)
                        {
-                               char *name = make_delta_ts_name("new", relid, 
gp_command_count);
+                               char *name = MakeDeltaName("new", relid, 
gp_command_count);
                                
tuplestore_set_sharedname(table->new_tuplestore, name);
                                tuplestore_set_tableid(table->new_tuplestore, 
relid);
                        }
                        if (table->old_tuplestore)
                        {
-                               char *name = make_delta_ts_name("old", relid, 
gp_command_count);
+                               char *name = MakeDeltaName("old", relid, 
gp_command_count);
                                
tuplestore_set_sharedname(table->old_tuplestore, name);
                                tuplestore_set_tableid(table->old_tuplestore, 
relid);
                        }
@@ -6175,13 +6174,13 @@ pg_trigger_depth(PG_FUNCTION_ARGS)
        PG_RETURN_INT32(MyTriggerDepth);
 }
 
-static char*
-make_delta_ts_name(const char *prefix, Oid relid, int count)
+char*
+MakeDeltaName(const char *prefix, Oid relid, int count)
 {
        char buf[NAMEDATALEN];
        char *name;
 
-       snprintf(buf, NAMEDATALEN, "__ivm_%s_%u_%u", prefix, relid, count);
+       snprintf(buf, NAMEDATALEN, "__ivm_%s_%u_%d", prefix, relid, count);
        name = pstrdup(buf);
 
        return name;
diff --git a/src/include/commands/trigger.h b/src/include/commands/trigger.h
index 832e229b88..995ba509cc 100644
--- a/src/include/commands/trigger.h
+++ b/src/include/commands/trigger.h
@@ -259,6 +259,8 @@ extern List* AfterTriggerGetMvList(void);
 extern void AfterTriggerAppendMvList(Oid matview_id);
 extern void SetTransitionTableName(Oid relid, CmdType cmdType, Oid mvoid);
 
+extern char* MakeDeltaName(const char *prefix, Oid relid, int count);
+
 /*
  * in utils/adt/ri_triggers.c
  */


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

Reply via email to