[
https://issues.apache.org/jira/browse/CALCITE-6586?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17884839#comment-17884839
]
suibianwanwan commented on CALCITE-6586:
----------------------------------------
[~caicancai] Thank you for your attention to this issue, For simple example in
RelOptRulesTest:
{code:java}
/** Tests {@link AggregateProjectPullUpConstantsRule} where both keys are
* constants but only one can be removed. */
@Test void testAggregateConstantKeyRule3() {
final String sql = "select job\n"
+ "from sales.emp\n"
+ "where mgr is null and job = 'Clerk'\n"
+ "group by mgr, job\n"
+ "having count(*) > 3";
sql(sql).withRule(CoreRules.AGGREGATE_ANY_PULL_UP_CONSTANTS)
.check();
} {code}
This query applies the AGGREGATE_ANY_PULL_UP_CONSTANTS rule with a final plan:
{code:java}
LogicalProject(JOB=[$1])
LogicalFilter(condition=[>($2, 3)])
LogicalProject(MGR=[$0], JOB=['Clerk':VARCHAR(10)], $f2=[$1])
LogicalAggregate(group=[{0}], agg#0=[COUNT()])
LogicalProject(MGR=[$3])
LogicalFilter(condition=[AND(IS NULL($3), =($2, 'Clerk'))])
LogicalTableScan(table=[[CATALOG, SALES, EMP]]) {code}
However, if we use VolcanoPlanner:
{code:java}
@Test void testAggregateConstantKeyRule3() {
final String sql = "select job\n"
+ "from sales.emp\n"
+ "where mgr is null and job = 'Clerk'\n"
+ "group by mgr, job\n"
+ "having count(*) > 3";
sql(sql)
.withVolcanoPlanner(false, planner -> {
planner.addRule(CoreRules.AGGREGATE_ANY_PULL_UP_CONSTANTS);
planner.addRule(EnumerableRules.ENUMERABLE_PROJECT_RULE);
planner.addRule(EnumerableRules.ENUMERABLE_FILTER_RULE);
planner.addRule(EnumerableRules.ENUMERABLE_AGGREGATE_RULE);
planner.addRule(EnumerableRules.ENUMERABLE_TABLE_SCAN_RULE);
})
.check();
} {code}
AGGREGATE_ANY_PULL_UP_CONSTANTS will not be applied, and the final plan:
{code:java}
EnumerableProject(JOB=[$1])
EnumerableFilter(condition=[>($2, 3)])
EnumerableAggregate(group=[{0, 1}], agg#0=[COUNT()])
EnumerableProject(MGR=[$3], JOB=[$2])
EnumerableFilter(condition=[AND(IS NULL($3), =($2, 'Clerk'))])
EnumerableTableScan(table=[[CATALOG, SALES, EMP]]) {code}
> Some Rules not firing due to RelMdPredicates returning null in VolcanoPlanner
> -----------------------------------------------------------------------------
>
> Key: CALCITE-6586
> URL: https://issues.apache.org/jira/browse/CALCITE-6586
> Project: Calcite
> Issue Type: Improvement
> Reporter: suibianwanwan
> Priority: Major
> Labels: pull-request-available
>
> Because getPredicates(RelSubset r, RelMetadataQuery mq) returns null by
> default, some rules will not work in volcanoPlanner. Such as
> SortRemoveConstantKeysRule, UnionPullUpConstantsRule,
> ExchangeRemoveConstantKeysRule, AggregateJoinTransposeRule,
> ReduceExpressionsRule, etc.
> {code:java}
> public RelOptPredicateList getPredicates(RelSubset r,
> RelMetadataQuery mq) {
> if (!Bug.CALCITE_1048_FIXED) {
> return RelOptPredicateList.EMPTY;
> }
> }{code}
--
This message was sent by Atlassian Jira
(v8.20.10#820010)