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

Losing PRIMARY KEY metadata makes a DISTINCT + window COUNT + LEFT JOIN query return empty

    XMLWordPrintable

Details

    Description

      The derived side contributes exactly one value `10`, because `t2` has one row and both predicates `t2.c0 > 0` and `t2.c0 != 5` are true. With the only surviving outer row `t3.c0 = 20`, both join predicates `t3.c0 != subq0.subq0_c0` and `t3.c0 >= subq0.subq0_c0` are true, so the query must return the single row `1 | 1 | 10 | 20`. MariaDB does return that row if the temp table preserves `t2`'s primary-key metadata, but returns an empty result when the same value `10` is read from a keyless temp table.

      How to repeat:

      CREATE TABLE t2(c0 INT PRIMARY KEY);
      CREATE TABLE t3(c0 INT UNIQUE NOT NULL);

      INSERT INTO t2 VALUES (10);
      INSERT INTO t3 VALUES (20),(-1);

      CREATE TEMPORARY TABLE predicate_temp_0 (t2_c0 INT NOT NULL);
      INSERT INTO predicate_temp_0 SELECT t2.c0 FROM t2 WHERE (t2.c0 > 0);

      SELECT DISTINCT COUNT(1) OVER (), COUNT(subq0.subq0_c0) OVER (), subq0.subq0_c0, t3.c0
      FROM t3
      INNER JOIN t2 ON (t3.c0 > t2.c0)
      LEFT JOIN
      (SELECT predicate_temp_0.t2_c0 AS subq0_c0 FROM predicate_temp_0 WHERE (predicate_temp_0.t2_c0 != 5)) AS subq0
      ON (t3.c0 != subq0.subq0_c0)
      WHERE (t3.c0 >= subq0.subq0_c0); – Expected correct result: 1 | 1 | 10 | 20 – actual Wrong result: <empty>

      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.