[MDEV-24242] Query returns wrong result while using big_tables=1; Created: 2020-11-18  Updated: 2020-12-01  Resolved: 2020-11-28

Status: Closed
Project: MariaDB Server
Component/s: Optimizer
Affects Version/s: 10.5
Fix Version/s: 10.5.9

Type: Bug Priority: Major
Reporter: Alice Sherepa Assignee: Igor Babaev
Resolution: Fixed Votes: 0
Labels: None

Issue Links:
Relates
relates to MDEV-18844 Implement EXCEPT ALL and INTERSECT AL... Closed

 Description   

test case is a part of the set_operation.test:

create table t1 (a int, b int) engine=MyISAM;
create table t2 (c int, d int) engine=MyISAM;
create table t3 (e int, f int) engine=MyISAM;
create table t4 (g int, h int) engine=MyISAM;
insert into t1 values (1,1),(2,2),(3,3),(2,2),(3,3);
insert into t2 values (2,2),(3,3),(5,5),(2,2),(2,2),(3,3);
insert into t3 values (4,4),(2,2),(2,2),(1,1),(3,3);
insert into t4 values (3,3),(3,3);
 
let $q=
    select * from t1
    INTERSECT ALL
    select * from t2
    UNION ALL
    select * from t3
    EXCEPT ALL
    select * from t1
    UNION
    select * from t4
    EXCEPT
    select * from t3
    UNION ALL
    select * from t1;
 
eval $q;
 
set big_tables=1;
 
eval $q;

MariaDB [test1]> select * from t1
    ->     INTERSECT ALL
    ->     select * from t2
    ->     UNION ALL
    ->     select * from t3
    ->     EXCEPT ALL
    ->     select * from t1
    ->     UNION
    ->     select * from t4
    ->     EXCEPT
    ->     select * from t3
    ->     UNION ALL
    ->     select * from t1;
+------+------+
| a    | b    |
+------+------+
|    2 |    2 |
|    2 |    2 |
|    1 |    1 |
|    3 |    3 |
|    3 |    3 |
+------+------+
5 rows in set (0.009 sec)
 
MariaDB [test1]> set big_tables=1;
Query OK, 0 rows affected, 1 warning (0.001 sec)
 
MariaDB [test1]>     select * from t1
    ->     INTERSECT ALL
    ->     select * from t2
    ->     UNION ALL
    ->     select * from t3
    ->     EXCEPT ALL
    ->     select * from t1
    ->     UNION
    ->     select * from t4
    ->     EXCEPT
    ->     select * from t3
    ->     UNION ALL
    ->     select * from t1;
Empty set (0.013 sec)
 
MariaDB [test1]>  select * from t1     INTERSECT ALL     select * from t2     UNION ALL     select * from t3     EXCEPT ALL     select * from t1     UNION     select * from t4     EXCEPT     select * from t3     UNION    (select * from t1);
+------+------+
| a    | b    |
+------+------+
|    2 |    2 |
|    1 |    1 |
|    3 |    3 |
+------+------+
3 rows in set (0.013 sec)
 
MariaDB [test1]>  select * from t1     INTERSECT ALL     select * from t2     UNION ALL     select * from t3     EXCEPT ALL     select * from t1     UNION     select * from t4     EXCEPT     select * from t3     UNION  all  (select * from t1);
Empty set (0.007 sec)



 Comments   
Comment by Igor Babaev [ 2020-11-19 ]

A simpler test case:

create table t1 (a int, b int) engine=MyISAM;
insert into t1 values (1,1), (2,2);
set big_tables=0;
select * from t1 except all select * from t1 except select * from t1 union all select * from t1;
set  big_tables=1;
select * from t1 except all select * from t1 except select * from t1 union all select * from t1;

For this test case we have:

MariaDB [test]> set big_tables=0;
Query OK, 0 rows affected, 1 warning (0.000 sec)
 
MariaDB [test]> select * from t1 except all select * from t1 except select * from t1 union all select * from t1;
+------+------+
| a    | b    |
+------+------+
|    2 |    2 |
|    1 |    1 |
+------+------+
2 rows in set (0.001 sec)
 
MariaDB [test]> set  big_tables=1;
Query OK, 0 rows affected, 1 warning (0.000 sec)
 
MariaDB [test]> select * from t1 except all select * from t1 except select * from t1 union all select * from t1;
Empty set (0.002 sec)

Comment by Oleksandr Byelkin [ 2020-11-27 ]

OK to push

Comment by Igor Babaev [ 2020-11-28 ]

A fix for this bug was pushed into 10.5.

Generated at Thu Feb 08 09:28:30 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.