[
https://issues.apache.org/jira/browse/CALCITE-5254?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17600123#comment-17600123
]
Benchao Li commented on CALCITE-5254:
-------------------------------------
IMHO, a rule should only change the 'query' or 'target' when it does match and
returns a valid result, after that, we'll replace parent's input
[here|https://github.com/apache/calcite/blob/250d13c566913ba541ddd7ac4c4443a11a1a976b/core/src/main/java/org/apache/calcite/plan/SubstitutionVisitor.java#L590].
Else, we'll get an incomplete plan which is hard to proceed, anything will
happen.
> Infinite Loop in SubstitutionVisitor.go
> ---------------------------------------
>
> Key: CALCITE-5254
> URL: https://issues.apache.org/jira/browse/CALCITE-5254
> Project: Calcite
> Issue Type: Bug
> Reporter: Steven Talbot
> Priority: Major
>
> Happens when you have a materialization "target" of an Aggregate/Scan
> attempting to substitute for an a "query" with a matching Scan.
> The following test should repro (in CustomMaterializedViewRecognitionRuleTest)
> {code:java}
> @Test void testNoInifiniteLoopOnAggregateScanMaterialization() {
> final SchemaPlus rootSchema = Frameworks.createRootSchema(true);
> rootSchema.add("mv1", new AbstractTable() {
> @Override public RelDataType getRowType(RelDataTypeFactory typeFactory) {
> return typeFactory.builder()
> .add("count", SqlTypeName.INTEGER)
> .build();
> }
> });
> final Frameworks.ConfigBuilder config = Frameworks.newConfigBuilder()
> .parserConfig(SqlParser.Config.DEFAULT)
> .defaultSchema(
> CalciteAssert.addSchema(rootSchema,
> CalciteAssert.SchemaSpec.SCOTT_WITH_TEMPORAL))
> .traitDefs((List<RelTraitDef>) null);
> final RelBuilder relBuilder = RelBuilder.create(config.build());
> final RelNode query = relBuilder.scan("EMP")
> .project(relBuilder.field("DEPTNO"))
> .aggregate(
> relBuilder.groupKey(0),
> relBuilder.aggregateCall(SqlStdOperatorTable.COUNT)
> )
> .build();
> final RelNode target = relBuilder.scan("EMP")
> .aggregate(relBuilder.groupKey(),
> relBuilder.aggregateCall(SqlStdOperatorTable.COUNT))
> .build();
> final RelNode replacement = relBuilder.scan("mv1").build();
> final RelOptMaterialization relOptMaterialization =
> new RelOptMaterialization(replacement,
> target, null, Lists.newArrayList("mv1"));
> final List<Pair<RelNode, List<RelOptMaterialization>>> relOptimized =
> RelOptMaterializations.useMaterializedViews(query,
> ImmutableList.of(relOptMaterialization),
> SubstitutionVisitor.DEFAULT_RULES);
> System.out.println("never get here!");
> } {code}
--
This message was sent by Atlassian Jira
(v8.20.10#820010)