Thomas Rebele created CALCITE-5473:
--------------------------------------

             Summary: Keep more collations in RelMdCollation#project for 
monotonic RexCalls
                 Key: CALCITE-5473
                 URL: https://issues.apache.org/jira/browse/CALCITE-5473
             Project: Calcite
          Issue Type: Improvement
            Reporter: Thomas Rebele


Some RexCalls do not affect the collation, i.e., $0+10 has the same collation 
as $0 (if there are now integer overflows). This is already implemented in 
{{{}SqlMonotonicBinaryOperator#getMonotonicity{}}}.

If we have an input with collation [0,1], and a {{{}Calc(a=$0+10, b=$1){}}}, 
then the output collation would be [0, 1] as well. This is the case for 
STRICTLY_INCREASING or STRICTLY_DECREASING calls (though the direction of the 
field collation might need to be adapted).

However, if the Calc was {{{}Calc(a=FLOOR($0), b=$1){}}}, then the output 
collation would be just [0], as the sortedness of b is not guaranteed. This 
happens for example with rows (0.2, 50) and (0.3, 20) and (0.4, 30), in that 
order. So for INCREASING, DECREASING, or CONSTANT the collation would be 
shortened.

The right place to implement this would probably be 
{{{}RelMdCollation#project{}}}. The {{fieldCollationsForRexCalls}} loop would 
need to stay, because some calls may introduce a collation, regardless of the 
input. E.g., {{SELECT CURRENT_DATE FROM some_random_table}} is always sorted.



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

Reply via email to