EmmyMiao87 commented on a change in pull request #4014:
URL: https://github.com/apache/incubator-doris/pull/4014#discussion_r450093057



##########
File path: fe/src/main/java/org/apache/doris/analysis/QueryStmt.java
##########
@@ -113,6 +113,40 @@
     // represent the "INTO OUTFILE" clause
     protected OutFileClause outFileClause;
 
+    /**
+     * If the query stmt belongs to CreateMaterializedViewStmt,
+     * such as
+     * `CREATE MATERIALIZED VIEW mv AS SELECT bitmap_union(to_bitmap(k1)) from 
table`
+     * query stmt will not be rewrite by MVRewriter.
+     * The `bitmap_union(to_bitmap(k1))` is the definition of the mv column 
rather then a expr.
+     * So `forbiddenMVRewrite` will be set to true to protect the definition 
of the mv column from being overwritten.
+     * <p>
+     * In other query case, `forbiddenMVRewrite` is always false.
+     */
+    private boolean forbiddenMVRewrite = false;
+
+    /**
+     * If the tuple id in `disableMVRewriteTupleIds`, the expr which belongs 
to this tuple will not be MVRewritten.
+     * Initially this set is an empty set.
+     * When the scan node is unable to match any index in selecting the 
materialized view,
+     *   the tuple is added to this set.
+     * The query will be re-executed, and this tuple will not be mv rewritten.
+     * For example:
+     * TableA: (k1 int, k2 int, k3 int)
+     * MV: (k1 int, mv_bitmap_union_k2 bitmap bitmap_union)
+     * Query: select k3, bitmap_union(to_bitmap(k2)) from TableA
+     * First analyze: MV rewriter enable and this set is empty
+     *     select k3, bitmap_union(mv_bitmap_union_k2) from TableA
+     * SingleNodePlanner: could not select any index for TableA
+     *     Add table to disableMVRewriteTupleIds.
+     * `disableMVRewriteTupleIds` = {TableA}
+     * Re-executed:
+     * Second analyze: MV rewrite disable in table and use origin stmt.
+     *     select k3, bitmap_union(to_bitmap(k2)) from TableA
+     * SingleNodePlanner: base index selected

Review comment:
       Under normal circumstances, the tuple id of the first parsing statement 
and the second parsing statement should be the same.
   If it involves query rewriting, I tested it, and no new tuple will be 
generated. So in theory, there is no problem.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org
For additional commands, e-mail: commits-h...@doris.apache.org

Reply via email to