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

Wrong result for scalar subquery (single value aggregation) from empty input

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • None
    • 1.29.0
    • None

    Description

      Scalar subqueries from the empty input return non-nullable type and in some cases it leads to wrong results. For example:

      SELECT (SELECT 1 FROM (SELECT NULL) WHERE 1 = 0)
      

      Returns 0, but expected NULL according to the SQL standard:

      Let SS be a <scalar subquery>.
      Case:
      a) If the cardinality of SS is greater than 1 (one), then an exception condition is raised: cardinality violation.
      b) If the cardinality of SS is 0 (zero), then the value of the <scalar subquery> is the null value.
      c) Otherwise, let C be the column of <query expression> simply contained in SS. The value of SS is the value of C in the unique row of the result of the <scalar subquery>.
      

      Attachments

        Activity

          People

            alex_pl Aleksey Plekhanov
            alex_pl Aleksey Plekhanov
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Time Tracking

                Estimated:
                Original Estimate - Not Specified
                Not Specified
                Remaining:
                Remaining Estimate - 0h
                0h
                Logged:
                Time Spent - 50m
                50m