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

Wrong result - count(distinct), Using index for group-by (scanning)

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: 10.0.4, 5.5.32
    • Fix Version/s: 5.5.38, 10.0.12
    • Component/s: None
    • Labels:

      Description

      Taken from: http://bugs.mysql.com/bug.php?id=70038

      test case:

      --source include/have_innodb.inc
      
      CREATE TABLE tmp (
        id int NOT NULL AUTO_INCREMENT,
        a int NOT NULL,
        b int NOT NULL,
        PRIMARY KEY (id),
        UNIQUE KEY ba (b, a)
      ) ENGINE=InnoDB;
      
      INSERT INTO tmp (a, b) VALUES(1,101),(1,102),(1,103),(1,104),(1,105),(1,106),(1,107),(1,108),(1,109),(1,110);
      
      SELECT COUNT(DISTINCT b) FROM tmp WHERE a = 1;
      
      DROP TABLE tmp;
      

      Select returns 5, should be 10. Myisam works correctly.
      I think the problem is because in function QUICK_GROUP_MIN_MAX_SELECT::get_next() call to file->ha_index_read_map() fetches next row when it shouldn't. Happens when index_next_different() is called with is_index_scan = true.

        Gliffy Diagrams

          Attachments

            Issue Links

              Activity

              Hide
              gpfeng Guangpu Feng added a comment -

              Glad to see the progress!

              Show
              gpfeng Guangpu Feng added a comment - Glad to see the progress!
              Hide
              timour Timour Katchaounov added a comment -

              Suggestion - add a storage engine property that tells the server if the engine supports this handler call sequence.

              Show
              timour Timour Katchaounov added a comment - Suggestion - add a storage engine property that tells the server if the engine supports this handler call sequence.
              Hide
              gpfeng Guangpu Feng added a comment -

              any progress?

              Show
              gpfeng Guangpu Feng added a comment - any progress?
              Hide
              pomyk Patryk Pomykalski added a comment -

              It was fixed in mysql 5.5.35 and the fix was merged. No test in mysql though.

              Show
              pomyk Patryk Pomykalski added a comment - It was fixed in mysql 5.5.35 and the fix was merged. No test in mysql though.
              Hide
              serg Sergei Golubchik added a comment -

              Thanks! I've added the test case, and will now close this bug report.

              Show
              serg Sergei Golubchik added a comment - Thanks! I've added the test case, and will now close this bug report.

                People

                • Assignee:
                  serg Sergei Golubchik
                  Reporter:
                  pomyk Patryk Pomykalski
                • Votes:
                  1 Vote for this issue
                  Watchers:
                  5 Start watching this issue

                  Dates

                  • Created:
                    Updated:
                    Resolved: