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

LP:1002108 - Wrong result (or crash) from a query with duplicated field in the group list and a limit clause

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 5.5.30, 5.3.13, 5.1.73
    • Component/s: None
    • Labels:

      Description

      The following test case gives us a wrong result in MariaDB 5.2/5.3/5.5:

      CREATE TABLE t1(
      col1 int,
      UNIQUE INDEX idx (col1)
      );

      INSERT INTO t1 VALUES (1),(2),(3),(4),(5),(6),(7),(8),(9),(10);

      SELECT SQL_BIG_RESULT tbl1.col1 AS field1, tbl2.col1 AS field2
      FROM t1 as tbl1, t1 as tbl2
      GROUP BY field1, field2
      LIMIT 3;

      (see also bug #53534 in bugs.mysql.com)

        Gliffy Diagrams

          Attachments

            Activity

            Hide
            ratzpo Rasmus Johansson added a comment -

            Launchpad bug id: 1002108

            Show
            ratzpo Rasmus Johansson added a comment - Launchpad bug id: 1002108
            Hide
            timour Timour Katchaounov added a comment -

            Investigation of the bug on various versions, using the following test case (based on the one in MySQL 5.6):
            CREATE TABLE t1m(col1 int, UNIQUE INDEX idx (col1)) engine=myisam;

            INSERT INTO t1m VALUES (1),(2),(3),(4),(5),(6),(7),(8),(9),(10),
            (11),(12),(13),(14),(15),(16),(17),(18),(19),(20);

            EXPLAIN
            SELECT SQL_BIG_RESULT col1 AS field1, col1 AS field2
            FROM t1m GROUP BY field1, field2;

            SELECT SQL_BIG_RESULT col1 AS field1, col1 AS field2
            FROM t1m GROUP BY field1, field2;

            • MariaDB 5.3 - wrong result
            • MariaDB 5.5 - crash in debug mode - failed assert DBUG_ASSERT(inited==INDEX)
              in ha_index_end() called from QUICK_GROUP_MIN_MAX_SELECT::~QUICK_GROUP_MIN_MAX_SELECT
            • MySQL 5.5 - wrong result
            • MySQL 5.6 - fixed
            Show
            timour Timour Katchaounov added a comment - Investigation of the bug on various versions, using the following test case (based on the one in MySQL 5.6): CREATE TABLE t1m(col1 int, UNIQUE INDEX idx (col1)) engine=myisam; INSERT INTO t1m VALUES (1),(2),(3),(4),(5),(6),(7),(8),(9),(10), (11),(12),(13),(14),(15),(16),(17),(18),(19),(20); EXPLAIN SELECT SQL_BIG_RESULT col1 AS field1, col1 AS field2 FROM t1m GROUP BY field1, field2; SELECT SQL_BIG_RESULT col1 AS field1, col1 AS field2 FROM t1m GROUP BY field1, field2; MariaDB 5.3 - wrong result MariaDB 5.5 - crash in debug mode - failed assert DBUG_ASSERT(inited==INDEX) in ha_index_end() called from QUICK_GROUP_MIN_MAX_SELECT::~QUICK_GROUP_MIN_MAX_SELECT MySQL 5.5 - wrong result MySQL 5.6 - fixed
            Hide
            timour Timour Katchaounov added a comment -

            MySQL's fix looks like an optimization that hides the real problem. Investigating.

            Show
            timour Timour Katchaounov added a comment - MySQL's fix looks like an optimization that hides the real problem. Investigating.
            Hide
            timour Timour Katchaounov added a comment -

            The situation described in this bug is quite uncommon, therefore the solution is to make loose scan analysis take into account that there may be duplicate columns. Since there cannot be an index with duplicate columns, loose scan will become inapplicable to group by queries with duplicate group columns.

            This limitation will be lifted in 10.0 by MDEV-4119.

            Show
            timour Timour Katchaounov added a comment - The situation described in this bug is quite uncommon, therefore the solution is to make loose scan analysis take into account that there may be duplicate columns. Since there cannot be an index with duplicate columns, loose scan will become inapplicable to group by queries with duplicate group columns. This limitation will be lifted in 10.0 by MDEV-4119 .
            Hide
            timour Timour Katchaounov added a comment -

            Moved fix to 5.1, test, push

            Show
            timour Timour Katchaounov added a comment - Moved fix to 5.1, test, push

              People

              • Assignee:
                timour Timour Katchaounov
                Reporter:
                igor Igor Babaev
              • Votes:
                0 Vote for this issue
                Watchers:
                1 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:

                  Time Tracking

                  Estimated:
                  Original Estimate - Not Specified
                  Not Specified
                  Remaining:
                  Time Spent - 3 days, 5 hours, 30 minutes Remaining Estimate - 4 hours, 30 minutes
                  4h 30m
                  Logged:
                  Time Spent - 3 days, 5 hours, 30 minutes Remaining Estimate - 4 hours, 30 minutes
                  3d 5h 30m