[ 
https://issues.apache.org/jira/browse/CALCITE-5254?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17600064#comment-17600064
 ] 

Steven Talbot commented on CALCITE-5254:
----------------------------------------

Ah, could be ultimately that. I’m unsure about what responsibilities each
rule has in terms of guarantees it makes about how it will or won’t touch
the mutable rels.

Bottom line if the fault can lie in a rule, and a rule can be passed by
caller, I do think this code may still want the safety cap on max
iterations, even it hitting the cap raises an exception.




> 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)

Reply via email to