Uploaded image for project: 'Calcite'
  1. Calcite
  2. CALCITE-1498

Avoid LIMIT with trivial ORDER BY being pushed through JOIN endlessly

Details

    • Bug
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • 1.10.0
    • 1.11.0
    • core
    • None

    Description

      Currently LIMIT with trivial ORDER BY will be pushed through a JOIN endlessly by SortJoinTransposeRule, because the method RelMdUtil.checkInputForCollationAndLimit used to prevent endless matching does not know that an sort on zero keys is trivially satisfied (without requiring a Sort) by any relational expression:

          // Check if the input is already sorted
          boolean alreadySorted = false;
          if (!alreadySorted) {
            for (RelCollation inputCollation : mq.collations(input)) {
              if (inputCollation.satisfies(collation)) {
                alreadySorted = true;
                break;
              }
            }
          }
      

      if mq.collations(input) returns an empty array, alreadySorted will always be false even if the required collation is an empty collation (which indicates there's no need to sort). As a result, the check method RelMdUtil.checkInputForCollationAndLimit will always return false and the SortJoinTransposeRule will keep being fired endlessly.

      Attachments

        Activity

          No work has yet been logged on this issue.

          People

            maryannxue Wei Xue
            maryannxue Wei Xue
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: