[
https://issues.apache.org/jira/browse/CALCITE-6899?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17986289#comment-17986289
]
Silun Dong commented on CALCITE-6899:
-------------------------------------
I will add some details to this case:
1.Why does the LogicalFilter have the broadcast distribution in the initial
plan?
{code:java}
LogicalProject#16(subset=[rel#17:RelSubset#2.NONE.any], ENAME=[$1],
input=[rel#15])
LogicalFilter#14(subset=[rel#15:RelSubset#1.NONE.broadcast], condition=[...])
LogicalTableScan(subset=[rel#13:RelSubset#0.NONE.any], table=[[CATALOG,
SALES, EMP]]) {code}
Answer: The {{create}} function in LogicalFilter will use RelMdDistribution for
recursive inference. In this case, it recurses to LogicalTableScan and obtains
the distribution of its table. MockTable has the broadcast distribution by
default.
2.Why does the distribution of the new LogicalFilter become single after
SubQueryRemoveRule?
{code:java}
LogicalProject#16(subset=[rel#17:RelSubset#2.NONE.any], input=[rel#15])
LogicalProject#37(subset=[rel#38:RelSubset#1.NONE.any], ...)
LogicalFilter#35(subset=[rel#36:RelSubset#7.NONE.single], condition=[...)])
LogicalJoin#33(subset=[rel#34:RelSubset#6.NONE.any], condition=[true],
joinType=[inner])
LogicalTableScan#8(subset=[rel#13:RelSubset#0.NONE.any],
table=[[CATALOG, SALES, EMP]])
LogicalProject#31(subset=[rel#32:RelSubset#5.NONE.any], m=[$0], c=[$1],
d=[$1])
LogicalAggregate#29(subset=[rel#30:RelSubset#4.NONE.any], group=[{}],
m=[MAX($0)], c=[COUNT()])
LogicalProject#27(subset=[rel#28:RelSubset#3.NONE.any], COMM=[$6])
LogicalTableScan#8(subset=[rel#13:RelSubset#0.NONE.any],
table=[[CATALOG, SALES, EMP]]) {code}
Answer: After the plan is registered to volcano, the input of LogicalFilter is
no longer TableScan, but RelSubset. When the SubQueryRemoveRule generates a new
LogicalFilter, as mentioned in the first point, RelMdDistribution recursively
infers the distribution, it will recurse to the RelSubset, and
RelMdDistribution does not have a special function to handle RelSubSet. It will
return single as default. So the new LogicalFilter change to single
distribution.
> Mismatch of Trait information results in a missing conversion exception
> -----------------------------------------------------------------------
>
> Key: CALCITE-6899
> URL: https://issues.apache.org/jira/browse/CALCITE-6899
> Project: Calcite
> Issue Type: Bug
> Reporter: xiong duan
> Priority: Major
> Labels: pull-request-available
>
> The unit test in RelOptRulesTest:
> {code:java}
> @Test void testEnumerableFilterRule() {
> final String sql = "select ename from emp where sal > all (select comm from
> emp)";
> sql(sql)
> .withVolcanoPlanner(false, p -> {
> p.addRelTraitDef(RelDistributionTraitDef.INSTANCE);
> p.addRule(CoreRules.FILTER_SUB_QUERY_TO_CORRELATE);
> p.addRule(EnumerableRules.ENUMERABLE_FILTER_RULE);
> p.addRule(EnumerableRules.ENUMERABLE_PROJECT_RULE);
> p.addRule(EnumerableRules.ENUMERABLE_TABLE_SCAN_RULE);
> p.addRule(EnumerableRules.ENUMERABLE_JOIN_RULE);
> p.addRule(EnumerableRules.ENUMERABLE_AGGREGATE_RULE);
> }).check();
> } {code}
> It throws an exception:
> {code:java}
> There are not enough rules to produce a node with desired properties:
> convention=ENUMERABLE, dist=any.
> Missing conversion is LogicalFilter[convention: NONE -> ENUMERABLE]
> There is 1 empty subset: rel#39:RelSubset#1.ENUMERABLE.broadcast, the
> relevant part of the original plan is as follows
> 14:LogicalFilter(condition=[NOT(<= SOME($5, {
> LogicalProject(COMM=[$6])
> LogicalTableScan(table=[[CATALOG, SALES, EMP]])
> }))])
> 8:LogicalTableScan(subset=[rel#13:RelSubset#0.NONE.any], table=[[CATALOG,
> SALES, EMP]]) {code}
--
This message was sent by Atlassian Jira
(v8.20.10#820010)