[ https://issues.apache.org/jira/browse/CALCITE-2978?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16808847#comment-16808847 ]
Julian Hyde commented on CALCITE-2978: -------------------------------------- Yes, this is intended behavior. Note that if the sub-query comes from expanding a view with an ORDER BY clause we will try to respect that. > sorting not applied in subqueries > --------------------------------- > > Key: CALCITE-2978 > URL: https://issues.apache.org/jira/browse/CALCITE-2978 > Project: Calcite > Issue Type: Bug > Affects Versions: 1.19.0 > Reporter: Pressenna > Assignee: Danny Chan > Priority: Major > > {code:sql} > CREATE TABLE test (id INT, val INT); > INSERT INTO test VALUES (1,1); > INSERT INTO test VALUES (2,2); > INSERT INTO test VALUES (3,3); > INSERT INTO test VALUES (4,4); > SELECT id FROM (SELECT id, val FROM test ORDER BY val DESC); > {code} > Looks like CALCITE-2798 removes the sorting in sub-queries too aggressively. > Update: > I might be wrong here and jumped the gun too early. > Looks like SQL does not dictate that the outer query has to retain any order > of the inner query. > The sort is applied if a {{LIMIT}} is specified in the inner query, to reduce > the inner result correctly. > Happy to close as invalid. -- This message was sent by Atlassian JIRA (v7.6.3#76005)