You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudberry.apache.org by ma...@apache.org on 2025/06/04 08:14:27 UTC

(cloudberry) branch main updated: [AQUMV] Remove aqumv_adjust_simple_query

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 a3bcbcb17b [AQUMV] Remove aqumv_adjust_simple_query
a3bcbcb17b is described below

commit a3bcbcb17b549ea265bc4e39c94ff63af0ebad8e
Author: Zhang Mingli <av...@gmail.com>
AuthorDate: Tue Jun 3 12:12:30 2025 +0800

    [AQUMV] Remove aqumv_adjust_simple_query
    
    With the view SQL now stored in the gp_matview_aux table, the use of
    rules that add OLD and NEW rtables for REFRESH is no longer necessary.
    This change may also speed up the AQUMV process.
    
    We are storing the raw view SQL without any modifications, eliminating
    the need to call aqumv_adjust_simple_query to adjust the SQL to a
    standard format.
    
    Authored-by: Zhang Mingli avamingli@gmail.com
---
 src/backend/catalog/gp_matview_aux.c |   6 +-
 src/backend/optimizer/plan/aqumv.c   | 116 -----------------------------------
 src/include/optimizer/aqumv.h        |   7 ---
 3 files changed, 1 insertion(+), 128 deletions(-)

diff --git a/src/backend/catalog/gp_matview_aux.c b/src/backend/catalog/gp_matview_aux.c
index fc930c95df..e62486f248 100644
--- a/src/backend/catalog/gp_matview_aux.c
+++ b/src/backend/catalog/gp_matview_aux.c
@@ -41,7 +41,6 @@
 #include "catalog/pg_type.h"
 #include "catalog/indexing.h"
 #include "cdb/cdbvars.h"
-#include "commands/matview.h"
 #include "utils/array.h"
 #include "utils/builtins.h"
 #include "utils/rel.h"
@@ -168,7 +167,6 @@ InsertMatviewAuxEntry(Oid mvoid, const Query *viewQuery, bool skipdata)
 	List 		*relids;
 	NameData	mvname;
 	bool		has_foreign = false;
-	Relation		matviewRel;
 	char	   *viewsql;
 
 	Assert(OidIsValid(mvoid));
@@ -190,9 +188,7 @@ InsertMatviewAuxEntry(Oid mvoid, const Query *viewQuery, bool skipdata)
 
 	values[Anum_gp_matview_aux_has_foreign - 1] = BoolGetDatum(has_foreign);
 
-	matviewRel = table_open(mvoid, NoLock);
-	viewsql = nodeToString((Node *) copyObject(get_matview_query(matviewRel)));
-	table_close(matviewRel, NoLock);
+	viewsql = nodeToString((Node *) copyObject(viewQuery));
 	values[Anum_gp_matview_aux_view_query - 1] = CStringGetTextDatum(viewsql);
 
 	if (skipdata)
diff --git a/src/backend/optimizer/plan/aqumv.c b/src/backend/optimizer/plan/aqumv.c
index d32c104923..59d133d8af 100644
--- a/src/backend/optimizer/plan/aqumv.c
+++ b/src/backend/optimizer/plan/aqumv.c
@@ -57,15 +57,7 @@
 #include "nodes/pathnodes.h"
 #include "nodes/pg_list.h"
 
-typedef struct
-{
-	int 	varno;
-} aqumv_adjust_varno_context;
-
-extern void aqumv_adjust_simple_query(Query *viewQuery);
 static bool aqumv_process_from_quals(Node *query_quals, Node *mv_quals, List** post_quals);
