[MDEV-30708] The query result is incorrect when querying multiple tables Created: 2023-02-22  Updated: 2023-11-28

Status: Confirmed
Project: MariaDB Server
Component/s: None
Affects Version/s: 10.5.16, 10.4, 10.5, 10.6, 10.7, 10.8, 10.9, 10.10, 10.11, 11.0
Fix Version/s: 10.4, 10.5, 10.6, 10.11

Type: Bug Priority: Major
Reporter: guozhentang Assignee: Sergei Petrunia
Resolution: Unresolved Votes: 0
Labels: None
Environment:

centos 7.6


Attachments: PNG File image-2023-02-22-20-18-44-485.png     File sql_file.rar    

 Description   

Step 1: Create a table and insert data
1.Create database sqltester
create database sqltester
2.Execute the attachment file to create a table and insert data
source sqltester_for_parallel_with_index.2k_dp_210col.index_desc.sql
3.Execute the attachment file to create a table and insert data
source sqltester_for_parallel_with_index_view_part_tab.sql
Step 2: Execute the query

select
  ref_0.tinytext_col as c0
from 
  sqltester.alltypecol_t1 as ref_0
where (EXISTS (
    select          
          count(
            18) over (partition by ref_1.c0 order by ref_0.longtext_col) as c2
      from 
        sqltester_1.tx_cmplx_005 as ref_1
      where (EXISTS (
          select  
              ref_0.mediumint_col as c2
            from 
              sqltester.tx_cmplx_004 as ref_2
                  inner join sqltester.t0_sub_1 as ref_3
                  on (false)
                inner join sqltester_1.t12 as ref_5
                on (false)
            where (false)
            )) 
        and (EXISTS (
              select  
                  ref_0.double_col as c1
                from 
                  sqltester.t5 as ref_8
                where false
                ))
      ))
group by 1
order by 1 desc;

The expected result is empty, but the actual result is not empty



 Comments   
Comment by Alice Sherepa [ 2023-03-29 ]

Thank you for the report!
I repeated on MariaDB 10.4-10.11:

create table t1 (a int);
insert into t1 values (1),(2),(3);
 
SELECT a FROM t1 WHERE EXISTS ( SELECT count(*) over () FROM (select 1)dt WHERE  (EXISTS ( SELECT t1.a FROM (select 1)f WHERE 0 )) );

MariaDB [sqltester]> create table t1 (a int);
Query OK, 0 rows affected (0,031 sec)
 
MariaDB [sqltester]> insert into t1 values (1),(2),(3);
Query OK, 3 rows affected (0,002 sec)
Records: 3  Duplicates: 0  Warnings: 0
 
MariaDB [sqltester]> SELECT a FROM t1 WHERE EXISTS ( SELECT count(*) over () FROM (select 1)dt WHERE  (EXISTS ( SELECT t1.a FROM (select 1)f WHERE 0 )) );
+------+
| a    |
+------+
|    1 |
|    2 |
|    3 |
+------+
3 rows in set (0,002 sec)
 
MariaDB [sqltester]> SELECT count(*) over () FROM (select 1)dt where 0;
Empty set (0,000 sec)
 
MariaDB [sqltester]> explain extended SELECT a FROM t1 WHERE EXISTS ( SELECT count(*) over () FROM (select 1)dt WHERE  (EXISTS ( SELECT t1.a FROM (select 1)f WHERE 0 )) );
+------+--------------------+------------+--------+---------------+------+---------+------+------+----------+------------------+
| id   | select_type        | table      | type   | possible_keys | key  | key_len | ref  | rows | filtered | Extra            |
+------+--------------------+------------+--------+---------------+------+---------+------+------+----------+------------------+
|    1 | PRIMARY            | t1         | ALL    | NULL          | NULL | NULL    | NULL | 3    |   100.00 | Using where      |
|    2 | DEPENDENT SUBQUERY | <derived3> | system | NULL          | NULL | NULL    | NULL | 1    |   100.00 | Using temporary  |
|    4 | DEPENDENT SUBQUERY | NULL       | NULL   | NULL          | NULL | NULL    | NULL | NULL |     NULL | Impossible WHERE |
|    5 | DERIVED            | NULL       | NULL   | NULL          | NULL | NULL    | NULL | NULL |     NULL | No tables used   |
|    3 | DERIVED            | NULL       | NULL   | NULL          | NULL | NULL    | NULL | NULL |     NULL | No tables used   |
+------+--------------------+------------+--------+---------------+------+---------+------+------+----------+------------------+
5 rows in set, 2 warnings (0,001 sec)
 
Note (Code 1276): Field or reference 'sqltester.t1.a' of SELECT #4 was resolved in SELECT #1
Note (Code 1003): /* select#1 */ select `sqltester`.`t1`.`a` AS `a` from `sqltester`.`t1` where <in_optimizer>(1,<expr_cache><`sqltester`.`t1`.`a`>(exists(/* select#2 */ select count(0) over () from dual where <in_optimizer>(1,<expr_cache><`sqltester`.`t1`.`a`>(exists(/* select#4 */ select `sqltester`.`t1`.`a` from (/* select#5 */ select 1 AS `1`) `f` where 0 limit 1))) limit 1)))

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