You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@calcite.apache.org by "qiang.wang (Jira)" <ji...@apache.org> on 2023/08/13 14:02:00 UTC

[jira] [Created] (CALCITE-5925) LoptOptimizeJoinRule has when judging if SelfJoinKeys are unique

qiang.wang created CALCITE-5925:
-----------------------------------

             Summary: LoptOptimizeJoinRule has  when judging if SelfJoinKeys are unique
                 Key: CALCITE-5925
                 URL: https://issues.apache.org/jira/browse/CALCITE-5925
             Project: Calcite
          Issue Type: Bug
          Components: core
    Affects Versions: 1.35.0, 1.34.0, 1.33.0
            Reporter: qiang.wang


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)