-static void aqumv_adjust_varno(Query *parse, int delta);
-static Node *aqumv_adjust_varno_mutator(Node *node, aqumv_adjust_varno_context *context);
 
 typedef struct
 {
@@ -361,9 +353,6 @@ answer_query_using_materialized_views(PlannerInfo *root, AqumvContext aqumv_cont
 		subroot->tuple_fraction = root->tuple_fraction;
 		subroot->limit_tuples = root->limit_tuples;
 
-		/* Adjust to valid query tree and fix varno after rewrite.*/
-		aqumv_adjust_simple_query(viewQuery);
-
 		/*
 		 * AQUMV_FIXME_MVP
 		 * Are stable functions OK?
@@ -886,111 +875,6 @@ aqumv_process_targetlist(aqumv_equivalent_transformation_context *context, List
 	return !context->has_unmatched;
 }
 
-void aqumv_adjust_simple_query(Query *viewQuery)
-{
-	ListCell *lc;
-	/*
-	 * AQUMV
-	 * We have to rewrite now before we do the real Equivalent
-	 * Transformation 'rewrite'.
-	 * Because actions stored in rule is not a normal query tree,
-	 * it can't be used directly, with exception to new/old relations used to
-	 * refresh mv.
-	 * Erase unused relations, keep the right one.
-	 */
-	foreach (lc, viewQuery->rtable)
-	{
-		RangeTblEntry *rtetmp = lfirst(lc);
-		if ((rtetmp->relkind == RELKIND_MATVIEW) &&
-			(rtetmp->alias != NULL) &&
-			(strcmp(rtetmp->alias->aliasname, "new") == 0 ||
-			 strcmp(rtetmp->alias->aliasname, "old") == 0))
-		{
-			foreach_delete_current(viewQuery->rtable, lc);
-		}
-	}
-
-	/*
-	 * Now we have the right relation, adjust
-	 * varnos in its query tree.
-	 * AQUMV_FIXME_MVP: Only one single relation
-	 * is supported now, we could assign varno
-	 * to 1 opportunistically.
-	 */
-	aqumv_adjust_varno(viewQuery, 1);
-}
-
-/*
- * Process varno after we eliminate mv's actions("old" and "new" relation)
- * Correct rindex and all varnos with a delta.
- *
- * MV's actions query tree:
- *		[rtable]
- *				RangeTblEntry [rtekind=RTE_RELATION]
- *						[alias] Alias [aliasname="old"]
- *				RangeTblEntry [rtekind=RTE_RELATION]
- *						[alias] Alias [aliasname="new"]
- *				RangeTblEntry [rtekind=RTE_RELATION]
- *		[jointree]
- *				FromExpr []
- *						[fromlist]
- *								RangeTblRef [rtindex=3]
- *		[targetList]
- *				TargetEntry [resno=1 resname="c1"]
- *						Var [varno=3 varattno=1]
- *				TargetEntry [resno=2 resname="c2"]
- *						Var [varno=3 varattno=2]
- *------------------------------------------------------------------------------------------
- * MV's query tree after rewrite:
- *		[rtable]
- *				RangeTblEntry [rtekind=RTE_RELATION]
- *		[jointree]
- *				FromExpr []
- *						[fromlist]
- *								RangeTblRef [rtindex=3]
- *		[targetList]
- *				TargetEntry [resno=1 resname="c1"]
- *						Var [varno=3 varattno=1]
- *				TargetEntry [resno=2 resname="c2"]
- *						Var [varno=3 varattno=2]
- *------------------------------------------------------------------------------------------
- * MV's query tree after varno adjust:
- *		[rtable]
- *				RangeTblEntry [rtekind=RTE_RELATION]
- *		[jointree]
- *				FromExpr []
- *						[fromlist]
- *								RangeTblRef [rtindex=1]
- *		[targetList]
- *				TargetEntry [resno=1 resname="c1"]
- *						Var [varno=1 varattno=1]
- *				TargetEntry [resno=2 resname="c2"]
- *						Var [varno=1 varattno=2]
- *
- */
-static void
-aqumv_adjust_varno(Query* parse, int varno)
-{
-	aqumv_adjust_varno_context context;
-	context.varno = varno;
-	parse = query_tree_mutator(parse, aqumv_adjust_varno_mutator, &context, QTW_DONT_COPY_QUERY);
-}
-
-static Node *aqumv_adjust_varno_mutator(Node *node, aqumv_adjust_varno_context *context)
-{
-	if (node == NULL)
-		return NULL;
-	if (IsA(node, Var))
-	{
-		((Var *)node)->varno = context->varno;
-		((Var *)node)->varnosyn = context->varno; /* Keep syntactic with varno. */
-	}
-	else if (IsA(node, RangeTblRef))
-		/* AQUMV_FIXME_MVP: currently we have only one relation */
-		((RangeTblRef*) node)->rtindex = context->varno;
-	return expression_tree_mutator(node, aqumv_adjust_varno_mutator, context);
-}
-
 /*
  * check_partition - Check if the query's range table entries align with the partitioned table structure.
  *
diff --git a/src/include/optimizer/aqumv.h b/src/include/optimizer/aqumv.h
index 650dab634f..6e51d4dbc9 100644
--- a/src/include/optimizer/aqumv.h
+++ b/src/include/optimizer/aqumv.h
@@ -45,11 +45,4 @@ typedef AqumvContextData *AqumvContext;
 
 extern RelOptInfo* answer_query_using_materialized_views(PlannerInfo *root, AqumvContextData *aqumv_context);
 
-/*
- * Adjust parse tree storaged in view's actions.
- * Query should be a simple query, ex:
- * select from a single table.
- */
-extern void aqumv_adjust_simple_query(Query *viewQuery);
-
 #endif   /* AQUMV_H */


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