Details

    • Bug
    • Status: Closed (View Workflow)
    • Major
    • Resolution: Fixed
    • 10.3.8, 10.3.9, 10.3(EOL)
    • 10.3.10
    • Optimizer
    • None
    • CentOS 7 3.10.0-862.9.1.el7.x86_64

    Description

      CREATE TABLE IF NOT EXISTS `test` (
        `n1` int(10) NOT NULL,
        `n2` int(10) NOT NULL,
        `c1` char(1) NOT NULL,
        KEY `c1` (`c1`) USING BTREE,
        KEY `n1_c1_n2` (`n1`,`c1`,`n2`) USING BTREE
      ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
       
      INSERT INTO `test` (`n1`, `n2`, `c1`) VALUES
      (0, 2, 'a'),
      (1, 3, 'a');
       
      SELECT test.n1
      FROM test
      INNER JOIN (
      	SELECT n1, n2
      	FROM test
      	WHERE
      		c1 = 'a'
      	GROUP BY n1
      	) t2
      	ON (t2.n1 = test.n1 AND t2.n2 = test.n2)
      WHERE c1 = 'a'
      GROUP BY n1
      

      Running the above query, as setup above, gives the incorrect result of:
      1

      Removing n2 from the multi-column index (`n1`,`c1`,`n2`), or rearranging that index to be (`n2`,`c1`,`n1`), or removing that index altogether, gives the correct query result of:
      0
      1

      The combination of that specific multi-column index with the single-column index of c1 seems to trigger the issue.

      Attachments

        Activity

          fhx Frank E created issue -
          serg Sergei Golubchik made changes -
          Field Original Value New Value
          Description CREATE TABLE IF NOT EXISTS `test` (
            `n1` int(10) NOT NULL,
            `n2` int(10) NOT NULL,
            `c1` char(1) NOT NULL,
            KEY `c1` (`c1`) USING BTREE,
            KEY `n1_c1_n2` (`n1`,`c1`,`n2`) USING BTREE
          ) ENGINE=InnoDB DEFAULT CHARSET=utf8;

          INSERT INTO `test` (`n1`, `n2`, `c1`) VALUES
          (926, 1413870671, '3'),
          (27343, 1531920142, '3');

          SELECT test.n1
          FROM test
          INNER JOIN (
          SELECT n1, n2
          FROM test
          WHERE
          c1 = '3'
          GROUP BY n1
          ) t2
          ON (t2.n1 = test.n1 AND t2.n2 = test.n2)
          WHERE c1 = '3'
          GROUP BY n1

          Running the above query, as setup above, gives the incorrect result of:
          27343

          Removing the `n2` from the multi-column index n1_c1_n2, or rearranging that index to be (`n2`,`c1`,`n1`), or removing that index altogether, gives the correct query result of:
          926
          27343
          {code:sql}
          CREATE TABLE IF NOT EXISTS `test` (
            `n1` int(10) NOT NULL,
            `n2` int(10) NOT NULL,
            `c1` char(1) NOT NULL,
            KEY `c1` (`c1`) USING BTREE,
            KEY `n1_c1_n2` (`n1`,`c1`,`n2`) USING BTREE
          ) ENGINE=InnoDB DEFAULT CHARSET=utf8;

          INSERT INTO `test` (`n1`, `n2`, `c1`) VALUES
          (926, 1413870671, '3'),
          (27343, 1531920142, '3');

          SELECT test.n1
          FROM test
          INNER JOIN (
          SELECT n1, n2
          FROM test
          WHERE
          c1 = '3'
          GROUP BY n1
          ) t2
          ON (t2.n1 = test.n1 AND t2.n2 = test.n2)
          WHERE c1 = '3'
          GROUP BY n1
          {code}
          Running the above query, as setup above, gives the incorrect result of:
          27343

          Removing the `n2` from the multi-column index n1_c1_n2, or rearranging that index to be (`n2`,`c1`,`n1`), or removing that index altogether, gives the correct query result of:
          926
          27343
          fhx Frank E made changes -
          Description {code:sql}
          CREATE TABLE IF NOT EXISTS `test` (
            `n1` int(10) NOT NULL,
            `n2` int(10) NOT NULL,
            `c1` char(1) NOT NULL,
            KEY `c1` (`c1`) USING BTREE,
            KEY `n1_c1_n2` (`n1`,`c1`,`n2`) USING BTREE
          ) ENGINE=InnoDB DEFAULT CHARSET=utf8;

          INSERT INTO `test` (`n1`, `n2`, `c1`) VALUES
          (926, 1413870671, '3'),
          (27343, 1531920142, '3');

          SELECT test.n1
          FROM test
          INNER JOIN (
          SELECT n1, n2
          FROM test
          WHERE
          c1 = '3'
          GROUP BY n1
          ) t2
          ON (t2.n1 = test.n1 AND t2.n2 = test.n2)
          WHERE c1 = '3'
          GROUP BY n1
          {code}
          Running the above query, as setup above, gives the incorrect result of:
          27343

          Removing the `n2` from the multi-column index n1_c1_n2, or rearranging that index to be (`n2`,`c1`,`n1`), or removing that index altogether, gives the correct query result of:
          926
          27343
          {code:sql}
          CREATE TABLE IF NOT EXISTS `test` (
            `n1` int(10) NOT NULL,
            `n2` int(10) NOT NULL,
            `c1` char(1) NOT NULL,
            KEY `c1` (`c1`) USING BTREE,
            KEY `n1_c1_n2` (`n1`,`c1`,`n2`) USING BTREE
          ) ENGINE=InnoDB DEFAULT CHARSET=utf8;

          INSERT INTO `test` (`n1`, `n2`, `c1`) VALUES
          (0, 2, 'a'),
          (1, 3, 'a');

          SELECT test.n1
          FROM test
          INNER JOIN (
          SELECT n1, n2
          FROM test
          WHERE
          c1 = 'a'
          GROUP BY n1
          ) t2
          ON (t2.n1 = test.n1 AND t2.n2 = test.n2)
          WHERE c1 = 'a'
          GROUP BY n1
          {code}
          Running the above query, as setup above, gives the incorrect result of:
          1

          Removing n2 from the multi-column index (`n1`,`c1`,`n2`), or rearranging that index to be (`n2`,`c1`,`n1`), or removing that index altogether, gives the correct query result of:
          0
          1

          The combination of that specific multi-column index with the single-column index of c1 seem to cause the issue.
          fhx Frank E made changes -
          Description {code:sql}
          CREATE TABLE IF NOT EXISTS `test` (
            `n1` int(10) NOT NULL,
            `n2` int(10) NOT NULL,
            `c1` char(1) NOT NULL,
            KEY `c1` (`c1`) USING BTREE,
            KEY `n1_c1_n2` (`n1`,`c1`,`n2`) USING BTREE
          ) ENGINE=InnoDB DEFAULT CHARSET=utf8;

          INSERT INTO `test` (`n1`, `n2`, `c1`) VALUES
          (0, 2, 'a'),
          (1, 3, 'a');

          SELECT test.n1
          FROM test
          INNER JOIN (
          SELECT n1, n2
          FROM test
          WHERE
          c1 = 'a'
          GROUP BY n1
          ) t2
          ON (t2.n1 = test.n1 AND t2.n2 = test.n2)
          WHERE c1 = 'a'
          GROUP BY n1
          {code}
          Running the above query, as setup above, gives the incorrect result of:
          1

          Removing n2 from the multi-column index (`n1`,`c1`,`n2`), or rearranging that index to be (`n2`,`c1`,`n1`), or removing that index altogether, gives the correct query result of:
          0
          1

          The combination of that specific multi-column index with the single-column index of c1 seem to cause the issue.
          {code:sql}
          CREATE TABLE IF NOT EXISTS `test` (
            `n1` int(10) NOT NULL,
            `n2` int(10) NOT NULL,
            `c1` char(1) NOT NULL,
            KEY `c1` (`c1`) USING BTREE,
            KEY `n1_c1_n2` (`n1`,`c1`,`n2`) USING BTREE
          ) ENGINE=InnoDB DEFAULT CHARSET=utf8;

          INSERT INTO `test` (`n1`, `n2`, `c1`) VALUES
          (0, 2, 'a'),
          (1, 3, 'a');

          SELECT test.n1
          FROM test
          INNER JOIN (
          SELECT n1, n2
          FROM test
          WHERE
          c1 = 'a'
          GROUP BY n1
          ) t2
          ON (t2.n1 = test.n1 AND t2.n2 = test.n2)
          WHERE c1 = 'a'
          GROUP BY n1
          {code}
          Running the above query, as setup above, gives the incorrect result of:
          1

          Removing n2 from the multi-column index (`n1`,`c1`,`n2`), or rearranging that index to be (`n2`,`c1`,`n1`), or removing that index altogether, gives the correct query result of:
          0
          1

          The combination of that specific multi-column index with the single-column index of c1 seems to trigger the issue.
          fhx Frank E made changes -
          Affects Version/s 10.3.9 [ 23114 ]
          elenst Elena Stepanova made changes -
          Status Open [ 1 ] Confirmed [ 10101 ]
          elenst Elena Stepanova made changes -
          Component/s Optimizer [ 10200 ]
          Fix Version/s 10.3 [ 22126 ]
          Affects Version/s 10.3 [ 22126 ]
          Assignee Igor Babaev [ igor ]
          igor Igor Babaev (Inactive) made changes -
          Status Confirmed [ 10101 ] In Progress [ 3 ]
          igor Igor Babaev (Inactive) made changes -
          Fix Version/s 10.3.10 [ 23140 ]
          Fix Version/s 10.3 [ 22126 ]
          Resolution Fixed [ 1 ]
          Status In Progress [ 3 ] Closed [ 6 ]
          serg Sergei Golubchik made changes -
          Workflow MariaDB v3 [ 88787 ] MariaDB v4 [ 154762 ]

          People

            igor Igor Babaev (Inactive)
            fhx Frank E
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Git Integration

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