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

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

                Author: ASF GitHub Bot
            Created on: 26/Apr/22 08:59
            Start Date: 26/Apr/22 08:59
    Worklog Time Spent: 10m 
      Work Description: kasakrisz commented on code in PR #3229:
URL: https://github.com/apache/hive/pull/3229#discussion_r858465153


##########
ql/src/java/org/apache/hadoop/hive/ql/parse/CalcitePlanner.java:
##########
@@ -2347,22 +2348,49 @@ private RelNode applyPostJoinOrderingTransform(RelNode 
basePlan, RelMetadataProv
       return basePlan;
     }
 
+    /**
+     * Traverse the plan and collect table names from {@link TableScan} 
operators
+     * Use this method if plan does not have any sub query.
+     * Use {@link CalcitePlannerAction#getAllTablesUsed(RelNode)} to include 
sub-query expressions.
+     * @see HiveSubQueryRemoveRule
+     */
     protected Set<TableName> getTablesUsed(RelNode plan) {
       Set<TableName> tablesUsed = new HashSet<>();
       new RelVisitor() {
         @Override
         public void visit(RelNode node, int ordinal, RelNode parent) {
-          if (node instanceof TableScan) {
-            TableScan ts = (TableScan) node;
-            Table hiveTableMD = ((RelOptHiveTable) 
ts.getTable()).getHiveTableMD();
-            tablesUsed.add(hiveTableMD.getFullTableName());
-          }
+          addUsedTable(node, tablesUsed);
           super.visit(node, ordinal, parent);
         }
       }.go(plan);
       return tablesUsed;
     }
 
+    /**
+     * Traverse the plan including sub-query expressions and collect table 
names from {@link TableScan} operators.
+     */
+    protected Set<TableName> getAllTablesUsed(RelNode plan) {
+      Set<TableName> tablesUsed = new HashSet<>();
+      new HiveSubQueryVisitor() {

Review Comment:
   This seems to be a good idea. Let's see how it works: #3246 





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

    Worklog Id:     (was: 762182)
    Time Spent: 40m  (was: 0.5h)

> 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: 40m
>  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