public class HiveMaterializedViewBoxing
extends Object
This class contains logic that is useful to trigger additional materialized
view rewritings.
In particular, in Hive we do not combine the MV rewriting rules with other
rules that may generate additional rewritings in the planner, e.g., join
reordering rules. In fact, the rewriting has some built-in logic to add
compensation joins on top of the MV scan which make adding these rules
unnecessary. This leads to faster planning, however it can also lead to some
missing rewriting opportunities if we are not careful. For instance, the
rewriting algorithm will bail out if an input of a join contains operators
that are not supported. Consider the following example where Union is not
supported by the rewriting algorithm:
MV:
Join
/ \
A B
Query:
Join
/ \
Join B
/ \
Union A
|
S
The rewriting can only be triggered at the root of the plan since that is
the operator where A and B are visible. However, after checking the
operators in the plan, the rewriting bails out since Union is not supported.
This class contains boxing/unboxing logic that aims at fixing this. The
boxing logic will do a traversal of the query plan and introduce Box
operators when it detects an unsupported operator. For the former query,
this will be the rewritten plan:
Query:
Join
/ \
Join B
/ \
Box$0 A
Box extends TableScan, and thus, MV rewriting will proceed as expected. In
addition, the Box node keeps a internal pointer to the former subplan that
it replaced. During MV rewriting, we include the unboxing rule in the
planner, which will transform the Box node into the original subplan. The
Box node has an infinite cost: Though it helps the rewriting to be
triggered, it will never be part of the final plan, i.e., the original
subplan (possibly with other MV rewritings) will be chosen.