Skip to content

Commit a3bcbcb

Browse files
avaminglimy-ship-it
authored andcommitted
[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
1 parent 54087f7 commit a3bcbcb

3 files changed

Lines changed: 1 addition & 128 deletions

File tree

src/backend/catalog/gp_matview_aux.c

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@
4141
#include "catalog/pg_type.h"
4242
#include "catalog/indexing.h"
4343
#include "cdb/cdbvars.h"
44-
#include "commands/matview.h"
4544
#include "utils/array.h"
4645
#include "utils/builtins.h"
4746
#include "utils/rel.h"
@@ -168,7 +167,6 @@ InsertMatviewAuxEntry(Oid mvoid, const Query *viewQuery, bool skipdata)
168167
List *relids;
169168
NameData mvname;
170169
bool has_foreign = false;
171-
Relation matviewRel;
172170
char *viewsql;
173171

174172
Assert(OidIsValid(mvoid));
@@ -190,9 +188,7 @@ InsertMatviewAuxEntry(Oid mvoid, const Query *viewQuery, bool skipdata)
190188

191189
values[Anum_gp_matview_aux_has_foreign - 1] = BoolGetDatum(has_foreign);
192190

193-
matviewRel = table_open(mvoid, NoLock);
194-
viewsql = nodeToString((Node *) copyObject(get_matview_query(matviewRel)));
195-
table_close(matviewRel, NoLock);
191+
viewsql = nodeToString((Node *) copyObject(viewQuery));
196192
values[Anum_gp_matview_aux_view_query - 1] = CStringGetTextDatum(viewsql);
197193

198194
if (skipdata)

src/backend/optimizer/plan/aqumv.c

Lines changed: 0 additions & 116 deletions
Original file line numberDiff line numberDiff line change
@@ -57,15 +57,7 @@
5757
#include "nodes/pathnodes.h"
5858
#include "nodes/pg_list.h"
5959

60-
typedef struct
61-
{
62-
int varno;
63-
} aqumv_adjust_varno_context;
64-
65-
extern void aqumv_adjust_simple_query(Query *viewQuery);
6660
static bool aqumv_process_from_quals(Node *query_quals, Node *mv_quals, List** post_quals);
67-
static void aqumv_adjust_varno(Query *parse, int delta);
68-
static Node *aqumv_adjust_varno_mutator(Node *node, aqumv_adjust_varno_context *context);
6961

7062
typedef struct
7163
{
@@ -361,9 +353,6 @@ answer_query_using_materialized_views(PlannerInfo *root, AqumvContext aqumv_cont
361353
subroot->tuple_fraction = root->tuple_fraction;
362354
subroot->limit_tuples = root->limit_tuples;
363355

364-
/* Adjust to valid query tree and fix varno after rewrite.*/
365-
aqumv_adjust_simple_query(viewQuery);
366-
367356
/*
368357
* AQUMV_FIXME_MVP
369358
* Are stable functions OK?
@@ -886,111 +875,6 @@ aqumv_process_targetlist(aqumv_equivalent_transformation_context *context, List
886875
return !context->has_unmatched;
887876
}
888877

889-
void aqumv_adjust_simple_query(Query *viewQuery)
890-
{
891-
ListCell *lc;
892-
/*
893-
* AQUMV
894-
* We have to rewrite now before we do the real Equivalent
895-
* Transformation 'rewrite'.
896-
* Because actions stored in rule is not a normal query tree,
897-
* it can't be used directly, with exception to new/old relations used to
898-
* refresh mv.
899-
* Erase unused relations, keep the right one.
900-
*/
901-
foreach (lc, viewQuery->rtable)
902-
{
903-
RangeTblEntry *rtetmp = lfirst(lc);
904-
if ((rtetmp->relkind == RELKIND_MATVIEW) &&
905-
(rtetmp->alias != NULL) &&
906-
(strcmp(rtetmp->alias->aliasname, "new") == 0 ||
907-
strcmp(rtetmp->alias->aliasname, "old") == 0))
908-
{
909-
foreach_delete_current(viewQuery->rtable, lc);
910-
}
911-
}
912-
913-
/*
914-
* Now we have the right relation, adjust
915-
* varnos in its query tree.
916-
* AQUMV_FIXME_MVP: Only one single relation
917-
* is supported now, we could assign varno
918-
* to 1 opportunistically.
919-
*/
920-
aqumv_adjust_varno(viewQuery, 1);
921-
}
922-
923-
/*
924-
* Process varno after we eliminate mv's actions("old" and "new" relation)
925-
* Correct rindex and all varnos with a delta.
926-
*
927-
* MV's actions query tree:
928-
* [rtable]
929-
* RangeTblEntry [rtekind=RTE_RELATION]
930-
* [alias] Alias [aliasname="old"]
931-
* RangeTblEntry [rtekind=RTE_RELATION]
932-
* [alias] Alias [aliasname="new"]
933-
* RangeTblEntry [rtekind=RTE_RELATION]
934-
* [jointree]
935-
* FromExpr []
936-
* [fromlist]
937-
* RangeTblRef [rtindex=3]
938-
* [targetList]
939-
* TargetEntry [resno=1 resname="c1"]
940-
* Var [varno=3 varattno=1]
941-
* TargetEntry [resno=2 resname="c2"]
942-
* Var [varno=3 varattno=2]
943-
*------------------------------------------------------------------------------------------
944-
* MV's query tree after rewrite:
945-
* [rtable]
946-
* RangeTblEntry [rtekind=RTE_RELATION]
947-
* [jointree]
948-
* FromExpr []
949-
* [fromlist]
950-
* RangeTblRef [rtindex=3]
951-
* [targetList]
952-
* TargetEntry [resno=1 resname="c1"]
953-
* Var [varno=3 varattno=1]
954-
* TargetEntry [resno=2 resname="c2"]
955-
* Var [varno=3 varattno=2]
956-
*------------------------------------------------------------------------------------------
957-
* MV's query tree after varno adjust:
958-
* [rtable]
959-
* RangeTblEntry [rtekind=RTE_RELATION]
960-
* [jointree]
961-
* FromExpr []
962-
* [fromlist]
963-
* RangeTblRef [rtindex=1]
964-
* [targetList]
965-
* TargetEntry [resno=1 resname="c1"]
966-
* Var [varno=1 varattno=1]
967-
* TargetEntry [resno=2 resname="c2"]
968-
* Var [varno=1 varattno=2]
969-
*
970-
*/
971-
static void
972-
aqumv_adjust_varno(Query* parse, int varno)
973-
{
974-
aqumv_adjust_varno_context context;
975-
context.varno = varno;
976-
parse = query_tree_mutator(parse, aqumv_adjust_varno_mutator, &context, QTW_DONT_COPY_QUERY);
977-
}
978-
979-
static Node *aqumv_adjust_varno_mutator(Node *node, aqumv_adjust_varno_context *context)
980-
{
981-
if (node == NULL)
982-
return NULL;
983-
if (IsA(node, Var))
984-
{
985-
((Var *)node)->varno = context->varno;
986-
((Var *)node)->varnosyn = context->varno; /* Keep syntactic with varno. */
987-
}
988-
else if (IsA(node, RangeTblRef))
989-
/* AQUMV_FIXME_MVP: currently we have only one relation */
990-
((RangeTblRef*) node)->rtindex = context->varno;
991-
return expression_tree_mutator(node, aqumv_adjust_varno_mutator, context);
992-
}
993-
994878
/*
995879
* check_partition - Check if the query's range table entries align with the partitioned table structure.
996880
*

src/include/optimizer/aqumv.h

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,4 @@ typedef AqumvContextData *AqumvContext;
4545

4646
extern RelOptInfo* answer_query_using_materialized_views(PlannerInfo *root, AqumvContextData *aqumv_context);
4747

48-
/*
49-
* Adjust parse tree storaged in view's actions.
50-
* Query should be a simple query, ex:
51-
* select from a single table.
52-
*/
53-
extern void aqumv_adjust_simple_query(Query *viewQuery);
54-
5548
#endif /* AQUMV_H */

0 commit comments

Comments
 (0)