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

suibianwanwan commented on CALCITE-6759:
----------------------------------------

[~nobigo] This seems to be a specific case, and I think it's better to add this 
in the rules rather than in the SqlToRelConverter. 

In addition, there are many other optimisations for count such as
{code:java}
select count(*) from (select trim(x) from A)

//optimize:
select count(*) from A{code}
If feasible, we can add a rule to handle a similar case.

> SqlToRelConverter will remove the sort with offset
> --------------------------------------------------
>
>                 Key: CALCITE-6759
>                 URL: https://issues.apache.org/jira/browse/CALCITE-6759
>             Project: Calcite
>          Issue Type: Bug
>            Reporter: suibianwanwan
>            Assignee: suibianwanwan
>            Priority: Critical
>              Labels: pull-request-available
>
> Tests in RelToSqlConverterTest:
> {code:java}
> @Test void testSortWithOffsetInSubQuery() {
>   final String sql = "select count(*) from (select * from emp order by empno 
> offset 10)";
>   sql(sql).ok();
> } {code}
> Plan:
> {code:java}
> LogicalAggregate(group=[{}], EXPR$0=[COUNT()])
>   LogicalProject($f0=[0])
>     LogicalTableScan(table=[[CATALOG, SALES, EMP]]) {code}
> Sort was removed because it didn't contain fetch. In PostgreSQL, SqlServer, 
> such a query is legal and will return the result after the offset.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to