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

Wrong results for queries with row constructors and information_schema

Details

    • 10.2.10

    Description

      Basically, MariaDB is affected by the upstream https://bugs.mysql.com/bug.php?id=86930, but our case is even worse, as a workaround with subquery does not work:

      openxs@ao756:~/dbs/maria10.2$ bin/mysql --host=127.0.0.1 --port=3308 -uroot testReading table information for completion of table and column names
      You can turn off this feature to get a quicker startup with -A
       
      Welcome to the MariaDB monitor.  Commands end with ; or \g.
      Your MariaDB connection id is 8
      Server version: 10.2.7-MariaDB Source distribution
       
      Copyright (c) 2000, 2017, Oracle, MariaDB Corporation Ab and others.
       
      Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
       
      MariaDB [test]> create table tt1(c1 int);
      Query OK, 0 rows affected (0.31 sec)
       
      MariaDB [test]> create table tt2(c2 int);
      Query OK, 0 rows affected (0.22 sec)
       
      MariaDB [test]> select count(*) from information_schema.columns where table_schema='test' and (table_name, column_name) in (('tt1', 'c1'));
      +----------+
      | count(*) |
      +----------+
      |        1 |
      +----------+
      1 row in set (0.04 sec)
       
      MariaDB [test]> select count(*) from information_schema.columns where table_schema='test' and (table_name, column_name) in (('tt2', 'c2'));
      +----------+
      | count(*) |
      +----------+
      |        1 |
      +----------+
      1 row in set (0.00 sec)
       
      MariaDB [test]> select count(*) from information_schema.columns where table_schema='test' and (table_name, column_name) in (('tt1','c1'),('tt2', 'c2'));
      +----------+
      | count(*) |
      +----------+
      |        0 |
      +----------+
      1 row in set (0.01 sec)
       
      MariaDB [test]> select count(*) from information_schema.columns where table_schema='test' and (table_name, column_name) in (select 'tt1','c1' from dual union select 'tt2', 'c2' from dual);
      +----------+
      | count(*) |
      +----------+
      |        0 |
      +----------+
      1 row in set (0.02 sec)
       
      MariaDB [test]> select count(*) from information_schema.columns where table_schema='test' and (table_name='tt1' and column_name='c1') or (table_name='tt2' and column_name='c2');
      +----------+
      | count(*) |
      +----------+
      |        2 |
      +----------+
      1 row in set (0.00 sec)
      

      Attachments

        Activity

          valerii Valerii Kravchuk created issue -
          valerii Valerii Kravchuk made changes -
          Field Original Value New Value
          Status Open [ 1 ] Confirmed [ 10101 ]
          serg Sergei Golubchik made changes -
          Fix Version/s 10.1 [ 16100 ]
          serg Sergei Golubchik made changes -
          Fix Version/s 10.2 [ 14601 ]
          julien.fritsch Julien Fritsch made changes -
          Comment [ A comment with security level 'Developers' was removed. ]
          serg Sergei Golubchik made changes -
          serg Sergei Golubchik made changes -
          Assignee Alexander Barkov [ bar ]
          serg Sergei Golubchik made changes -
          Sprint 10.2.10 [ 183 ]
          bar Alexander Barkov added a comment - - edited

          If I remove the table_schema='test' part from the condition:

          select * from information_schema.columns where (table_name, column_name) in (('tt1','c1'),('tt2', 'c2'));
          

          It still returns empty set.

          If I rewrite the query as follows:

          SELECT table_name, column_name, table_schema='test' AND (table_name, column_name) IN (('tt1','c1'),('tt2', 'c2')) as `IN` FROM INFORMATION_SCHEMA.COLUMNS HAVING `IN`;
          

          it correctly returns this result:

          +------------+-------------+----+
          | table_name | column_name | IN |
          +------------+-------------+----+
          | tt1        | c1          |  1 |
          | tt2        | c2          |  1 |
          +------------+-------------+----+
          

          If I copy the data into a "normal" table, it works as expected:

          CREATE OR REPLACE TABLE t1 AS SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE table_schema='test';
          select count(*) from t1 where table_schema='test' and (table_name, column_name) in (('tt1','c1'),('tt2', 'c2'));
          

          +----------+
          | count(*) |
          +----------+
          |        2 |
          +----------+
          

          and this query returns two rows:

          select * from t1 where table_schema='test' and (table_name, column_name) in (('tt1','c1'),('tt2', 'c2'));
          

          bar Alexander Barkov added a comment - - edited If I remove the table_schema='test' part from the condition: select * from information_schema.columns where (table_name, column_name) in (( 'tt1' , 'c1' ),( 'tt2' , 'c2' )); It still returns empty set. If I rewrite the query as follows: SELECT table_name, column_name, table_schema= 'test' AND (table_name, column_name) IN (( 'tt1' , 'c1' ),( 'tt2' , 'c2' )) as ` IN ` FROM INFORMATION_SCHEMA.COLUMNS HAVING ` IN `; it correctly returns this result: +------------+-------------+----+ | table_name | column_name | IN | +------------+-------------+----+ | tt1 | c1 | 1 | | tt2 | c2 | 1 | +------------+-------------+----+ If I copy the data into a "normal" table, it works as expected: CREATE OR REPLACE TABLE t1 AS SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE table_schema= 'test' ; select count (*) from t1 where table_schema= 'test' and (table_name, column_name) in (( 'tt1' , 'c1' ),( 'tt2' , 'c2' )); +----------+ | count(*) | +----------+ | 2 | +----------+ and this query returns two rows: select * from t1 where table_schema= 'test' and (table_name, column_name) in (( 'tt1' , 'c1' ),( 'tt2' , 'c2' ));
          bar Alexander Barkov made changes -
          Status Confirmed [ 10101 ] In Progress [ 3 ]
          bar Alexander Barkov made changes -
          issue.field.resolutiondate 2017-10-05 09:42:52.0 2017-10-05 09:42:52.237
          bar Alexander Barkov made changes -
          Fix Version/s 10.1.29 [ 22636 ]
          Fix Version/s 10.2 [ 14601 ]
          Fix Version/s 10.1 [ 16100 ]
          Resolution Fixed [ 1 ]
          Status In Progress [ 3 ] Closed [ 6 ]
          serg Sergei Golubchik made changes -
          Workflow MariaDB v3 [ 81552 ] MariaDB v4 [ 152434 ]
          mariadb-jira-automation Jira Automation (IT) made changes -
          Zendesk Related Tickets 123469

          People

            bar Alexander Barkov
            valerii Valerii Kravchuk
            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.