[MDEV-15581] Incorrect result (missing row) with UNION DISTINCT in anchor parts Created: 2018-03-16  Updated: 2018-05-18  Resolved: 2018-05-18

Status: Closed
Project: MariaDB Server
Component/s: Optimizer - CTE
Affects Version/s: 10.2
Fix Version/s: 10.2.16

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

Issue Links:
Relates
relates to MDEV-15447 Import CTE tests from MySQL 8 Stalled

 Description   

 
create table t1(a int);
insert into t1 values(1),(2);
insert into t1 values(1),(2);
 
set @c=0, @d=0;
WITH RECURSIVE qn AS
(
select 1,0 as col from t1
union distinct
select 1,0 from t1
union all
select 3, 0*(@c:=@c+1) from qn where @c<1
union all
select 3, 0*(@d:=@d+1) from qn where @d<1
)
select * from qn;

MariaDB [test]> create table t1(a int);
Query OK, 0 rows affected (0.35 sec)
 
MariaDB [test]> insert into t1 values(1),(2);
Query OK, 2 rows affected (0.15 sec)
Records: 2  Duplicates: 0  Warnings: 0
 
MariaDB [test]> insert into t1 values(1),(2);
Query OK, 2 rows affected (0.06 sec)
Records: 2  Duplicates: 0  Warnings: 0
 
MariaDB [test]> set @c=0, @d=0;
Query OK, 0 rows affected (0.00 sec)
 
MariaDB [test]> WITH RECURSIVE qn AS
    -> (
    -> select 1,0 as col from t1
    -> union distinct
    -> select 1,0 from t1
    -> union all
    -> select 3, 0*(@c:=@c+1) from qn where @c<1
    -> union all
    -> select 3, 0*(@d:=@d+1) from qn where @d<1
    -> )
    -> select * from qn;
+---+-----+
| 1 | col |
+---+-----+
| 1 |   0 |
| 3 |   0 |
+---+-----+
2 rows in set (0.00 sec)
 
MariaDB [test]> select 1,0 as col from t1         # expected result
    -> union distinct
    -> select 1,0 from t1
    -> union all
    -> select 3, 0 
    -> union all
    -> select 3, 0;
+---+-----+
| 1 | col |
+---+-----+
| 1 |   0 |
| 3 |   0 |
| 3 |   0 |
+---+-----+
3 rows in set (0.00 sec)



 Comments   
Comment by Igor Babaev [ 2018-05-18 ]

A fix for this bug was pushed into 10.2

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