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

Wrong result set from a query with HAVING containing a subquery with SF call.

Details

    • Bug
    • Status: Stalled (View Workflow)
    • Major
    • Resolution: Unresolved
    • 10.2(EOL), 10.3(EOL), 10.4(EOL), 10.5, 10.6, 10.7(EOL), 10.8(EOL)
    • 10.3(EOL)
    • Optimizer

    Description

      The query with HAVING from the following test case

      SET @@sql_mode = '';
       
      CREATE TABLE series (
        val INT(10) UNSIGNED NOT NULL
      );
      INSERT INTO series VALUES(1);
      CREATE TABLE seq_calls (
        c INT
      );
      INSERT INTO seq_calls VALUES(0);
       
      DELIMITER |;
      CREATE FUNCTION next_seq_value() RETURNS INT
      BEGIN
       DECLARE next_val INT;
       SELECT val INTO next_val FROM series;
       UPDATE series SET val=mod(val + 1, 2);
       UPDATE seq_calls SET c=c+1;
       RETURN next_val;
      END;
      |
      DELIMITER ;|
       
      CREATE TABLE t1 (t INT, u INT, KEY(t));
      INSERT INTO t1 VALUES(10, 10), (11, 11), (12, 12), (12, 13),(14, 15), (15, 16),
                           (16, 17), (17, 18);
      ANALYZE TABLE t1;
       
      SELECT * FROM series, seq_calls;
      SELECT t, next_seq_value() r FROM t1 FORCE INDEX(t)
      GROUP BY t HAVING (SELECT 1 FROM t1 WHERE r = 1 LIMIT 1)
      ORDER BY t1.u;
       
      DROP TABLE t1;
      DROP FUNCTION next_seq_value;
      DROP TABLE series, seq_calls;
      

      returns a wrong result set:

      MariaDB [test]> SELECT t, next_seq_value() r FROM t1 FORCE INDEX(t)
          -> GROUP BY t HAVING (SELECT 1 FROM t1 WHERE r = 1 LIMIT 1)
          -> ORDER BY t1.u;
      +------+------+
      | t    | r    |
      +------+------+
      |   10 |    1 |
      |   11 |    1 |
      |   12 |    1 |
      |   14 |    1 |
      |   15 |    1 |
      |   16 |    1 |
      |   17 |    1 |
      +------+------+
      

      The expected result set is:

      MariaDB [test]> SELECT t, next_seq_value() r FROM t1 FORCE INDEX(t)
          -> GROUP BY t HAVING (SELECT 1 FROM t1 WHERE r = 1 LIMIT 1)
          -> ORDER BY t1.u;
      +------+------+
      | t    | r    |
      +------+------+
      |   10 |    1 |
      |   12 |    1 |
      |   15 |    1 |
      |   17 |    1 |
      +------+------+
      

      This bug is a regression as 5.5,10.0,10.1 return the right result set

      Attachments

        Activity

          igor Igor Babaev created issue -
          igor Igor Babaev made changes -
          Field Original Value New Value
          Summary Wrong result set from a query with HAVING over SP call. Wrong result set from a query with HAVING over SF call.
          igor Igor Babaev made changes -
          Labels regression
          igor Igor Babaev made changes -
          Status Open [ 1 ] In Progress [ 3 ]
          igor Igor Babaev made changes -
          Summary Wrong result set from a query with HAVING over SF call. Wrong result set from a query with HAVING containing a subquery with SF call.
          serg Sergei Golubchik made changes -
          Workflow MariaDB v3 [ 83340 ] MariaDB v4 [ 144467 ]
          alice Alice Sherepa added a comment - - edited

          Currently 10.3-10.10 (10.3 f4a1298f245f678badc8a5b5) returns the expected result, but without FORCE INDEX the result is different:

          SELECT t, next_seq_value() r FROM t1 FORCE INDEX(t)
          GROUP BY t HAVING (SELECT 1 FROM t1 WHERE r = 1 LIMIT 1)
          ORDER BY t1.u;
          t	r
          10	1
          12	1
          15	1
          17	1
          

          without FORCE INDEX:

          SELECT t, next_seq_value() r FROM t1 
          GROUP BY t HAVING (SELECT 1 FROM t1 WHERE r = 1 LIMIT 1)
          ORDER BY t1.u;
          t	r
          10	1
          12	1
          14	1
          16	1
          

          on bb-11.0 ebd10cdcd5f87743ff3 - there is a wrong (2nd) result in both cases

          alice Alice Sherepa added a comment - - edited Currently 10.3-10.10 (10.3 f4a1298f245f678badc8a5b5) returns the expected result, but without FORCE INDEX the result is different: SELECT t, next_seq_value() r FROM t1 FORCE INDEX(t) GROUP BY t HAVING (SELECT 1 FROM t1 WHERE r = 1 LIMIT 1) ORDER BY t1.u; t r 10 1 12 1 15 1 17 1 without FORCE INDEX: SELECT t, next_seq_value() r FROM t1 GROUP BY t HAVING (SELECT 1 FROM t1 WHERE r = 1 LIMIT 1) ORDER BY t1.u; t r 10 1 12 1 14 1 16 1 on bb-11.0 ebd10cdcd5f87743ff3 - there is a wrong (2nd) result in both cases
          alice Alice Sherepa made changes -
          Labels regression 11.0-sel
          alice Alice Sherepa made changes -
          Affects Version/s 10.3 [ 22126 ]
          Affects Version/s 10.4 [ 22408 ]
          Affects Version/s 10.5 [ 23123 ]
          Affects Version/s 10.6 [ 24028 ]
          Affects Version/s 10.7 [ 24805 ]
          Affects Version/s 10.8 [ 26121 ]
          alice Alice Sherepa made changes -
          Fix Version/s 10.3 [ 22126 ]
          Fix Version/s 10.2 [ 14601 ]
          monty Michael Widenius made changes -
          Assignee Igor Babaev [ igor ] Michael Widenius [ monty ]
          julien.fritsch Julien Fritsch made changes -
          Comment [ Automated message:
          ----------------------------
          Since this issue has not been updated since 6 weeks, it's time to move it back to Stalled. ]
          julien.fritsch Julien Fritsch made changes -
          Status In Progress [ 3 ] Stalled [ 10000 ]

          People

            monty Michael Widenius
            igor Igor Babaev
            Votes:
            0 Vote for this issue
            Watchers:
            4 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.