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

[5.1-5.3] Wrong result (extra rows) with subquery in HAVING clause

Details

    Description

      It's an upstream bug, it was introduced by a 5.1 merge, particularly by the following revision:

      revno: 4005
      revision-id: sergey.glukhov@oracle.com-20130507091058-x4li5jat6pvhop96
      parent: annamalai.gurusami@oracle.com-20130506105856-d5il8vpqcovru47g
      committer: Sergey Glukhov <sergey.glukhov@oracle.com>
      branch nick: mysql-5.1
      timestamp: Tue 2013-05-07 13:10:58 +0400
      message:
        Bug#16095534 CRASH: PREPARED STATEMENT CRASHES IN ITEM_BOOL_FUNC2::FIX_LENGTH_AND_DEC
        The problem happened due to broken left expression in Item_in_optimizer object.
        In case of the bug left expression is runtime created Item_outer_ref item which
        is deleted at the end of the statement and one of Item_in_optimizer arguments
        becomes bad when re-executed. The fix is to use real_item() instead of original
        left expression. Note: It feels a bit weird that after preparing, the field is
        directly part of the generated Item_func_eq, whereas in execution it is replaced
        with an Item_outer_ref wrapper object.

      CREATE TABLE t1 (a INT);
      INSERT INTO t1 VALUES (8),(3);
      SELECT a FROM t1 GROUP BY a HAVING a IN ( SELECT 3 );

      Actual result:

      a
      3
      8

      Expected result:

      a
      3

      Reproducible on MySQL 5.1.73, 5.5.38.
      Not reproducible on MySQL 5.6.17.
      Reproducible on current MariaDB 5.1 (revno 3221), 5.2 (revno 3233), 5.3 (revno 3788).
      Not reproducible on current MariaDB 5.5 (revno 4192) and 10.0 (revno 4212).

      Attachments

        Activity

          elenst Elena Stepanova created issue -
          elenst Elena Stepanova made changes -
          Field Original Value New Value
          serg Sergei Golubchik made changes -
          Priority Major [ 3 ] Minor [ 4 ]
          serg Sergei Golubchik made changes -
          Workflow defaullt [ 41709 ] MariaDB v2 [ 43607 ]
          elenst Elena Stepanova made changes -
          Affects Version/s N/A [ 14700 ]
          elenst Elena Stepanova made changes -
          Description It's an upstream bug, it was introduced by a 5.1 merge, particularly by the following revision:

          {noformat}
          revno: 4005
          revision-id: sergey.glukhov@oracle.com-20130507091058-x4li5jat6pvhop96
          parent: annamalai.gurusami@oracle.com-20130506105856-d5il8vpqcovru47g
          committer: Sergey Glukhov <sergey.glukhov@oracle.com>
          branch nick: mysql-5.1
          timestamp: Tue 2013-05-07 13:10:58 +0400
          message:
            Bug#16095534 CRASH: PREPARED STATEMENT CRASHES IN ITEM_BOOL_FUNC2::FIX_LENGTH_AND_DEC
            The problem happened due to broken left expression in Item_in_optimizer object.
            In case of the bug left expression is runtime created Item_outer_ref item which
            is deleted at the end of the statement and one of Item_in_optimizer arguments
            becomes bad when re-executed. The fix is to use real_item() instead of original
            left expression. Note: It feels a bit weird that after preparing, the field is
            directly part of the generated Item_func_eq, whereas in execution it is replaced
            with an Item_outer_ref wrapper object.
          {noformat}

          {code:sql}
          CREATE TABLE t1 (a INT);
          INSERT INTO t1 VALUES (8),(3);
          SELECT a FROM t1 GROUP BY a HAVING a IN ( SELECT 3 );
          {code}

          Actual result:
          {noformat}
          a
          3
          8
          {noformat}

          Expected result:
          {noformat}
          a
          3
          {noformat}

          Reproducible on MySQL 5.1.73, 5.5.38.
          Not reproducible on current 5.5 (revno 4192) and 10.0 (revno 4212).
          Not reproducible on MySQL 5.6.17.
          It's an upstream bug, it was introduced by a 5.1 merge, particularly by the following revision:

          {noformat}
          revno: 4005
          revision-id: sergey.glukhov@oracle.com-20130507091058-x4li5jat6pvhop96
          parent: annamalai.gurusami@oracle.com-20130506105856-d5il8vpqcovru47g
          committer: Sergey Glukhov <sergey.glukhov@oracle.com>
          branch nick: mysql-5.1
          timestamp: Tue 2013-05-07 13:10:58 +0400
          message:
            Bug#16095534 CRASH: PREPARED STATEMENT CRASHES IN ITEM_BOOL_FUNC2::FIX_LENGTH_AND_DEC
            The problem happened due to broken left expression in Item_in_optimizer object.
            In case of the bug left expression is runtime created Item_outer_ref item which
            is deleted at the end of the statement and one of Item_in_optimizer arguments
            becomes bad when re-executed. The fix is to use real_item() instead of original
            left expression. Note: It feels a bit weird that after preparing, the field is
            directly part of the generated Item_func_eq, whereas in execution it is replaced
            with an Item_outer_ref wrapper object.
          {noformat}

          {code:sql}
          CREATE TABLE t1 (a INT);
          INSERT INTO t1 VALUES (8),(3);
          SELECT a FROM t1 GROUP BY a HAVING a IN ( SELECT 3 );
          {code}

          Actual result:
          {noformat}
          a
          3
          8
          {noformat}

          Expected result:
          {noformat}
          a
          3
          {noformat}

          Reproducible on MySQL 5.1.73, 5.5.38.
          Not reproducible on MySQL 5.6.17.
          Reproducible on current MariaDB 5.1 (revno 3221), 5.2 (revno 3233), 5.3 (revno 3788).
          Not reproducible on current MariaDB 5.5 (revno 4192) and 10.0 (revno 4212).
          elenst Elena Stepanova made changes -
          Summary Wrong result (extra rows) with subquery in HAVING clause [5.1-5.3] Wrong result (extra rows) with subquery in HAVING clause
          ratzpo Rasmus Johansson (Inactive) made changes -
          Workflow MariaDB v2 [ 43607 ] MariaDB v3 [ 64576 ]
          elenst Elena Stepanova made changes -
          Component/s Optimizer [ 10200 ]
          Fix Version/s N/A [ 14700 ]
          Resolution Won't Fix [ 2 ]
          Status Open [ 1 ] Closed [ 6 ]
          serg Sergei Golubchik made changes -
          Workflow MariaDB v3 [ 64576 ] MariaDB v4 [ 147927 ]

          People

            Unassigned Unassigned
            elenst Elena Stepanova
            Votes:
            0 Vote for this issue
            Watchers:
            2 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.