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

qiang.wang commented on CALCITE-5927:
-------------------------------------

[~jhyde] hi, i have submit a PR to fix this issue, could you please help to 
review this pr?  thanks 

> LoptOptimizeJoinRule has wrong condition when finding out if Self-Join keys 
> are unique
> --------------------------------------------------------------------------------------
>
>                 Key: CALCITE-5927
>                 URL: https://issues.apache.org/jira/browse/CALCITE-5927
>             Project: Calcite
>          Issue Type: Bug
>          Components: core
>    Affects Versions: 1.33.0, 1.34.0, 1.35.0
>            Reporter: qiang.wang
>            Assignee: qiang.wang
>            Priority: Minor
>              Labels: pull-request-available
>
> There's wrong condition in function _areSelfJoinKeysUnique._ 
>  
> {code:java}
> // Make sure each key on the left maps to the same simple column as the
> // corresponding key on the right
> for (IntPair pair : joinInfo.pairs()) {
>   final RelColumnOrigin leftOrigin =
>       mq.getColumnOrigin(leftRel, pair.source);
>   if (leftOrigin == null || !leftOrigin.isDerived()) {
>     return false;
>   }
>   final RelColumnOrigin rightOrigin =
>       mq.getColumnOrigin(rightRel, pair.target);
>   if (rightOrigin == null || !rightOrigin.isDerived()) {
>     return false;
>   }
>   if (leftOrigin.getOriginColumnOrdinal()
>       != rightOrigin.getOriginColumnOrdinal()) {
>     return false;
>   }
> } {code}
> The wrong conditions are '{_}if (leftOrigin == null || 
> !leftOrigin.isDerived()){_}' and '{_}if (rightOrigin == null || 
> !rightOrigin.isDerived()){_}'.  
> This function wants to find out if the self-join keys are unique. so for each 
> self-join key, find
> _leftOrigin_ and _rightOrigin_ first, then will return false if any of them 
> is null. But why it returns false when any of them is not _Derived?_  I think 
> exactly the opposite is right.
>  I think this is a bug comes from CALCITE-4251
> Before that PR, this function will return false only when _leftOrigin_ or 
> _rightOrigin_ is null, and the function _RelMetadataQuery#getColumnOrigin_ 
> will return null if column is derived, so the logic is : 'this function will 
> return null when  _leftOrigin_ or _rightOrigin_ is null or is derived', but 
> now is : 'this function will return null when  _leftOrigin_ or _rightOrigin_ 
> is null or is not derived'.
>  



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

Reply via email to