diff --git a/src/gausskernel/optimizer/rewrite/rewriteHandler.cpp b/src/gausskernel/optimizer/rewrite/rewriteHandler.cpp index c5cabcf01..94951397e 100644 --- a/src/gausskernel/optimizer/rewrite/rewriteHandler.cpp +++ b/src/gausskernel/optimizer/rewrite/rewriteHandler.cpp @@ -127,6 +127,15 @@ static bool pull_qual_vars_walker(Node* node, pull_qual_vars_context* context); */ void AcquireRewriteLocks(Query* parsetree, bool forUpdatePushedDown) { + /* + * @Param[IN] parsetree: A query tree. We need to acquire suitable + * locks on all the relations mentioned in the Query. + * @Param[IN] forUpdatePushedDown: Indicates that whether there is a + * pushed-down FOR UPDATE/SHARE statement that applies to the + * current subquery. It should always be false at the start + * of the recursion. + * @Return[OUT]: None. + */ ListCell* l = NULL; int rt_index; @@ -1712,6 +1721,7 @@ static bool fireRIRonSubLink(Node* node, List* activeRIRs) /* * fireRIRrules - * Apply all RIR rules on each rangetable entry in a query + * */ static Query* fireRIRrules(Query* parsetree, List* activeRIRs, bool forUpdatePushedDown) { @@ -1733,7 +1743,8 @@ static Query* fireRIRrules(Query* parsetree, List* activeRIRs, bool forUpdatePus int i; ++rt_index; - + + // fetch RTE of current parsetree node. rte = rt_fetch(rt_index, parsetree->rtable); /* @@ -2699,14 +2710,17 @@ static List* RewriteQuery(Query* parsetree, List* rewrite_events) return rewritten; } + /* - * QueryRewrite - - * Primary entry point to the query rewriter. - * Rewrite one query via query rewrite system, possibly returning 0 - * or many queries. - * - * NOTE: the parsetree must either have come straight from the parser, - * or have been scanned by AcquireRewriteLocks to acquire suitable locks. + * QueryRewrite()--- + * + * @Description:Primary entry point to the query rewriter. + * Rewrite one query via query rewrite system, possibly returning 0 + * or many queries. + * @Param[IN] parsetree:A Query Tree. It must either have come straight + * from the parser, or have been scanned by AcquireRewriteLocks to + * acquire suitable locks. + * @Return[OUT]: Rewrited queries(0 or several queries). */ List* QueryRewrite(Query* parsetree) { @@ -2722,6 +2736,7 @@ List* QueryRewrite(Query* parsetree) * This function is only applied to top-level original queries */ AssertEreport(parsetree->querySource == QSRC_ORIGINAL, MOD_OPT, ""); + AssertEreport(parsetree->canSetTag, MOD_OPT, ""); /* * Step 1 @@ -2733,11 +2748,12 @@ List* QueryRewrite(Query* parsetree) /* * Step 2 * - * Apply all the RIR rules on each query + * Apply all the RIR rules on each query * * This is also a handy place to mark each query with the original queryId */ results = NIL; + foreach (l, querylist) { Query* query = (Query*)lfirst(l); @@ -3270,4 +3286,4 @@ List* QueryRewriteCTAS(Query* parsetree) } } } -#endif +#endif \ No newline at end of file