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

Haisheng Yuan commented on CALCITE-2057:
----------------------------------------

The query posted by Julian doesn't trigger stackoverflow anymore on 1.23:

{code:java}
select * from (
  select a."id" as a,b."id" as b,c."id" as c
  from "nullables" a
  join "nullables" b on (a."id" = b."id")
  join "nullables" c on (a."id" = b."id")
  where b."id" <= 1 and c."id" <= 1) z
where a > 1 or b > 1;
!plan
{code}

This is the plan:

{code:java}
> EnumerableNestedLoopJoin(condition=[true], joinType=[inner])
>   EnumerableMergeJoin(condition=[AND(=($0, $1), OR(>($0, 1), >($1, 1)))], 
> joinType=[inner])
>     EnumerableSort(sort0=[$0], dir0=[ASC])
>       EnumerableCalc(expr#0..1=[{inputs}], id=[$t0])
>         EnumerableTableScan(table=[[s, nullables]])
>     EnumerableSort(sort0=[$0], dir0=[ASC])
>       EnumerableCalc(expr#0..1=[{inputs}], expr#2=[1], expr#3=[<=($t0, $t2)], 
> id=[$t0], $condition=[$t3])
>         EnumerableTableScan(table=[[s, nullables]])
>   EnumerableCalc(expr#0..1=[{inputs}], expr#2=[1], expr#3=[<=($t0, $t2)], 
> id=[$t0], $condition=[$t3])
>     EnumerableTableScan(table=[[s, nullables]])
{code}



> StackOverflowError when running a JDBC query
> --------------------------------------------
>
>                 Key: CALCITE-2057
>                 URL: https://issues.apache.org/jira/browse/CALCITE-2057
>             Project: Calcite
>          Issue Type: Bug
>    Affects Versions: 1.14.0
>            Reporter: Eyal Segal
>            Priority: Minor
>
> I've ran the following code:
> {code:java}
> try (ResultSet rs = statement.executeQuery(
>                 "SELECT p.name, r.views " +
>                     "FROM reports.a as r " +
>                     "INNER JOIN main.b as p ON p.id = CAST(r.p_id AS INT) AND 
> p.id = 196 " +
>                     "WHERE p.id = 196 " +
>                     "AND r.p_id = 196 " +
>                     "AND r.data_timestamp = TIMESTAMP '2017-11-14 00:00:00'  
> " )) {
> {code}
> And I'm getting the following StackOverflowError:
> {code:java}
> Exception in thread "main" java.lang.StackOverflowError
>       at 
> com.google.common.collect.ImmutableList.indexOf(ImmutableList.java:339)
>       at GeneratedMetadataHandler_RowCount.getRowCount_$(Unknown Source)
>       at GeneratedMetadataHandler_RowCount.getRowCount(Unknown Source)
>       at 
> org.apache.calcite.rel.metadata.RelMetadataQuery.getRowCount(RelMetadataQuery.java:235)
>       at 
> org.apache.calcite.rel.metadata.RelMdRowCount.getRowCount(RelMdRowCount.java:71)
>       at GeneratedMetadataHandler_RowCount.getRowCount_$(Unknown Source)
>       at GeneratedMetadataHandler_RowCount.getRowCount(Unknown Source)
>       at 
> org.apache.calcite.rel.metadata.RelMetadataQuery.getRowCount(RelMetadataQuery.java:235)
>       at 
> org.apache.calcite.rel.metadata.RelMdUtil.estimateFilteredRows(RelMdUtil.java:718)
>       at 
> org.apache.calcite.rel.metadata.RelMdRowCount.getRowCount(RelMdRowCount.java:123)
>       at GeneratedMetadataHandler_RowCount.getRowCount_$(Unknown Source)
>       at GeneratedMetadataHandler_RowCount.getRowCount(Unknown Source)
>       at 
> org.apache.calcite.rel.metadata.RelMetadataQuery.getRowCount(RelMetadataQuery.java:235)
>       at 
> org.apache.calcite.rel.metadata.RelMdRowCount.getRowCount(RelMdRowCount.java:71)
>       at GeneratedMetadataHandler_RowCount.getRowCount_$(Unknown Source)
>       at GeneratedMetadataHandler_RowCount.getRowCount(Unknown Source)
>       at 
> org.apache.calcite.rel.metadata.RelMetadataQuery.getRowCount(RelMetadataQuery.java:235)
>       at 
> org.apache.calcite.rel.metadata.RelMdUtil.estimateFilteredRows(RelMdUtil.java:718)
>       at 
> org.apache.calcite.rel.metadata.RelMdRowCount.getRowCount(RelMdRowCount.java:123)
>       at GeneratedMetadataHandler_RowCount.getRowCount_$(Unknown Source)
>       at GeneratedMetadataHandler_RowCount.getRowCount(Unknown Source)
> ...
> {code}
> It's solved by removing "AND p.id = 196" from the INNER JOIN, but it's still 
> worth fixing.



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to