Uploaded image for project: 'MariaDB Server'
  1. MariaDB Server
  2. MDEV-39864

Window SUM over an empty left-joined derived table returns 0 instead of NULL

    XMLWordPrintable

Details

    • Bug
    • Status: Closed (View Workflow)
    • Major
    • Resolution: Duplicate
    • 11.8.8
    • N/A
    • Optimizer
    • None
    • Not for Release Notes

    Description

      the derived table `SELECT FALSE AS c0, t2.c0 AS c1 FROM t0, t2` is empty because `t0` is empty, so the outer `LEFT JOIN` produces exactly one NULL-extended row. On that row `s.c0` is NULL, therefore `SUM(s.c0) OVER (PARTITION BY t2.c0)` must also be NULL. MariaDB instead leaks the missing inner constant `FALSE/0` into the window aggregate and returns `0 | NULL`.

      CREATE TABLE t0(x INT);
      CREATE TABLE t2(c0 BOOLEAN);

      INSERT INTO t2 VALUES (FALSE);

      SELECT SUM(s.c0) OVER (PARTITION BY t2.c0), s.c0
      FROM t2
      LEFT JOIN (SELECT FALSE AS c0, t2.c0 AS c1 FROM t0, t2) AS s
      ON (t2.c0 = s.c1)
      WHERE s.c1 IS NULL; – Expected correct result: NULL | NULL – actual Wrong result: 0 | NULL

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              yx yx
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Git Integration

                  Error rendering 'com.xiplink.jira.git.jira_git_plugin:git-issue-webpanel'. Please contact your Jira administrators.