[ 
https://issues.apache.org/jira/browse/HIVE-26160?focusedWorklogId=761805&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-761805
 ]

ASF GitHub Bot logged work on HIVE-26160:
-----------------------------------------

                Author: ASF GitHub Bot
            Created on: 25/Apr/22 14:07
            Start Date: 25/Apr/22 14:07
    Worklog Time Spent: 10m 
      Work Description: zabetak commented on code in PR #3229:
URL: https://github.com/apache/hive/pull/3229#discussion_r857661697


##########
ql/src/java/org/apache/hadoop/hive/ql/optimizer/calcite/HiveSubQueryVisitor.java:
##########
@@ -0,0 +1,68 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hadoop.hive.ql.optimizer.calcite;
+
+import org.apache.calcite.rel.RelNode;
+import org.apache.calcite.rel.RelVisitor;
+import org.apache.calcite.rel.core.Filter;
+import org.apache.calcite.rel.core.Project;
+import org.apache.calcite.rex.RexNode;
+import org.apache.calcite.rex.RexSubQuery;
+import org.apache.calcite.rex.RexVisitorImpl;
+
+public class HiveSubQueryVisitor extends RelVisitor {

Review Comment:
   Do we really need this class? Can't we somehow exploit the 
`SubQueryRemoveRule`?  If we need this then probably we want to add some basic 
javadoc.



##########
ql/src/java/org/apache/hadoop/hive/ql/optimizer/calcite/HiveSubQueryVisitor.java:
##########
@@ -0,0 +1,68 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hadoop.hive.ql.optimizer.calcite;
+
+import org.apache.calcite.rel.RelNode;
+import org.apache.calcite.rel.RelVisitor;
+import org.apache.calcite.rel.core.Filter;
+import org.apache.calcite.rel.core.Project;
+import org.apache.calcite.rex.RexNode;
+import org.apache.calcite.rex.RexSubQuery;
+import org.apache.calcite.rex.RexVisitorImpl;
+
+public class HiveSubQueryVisitor extends RelVisitor {
+
+  @Override
+  public void visit(RelNode node, int ordinal, RelNode parent) {
+    if (node instanceof Filter) {
+      visit((Filter) node);
+    } else if (node instanceof Project) {
+      visit((Project) node);
+    }
+

Review Comment:
   Why do we need to focus only on Filter/Project ? Why not subqueries in 
`Join` or elsewhere? Can't we use the `RelNode#accept(RexShuttle)` for more 
uniform access?



##########
ql/src/test/queries/clientpositive/materialized_view_rewrite_by_text_9.q:
##########
@@ -0,0 +1,25 @@
+set hive.support.concurrency=true;
+set hive.txn.manager=org.apache.hadoop.hive.ql.lockmgr.DbTxnManager;
+set hive.materializedview.rewriting=false;
+
+create table t1(col0 int) STORED AS ORC
+                          TBLPROPERTIES ('transactional'='true');
+
+create table t2(col0 int) STORED AS ORC
+                          TBLPROPERTIES ('transactional'='true');
+
+insert into t1(col0) values (1), (NULL);
+insert into t2(col0) values (1), (2), (3), (NULL);
+
+create materialized view mat1 as
+select col0 from t1 where col0 = 1 union select col0 from t1 where col0 = 2;
+
+

Issue Time Tracking
-------------------

    Worklog Id:     (was: 761805)
    Time Spent: 20m  (was: 10m)

> Materialized View rewrite does not check tables scanned in sub-query 
> expressions
> --------------------------------------------------------------------------------
>
>                 Key: HIVE-26160
>                 URL: https://issues.apache.org/jira/browse/HIVE-26160
>             Project: Hive
>          Issue Type: Bug
>          Components: CBO, Materialized views
>            Reporter: Krisztian Kasa
>            Assignee: Krisztian Kasa
>            Priority: Major
>              Labels: pull-request-available
>          Time Spent: 20m
>  Remaining Estimate: 0h
>
> Materialized View rewrite based on exact sql text match uses the initial CBO 
> plan to explore possibilities to change the query plan or part of the plan to 
> an MV scan.
> This algorithm requires the tables scanned by the original query plan. If the 
> query contains sub query expressions the tables scanned by the sub query are 
> not listed which can lead to rewrite the original plan to scan an outdated MV.



--
This message was sent by Atlassian Jira
(v8.20.7#820007)

Reply via email to