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

Aman Sinha commented on CALCITE-569:
------------------------------------

Hmm..for your query, with my change, I get the following plan ... which has an 
extra Sort at the top.  
{code}
select t.psPartkey from (select ps.psPartkey from `tpch`.`partsupp` ps order by 
ps.psPartkey, ps.psSupplyCost) t order by t.psPartkey"
{code}

Plan: 
{code}
Sort(sort0=[$0], dir0=[ASC])
  LogicalProject(psPartkey=[$0])
    LogicalProject(psPartkey=[$0])
      Sort(sort0=[$0], sort1=[$1], dir0=[ASC], dir1=[ASC])
        LogicalProject(psPartkey=[$0], psSupplyCost=[$1])
          EnumerableTableScan(table=[[tpch, partsupp]])
{code}
However, with the original code, this query fails with the same IOBE, so in 
that sense the patch is an improvement but not optimal plan yet.  For the 
better plan I think we have to look closer at trait propagation.  

If you are ok with this, I will add your test.


> ArrayIndexOutOfBoundException when deducing collation
> -----------------------------------------------------
>
>                 Key: CALCITE-569
>                 URL: https://issues.apache.org/jira/browse/CALCITE-569
>             Project: Calcite
>          Issue Type: Bug
>    Affects Versions: 1.0.0-incubating
>            Reporter: Aman Sinha
>            Assignee: Julian Hyde
>         Attachments: 
> 0001-CALCITE-569-Create-a-Project-with-empty-collation-if.patch
>
>
> If a subquery has an ORDER BY on a column that is not in the SELECT list and 
> the outer query does another ORDER BY,  Calcite encounters an 
> ArrayIndexOutOfBoundException when deducing collation. 
> In PlannerTest, I created a simple test by first adding the following traits: 
>  {code}
>           List<RelTraitDef> traitDefs = new ArrayList<RelTraitDef>();
>           traitDefs.add(ConventionTraitDef.INSTANCE);
>           traitDefs.add(RelCollationTraitDef.INSTANCE);
> {code}
> And ran the following query: 
> {code}
> select t.psPartkey from (select ps.psPartkey from `tpch`.`partsupp` ps order 
> by ps.psSupplyCost) t order by t.psPartkey"
> {code}
> {code}
> java.lang.ArrayIndexOutOfBoundsException: -1
>       at 
> org.apache.calcite.rex.RexProgram.deduceCollations(RexProgram.java:589)
>       at org.apache.calcite.rex.RexProgram.getCollations(RexProgram.java:558)
>       at 
> org.apache.calcite.plan.RelOptUtil.createProject(RelOptUtil.java:2685)
>       at 
> org.apache.calcite.plan.RelOptUtil.createProject(RelOptUtil.java:2623)
>       at 
> org.apache.calcite.sql2rel.SqlToRelConverter.convertSelectList(SqlToRelConverter.java:3571)
>       at 
> org.apache.calcite.sql2rel.SqlToRelConverter.convertSelectImpl(SqlToRelConverter.java:613)
>       at 
> org.apache.calcite.sql2rel.SqlToRelConverter.convertSelect(SqlToRelConverter.java:568)
>       at 
> org.apache.calcite.sql2rel.SqlToRelConverter.convertQueryRecursive(SqlToRelConverter.java:2929)
>       at 
> org.apache.calcite.sql2rel.SqlToRelConverter.convertQuery(SqlToRelConverter.java:526)
>       at org.apache.calcite.prepare.PlannerImpl.convert(PlannerImpl.java:189)
> {code}



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to