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 cdbc1f79d1 Optimize code of IVM and fix some typos (#833)
cdbc1f79d1 is described below
commit cdbc1f79d1c37822dcdb3869aca1185615f1efa6
Author: Yongtao Huang <[email protected]>
AuthorDate: Tue Jan 7 17:42:31 2025 +0800
Optimize code of IVM and fix some typos (#833)
In pg_ivm, the variable count is required and is applied in the function
make_delta_enr_name,
but in cbdb, we use gp_command_count instead of count in MakeDeltaName.
---
src/backend/commands/matview.c | 32 +++++++++++++-------------------
1 file changed, 13 insertions(+), 19 deletions(-)
diff --git a/src/backend/commands/matview.c b/src/backend/commands/matview.c
index 8bd075e870..8448d2335f 100644
--- a/src/backend/commands/matview.c
+++ b/src/backend/commands/matview.c
@@ -663,7 +663,7 @@ ExecRefreshMatView(RefreshMatViewStmt *stmt, const char
*queryString,
refreshClause = MakeRefreshClause(concurrent, stmt->skipData,
stmt->relation);
/*
- * Only in dispather role, we should set intoPolicy, else it should
remain NULL.
+ * Only in dispatcher role, we should set intoPolicy, else it should
remain NULL.
*/
if (GP_ROLE_DISPATCH == Gp_role)
{
@@ -708,7 +708,7 @@ ExecRefreshMatView(RefreshMatViewStmt *stmt, const char
*queryString,
* QD, so both the segments and coordinator will have pgstat
for this
* relation. See pgstat_combine_from_qe(pgstat.c) for more
details.
* Then comment out the below codes on the dispatcher side and
leave
- * the current comment to avoid futher upstream merge issues.
+ * the current comment to avoid further upstream merge issues.
* The pgstat is updated in function transientrel_shutdown on
QE side.
* This related to issue:
https://github.com/greenplum-db/gpdb/issues/11375
*/
@@ -2014,7 +2014,7 @@ rewrite_query_for_preupdate_state(Query *query, List
*tables,
RangeTblEntry *rte_pre = get_prestate_rte(r,
table, pstate->p_queryEnv, matviewid);
/*
- * Set a row security poslicies of the modified
table to the subquery RTE which
+ * Set a row security policies of the modified
table to the subquery RTE which
* represents the pre-update state of the table.
*/
get_row_security_policies(query,
table->original_rte, i,
@@ -2063,9 +2063,7 @@ register_delta_ENRs(ParseState *pstate, Query *query,
List *tables)
{
MV_TriggerTable *table = (MV_TriggerTable *) lfirst(lc);
ListCell *lc2;
- int count;
- count = 0;
foreach(lc2, table->old_tuplestores)
{
Tuplestorestate *oldtable = (Tuplestorestate *)
lfirst(lc2);
@@ -2090,7 +2088,6 @@ register_delta_ENRs(ParseState *pstate, Query *query,
List *tables)
rte = nsitem->p_rte;
query->rtable = list_append_unique_ptr(query->rtable,
rte);
- count++;
/* Note: already freezed case */
if (freezed)
{
@@ -2103,7 +2100,6 @@ register_delta_ENRs(ParseState *pstate, Query *query,
List *tables)
tuplestore_freeze(oldtable);
}
- count = 0;
foreach(lc2, table->new_tuplestores)
{
Tuplestorestate *newtable = (Tuplestorestate *)
lfirst(lc2);
@@ -2129,7 +2125,6 @@ register_delta_ENRs(ParseState *pstate, Query *query,
List *tables)
query->rtable = list_append_unique_ptr(query->rtable,
rte);
- count++;
/* Note: already freezed case */
if (freezed)
{
@@ -2327,7 +2322,7 @@ replace_rte_with_delta(RangeTblEntry *rte,
MV_TriggerTable *table, bool is_new,
sub = transformStmt(pstate, raw->stmt);
/*
- * Update the subquery so that it represent the combined transition
+ * Update the subquery so that it represents the combined transition
* table. Note that we leave the security_barrier and securityQuals
* fields so that the subquery relation can be protected by the RLS
* policy as same as the modified table.
@@ -2922,7 +2917,6 @@ apply_old_delta_with_count(const char *matviewname, Oid
matviewRelid, const char
const char * tempTableName;
StringInfoData querybuf;
- StringInfoData tselect;
char *match_cond;
bool agg_without_groupby = (list_length(keys) == 0);
@@ -2962,9 +2956,8 @@ apply_old_delta_with_count(const char *matviewname, Oid
matviewRelid, const char
/* CBDB_IVM_FIXME: use tuplestore to replace temp table. */
tempTableName = MakeDeltaName("temp_old_delta", matviewRelid,
gp_command_count);
- initStringInfo(&tselect);
initStringInfo(&querybuf);
- appendStringInfo(&tselect,
+ appendStringInfo(&querybuf,
"CREATE TEMP TABLE %s AS SELECT
diff.%s, " /* count column */
"(diff.%s
OPERATOR(pg_catalog.=) mv.%s AND %s) AS for_dlt, "
"mv.ctid AS
tid, mv.gp_segment_id AS gid"
@@ -2979,11 +2972,12 @@ apply_old_delta_with_count(const char *matviewname, Oid
matviewRelid, const char
match_cond);
/* Create the temporary table. */
- if (SPI_exec(tselect.data, 0) != SPI_OK_UTILITY)
- elog(ERROR, "SPI_exec failed: %s", tselect.data);
- elogif(Debug_print_ivm, INFO, "IVM apply_old_delta_with_count select:
%s", tselect.data);
+ if (SPI_exec(querybuf.data, 0) != SPI_OK_UTILITY)
+ elog(ERROR, "SPI_exec failed: %s", querybuf.data);
+ elogif(Debug_print_ivm, INFO, "IVM apply_old_delta_with_count select:
%s", querybuf.data);
/* Search for matching tuples from the view and update or delete if
found. */
+ resetStringInfo(&querybuf);
appendStringInfo(&querybuf,
"UPDATE %s AS mv SET %s = mv.%s
OPERATOR(pg_catalog.-) t.%s "
"%s" /* SET clauses for aggregates */
@@ -3117,7 +3111,7 @@ apply_new_delta_with_count(const char *matviewname, const
char* deltaname_new,
"FROM %s AS diff "
"WHERE %s "
/* tuple matching condition */
"RETURNING %s"
/* returning keys of updated tuples */
- ") INSERT INTO %s (%s)" /* insert a new
tuple if this doesn't existw */
+ ") INSERT INTO %s (%s)" /* insert a new
tuple if this doesn't exist */
"SELECT %s FROM %s AS diff "
"WHERE NOT EXISTS (SELECT 1
FROM updt AS mv WHERE %s);",
matviewname, count_colname,
count_colname, count_colname,
@@ -3144,7 +3138,7 @@ apply_new_delta_with_count(const char *matviewname, const
char* deltaname_new,
resetStringInfo(&querybuf);
appendStringInfo(&querybuf,
- "INSERT INTO %s (%s)" /* insert a new
tuple if this doesn't existw */
+ "INSERT INTO %s (%s)" /* insert a new
tuple if this doesn't exist */
"SELECT %s FROM %s AS diff "
"WHERE NOT EXISTS (SELECT 1
FROM %s AS mv WHERE %s);",
matviewname, target_list->data,
@@ -3223,7 +3217,7 @@ get_matching_condition_string(List *keys)
}
/*
- * generate_equals
+ * generate_equal
*
* Generate an equality clause using given operands' default equality
* operator.
@@ -3857,7 +3851,7 @@ makeIvmIntoClause(const char *enrname, Relation
matviewRel)
{
IntoClause *intoClause = makeNode(IntoClause);
intoClause->ivm = true;
- /* rel is NULL means put tuples into memory.*/
+ /* rel is NULL means putting tuples into memory.*/
intoClause->rel = NULL;
intoClause->enrname = (char*) enrname;
intoClause->distributedBy = (Node*)
make_distributedby_for_rel(matviewRel);
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]