[MDEV-13242] Wrong results for queries with row constructors and information_schema Created: 2017-07-04  Updated: 2020-08-25  Resolved: 2017-10-05

Status: Closed
Project: MariaDB Server
Component/s: Optimizer
Affects Version/s: 10.1.14, 10.2.7
Fix Version/s: 10.1.29

Type: Bug Priority: Major
Reporter: Valerii Kravchuk Assignee: Alexander Barkov
Resolution: Fixed Votes: 0
Labels: information_schema, upstream

Sprint: 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)



 Comments   
Comment by Alexander Barkov [ 2017-10-04 ]

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'));

Generated at Thu Feb 08 08:04:01 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.