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

COUNT(expr) OVER() counts a NULL-extended constant from an empty derived table

    XMLWordPrintable

Details

    Description

      The derived table `SELECT 'x' AS c2 FROM t3` is empty because `t3` is empty, and `LEFT JOIN ... ON (0=1)` guarantees that the only output row sees `subq0.c2 = NULL`. Therefore `COUNT(subq0.c2) OVER ()` must be `0`. MariaDB instead counts that NULL-extended constant as if it were non-NULL and returns `1`.

      How to repeat:

      CREATE TABLE t0(c0 INT);
      CREATE TABLE t3(c0 INT);

      INSERT INTO t0 VALUES (0);

      SELECT COUNT(subq0.c2) OVER ()
      FROM t0
      LEFT JOIN (SELECT 'x' AS c2 FROM t3) AS subq0
      ON (0=1); – Expected correct result: 0 – actual Wrong result: 1

      Attachments

        Issue Links

          Activity

            People

              psergei Sergei Petrunia
              yx yx
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:

                Git Integration

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