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

Unexpected result of IN operator with prepared SELECT statement

    XMLWordPrintable

Details

    Description

      Hi,

      In the following test case, there are two equivalent queries, one is a normal SELECT and the other is a prepared SELECT. However, these two queries have different results. The normal SELECT returns 0 on all data, but the prepared SELECT returns 1. I believe the prepared statement returns unexpected results as the left operator of IN is not in the t1.c0.

      CREATE TABLE t1(c0 BIGINT UNSIGNED UNIQUE, c1 REAL);
      INSERT INTO t1 VALUES (2077795537, 1654315062);
      INSERT INTO t1 VALUES (0, 1503042352);
      SELECT (- CAST(1096867228 AS DECIMAL)) IN ((SELECT t1.c0 FROM t1 WHERE t1.c1)) FROM t1; 
      -- 0
      -- 0
      SET @a = 1096867228;
      PREPARE prepare_query FROM 'SELECT (- CAST(? AS DECIMAL)) IN ((SELECT t1.c0 FROM t1 WHERE t1.c1)) FROM t1';
      EXECUTE prepare_query USING @a;
      -- 1
      -- 1
      

      If I remove the UNIQUE keyword of t1, the prepared SELECT can return correct result.

      Attachments

        Activity

          People

            psergei Sergei Petrunia
            ChiZhang Chi Zhang
            Votes:
            0 Vote for this issue
            Watchers:
            3 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.