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

COUNT(DISTINCT column) returns bad result with too low tmp_table_size

    XMLWordPrintable

Details

    • Bug
    • Status: Confirmed (View Workflow)
    • Major
    • Resolution: Unresolved
    • 11.4.5, 11.7.2, 11.8.1, 10.6, 10.11, 11.4, 11.8, 11.4.7
    • 10.6, 10.11, 11.4, 11.8
    • Server
    • Both amd64 and aarch64 in docker are affected

    Description

      Under certain conditions, when setting `tmp_table_size` to very low value (tested with 1K, 2K, 4K, 8K (for 16K+ it works fine)), following query returns bad result:

      SELECT COUNT(DISTINCT t1.id_b) FROM t1 JOIN t2 ON t2.id_c = t1.id_c WHERE t1.id_a = 1;

      (returns 2 instead of 1)

      for following test data:

      CREATE TABLE t1 (id_a INT PRIMARY KEY, id_b INT, id_c INT);
      CREATE TABLE t2 (id_d INT PRIMARY KEY, id_c INT);

      INSERT INTO t1 VALUES (1, 1234, 1);
      INSERT INTO t2 VALUES (1, 1), (2, 1);

      Tried both InnoDB and MyISAM engines, the problem is not in the engine, as both fails the same way.

      The bug was introduced somewhere in the 11.4.5 release, as 11.4.4 is fine and everything newer is affected.

      Attaching shell script that can reproduce the error with provided minimal configuration file.

      Attachments

        1. minimal.cnf
          0.0 kB
        2. test.sh
          1 kB

        Issue Links

          Activity

            People

              monty Michael Widenius
              niximor Michal Kuchta
              Votes:
              0 Vote for this issue
              Watchers:
              3 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.