[ https://issues.apache.org/jira/browse/CALCITE-4557?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17326067#comment-17326067 ]
Julian Hyde commented on CALCITE-4557: -------------------------------------- A useful optimization would be to remove sort fields that are functionally dependent on columns that came before them. For example, {code}SELECT * FROM Emp ORDER BY deptno, empno, hiredate{code} can be simplified to {code}SELECT * FROM Emp ORDER BY deptno, empno{code} because everything is FD on {{empno}}. If you are doing a sort only for purposes of uniqueness (i.e. don't care about the actual order) it would make sense to move the highest cardinality columns up front. Then drop the trailing FD columns. > Sort costing should account the number of sort keys: the more keys to > compare, the more the cost > ------------------------------------------------------------------------------------------------ > > Key: CALCITE-4557 > URL: https://issues.apache.org/jira/browse/CALCITE-4557 > Project: Calcite > Issue Type: Improvement > Components: core > Affects Versions: 1.26.0 > Reporter: Vladimir Sitnikov > Priority: Major > > Current costing for sort does not account for the number of keys in the > comparison function which might result in worse plan selection. -- This message was sent by Atlassian Jira (v8.3.4#803005)