|
57 | 57 | #include "nodes/pathnodes.h" |
58 | 58 | #include "nodes/pg_list.h" |
59 | 59 |
|
60 | | -typedef struct |
61 | | -{ |
62 | | - int varno; |
63 | | -} aqumv_adjust_varno_context; |
64 | | - |
65 | | -extern void aqumv_adjust_simple_query(Query *viewQuery); |
66 | 60 | 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); |
69 | 61 |
|
70 | 62 | typedef struct |
71 | 63 | { |
@@ -361,9 +353,6 @@ answer_query_using_materialized_views(PlannerInfo *root, AqumvContext aqumv_cont |
361 | 353 | subroot->tuple_fraction = root->tuple_fraction; |
362 | 354 | subroot->limit_tuples = root->limit_tuples; |
363 | 355 |
|
364 | | - /* Adjust to valid query tree and fix varno after rewrite.*/ |
365 | | - aqumv_adjust_simple_query(viewQuery); |
366 | | - |
367 | 356 | /* |
368 | 357 | * AQUMV_FIXME_MVP |
369 | 358 | * Are stable functions OK? |
@@ -886,111 +875,6 @@ aqumv_process_targetlist(aqumv_equivalent_transformation_context *context, List |
886 | 875 | return !context->has_unmatched; |
887 | 876 | } |
888 | 877 |
|
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 | | - |
994 | 878 | /* |
995 | 879 | * check_partition - Check if the query's range table entries align with the partitioned table structure. |
996 | 880 | * |
|
0 commit comments