[
https://issues.apache.org/jira/browse/CALCITE-5254?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17597961#comment-17597961
]
Steven Talbot commented on CALCITE-5254:
----------------------------------------
Also, given that the "fix" there relies on the rule to do the right thing to
prevent an infinite loop, and the rules are part of a public interface, where a
caller can specify them, we may want an additional fix where
SubstitutionVisitor.go has some safety cap on the max number of times it will
substitute parts of the query before giving up.
> 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)