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

Haisheng Yuan commented on CALCITE-4557:
----------------------------------------

{quote}
I doubt that a 5-key sort is significantly more expensive than a 1- or 2-key 
sort. Most likely, they all terminate in 1 or 1.1 comparisons on average.
{quote}
It depends on the number of distinct values for each sort column, but generally 
more keys are more expensive. I also remember in Postgres mailing list, there 
is a discussion about the optimization to reorder the sorting columns based on 
the number of distinct values. But it is hard to give accurate formula based on 
the NDV, because there can also be some correlation between columns, just a 
very coarse level estimation, sometimes not even close. 

> 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)

Reply via email to