Skip to content

Commit

Permalink
fix(tianmu): fix UNION of non-matching columns (column no 0)
Browse files Browse the repository at this point in the history
  • Loading branch information
adofsauron authored and mergify[bot] committed Jun 15, 2023
1 parent 6b369e5 commit f180323
Show file tree
Hide file tree
Showing 9 changed files with 386 additions and 14 deletions.
144 changes: 144 additions & 0 deletions mysql-test/suite/tianmu/r/issue1784.result
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
DROP DATABASE IF EXISTS issue1784_test;
CREATE DATABASE issue1784_test;
USE issue1784_test;
create table t1 (age int) engine=tianmu;
select * from t1;
age
select age from t1;
age
select age, sum(age) from t1 group by age;
age sum(age)
select age, sum(age) from (select * from t1) ta group by age;
age sum(age)
select case when age is not null then age else 33 end, sum(age) from t1 group by age;
case when age is not null then age else 33 end sum(age)
select case when age is not null then age else 33 end, sum(age) from (select * from t1) ta group by age;
case when age is not null then age else 33 end sum(age)
insert into t1 values(1);
select * from t1;
age
1
select age from t1;
age
1
select age, sum(age) from t1 group by age;
age sum(age)
1 1
select age, sum(age) from (select * from t1) ta group by age;
age sum(age)
1 1
select case when age is not null then age else 33 end, sum(age) from t1 group by age;
case when age is not null then age else 33 end sum(age)
1 1
select case when age is not null then age else 33 end, sum(age) from (select * from t1) ta group by age;
case when age is not null then age else 33 end sum(age)
1 1
drop table t1;
create table t1 (age int) engine=innodb;
select * from t1;
age
select age from t1;
age
select age, sum(age) from t1 group by age;
age sum(age)
select age, sum(age) from (select * from t1) ta group by age;
age sum(age)
select case when age is not null then age else 33 end, sum(age) from t1 group by age;
case when age is not null then age else 33 end sum(age)
select case when age is not null then age else 33 end, sum(age) from (select * from t1) ta group by age;
case when age is not null then age else 33 end sum(age)
insert into t1 values(1);
select * from t1;
age
1
select age from t1;
age
1
select age, sum(age) from t1 group by age;
age sum(age)
1 1
select age, sum(age) from (select * from t1) ta group by age;
age sum(age)
1 1
select case when age is not null then age else 33 end, sum(age) from t1 group by age;
case when age is not null then age else 33 end sum(age)
1 1
select case when age is not null then age else 33 end, sum(age) from (select * from t1) ta group by age;
case when age is not null then age else 33 end sum(age)
1 1
drop table t1;
SET sql_mode='STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION';
create table t1 (age int) engine=tianmu;
select * from t1;
age
select age from t1;
age
select age, sum(age) from t1;
age sum(age)
NULL NULL
select age, sum(age) from (select * from t1) ta;
age sum(age)
NULL NULL
select case when age is not null then age else 33 end, sum(age) from t1;
case when age is not null then age else 33 end sum(age)
33 NULL
select case when age is not null then age else 33 end, sum(age) from (select * from t1) ta;
case when age is not null then age else 33 end sum(age)
33 NULL
insert into t1 values(1);
select * from t1;
age
1
select age from t1;
age
1
select age, sum(age) from t1;
age sum(age)
1 1
select age, sum(age) from (select * from t1) ta;
age sum(age)
1 1
select case when age is not null then age else 33 end, sum(age) from t1;
case when age is not null then age else 33 end sum(age)
1 1
select case when age is not null then age else 33 end, sum(age) from (select * from t1) ta;
case when age is not null then age else 33 end sum(age)
1 1
drop table t1;
create table t1 (age int) engine=innodb;
select * from t1;
age
select age from t1;
age
select age, sum(age) from t1;
age sum(age)
NULL NULL
select age, sum(age) from (select * from t1) ta;
age sum(age)
NULL NULL
select case when age is not null then age else 33 end, sum(age) from t1;
case when age is not null then age else 33 end sum(age)
33 NULL
select case when age is not null then age else 33 end, sum(age) from (select * from t1) ta;
case when age is not null then age else 33 end sum(age)
33 NULL
insert into t1 values(1);
select * from t1;
age
1
select age from t1;
age
1
select age, sum(age) from t1;
age sum(age)
1 1
select age, sum(age) from (select * from t1) ta;
age sum(age)
1 1
select case when age is not null then age else 33 end, sum(age) from t1;
case when age is not null then age else 33 end sum(age)
1 1
select case when age is not null then age else 33 end, sum(age) from (select * from t1) ta;
case when age is not null then age else 33 end sum(age)
1 1
DROP DATABASE issue1784_test;
32 changes: 32 additions & 0 deletions mysql-test/suite/tianmu/r/issue1864.result
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
DROP DATABASE IF EXISTS issue1864_test;
CREATE DATABASE issue1864_test;
USE issue1864_test;
create table t1(c1 decimal(5,2)) engine=tianmu;
insert into t1 values(111.22);
create table t2(id int) engine=tianmu;
insert into t2 values(11122);
select xxx.x from (select c1 as x from t1 union all select 1 as x from t2) xxx;
x
111.22
1.00
select xxx.x from ( select t1.c1 as x from t1 inner join t2 on t1.c1 != t2.id ) xxx;
x
111.22
CREATE TABLE cs1 (d1 DECIMAL(17), d2 DECIMAL(17,10), d3 DECIMAL(17,17)) engine=tianmu;
INSERT INTO cs1 VALUES (125, 1.25, 0.125);
INSERT INTO cs1 VALUES (-125, -1.25, -0.125);
select * from cs1;
d1 d2 d3
125 1.2500000000 0.12500000000000000
-125 -1.2500000000 -0.12500000000000000
select * from cs1 union select * from cs1;
d1 d2 d3
125 1.2500000000 0.12500000000000000
-125 -1.2500000000 -0.12500000000000000
SELECT d1, d1, d2 FROM cs1 UNION SELECT d2, d3, d3 FROM cs1;
d1 d1 d2
125.0000000000 -59.46744073709551616 1.25000000000000000
-125.0000000000 59.46744073709551616 -1.25000000000000000
1.2500000000 0.12500000000000000 0.12500000000000000
-1.2500000000 -0.12500000000000000 -0.12500000000000000
DROP DATABASE issue1864_test;
6 changes: 3 additions & 3 deletions mysql-test/suite/tianmu/r/various_join.result
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,14 @@ select * from t1 inner join t2 on (t1.a = t2.a) right join t3 on (t1.a = t3.a an
a b a b a b
NULL NULL NULL NULL 3 4
NULL NULL NULL NULL 4 5
NULL NULL NULL NULL 1 2
NULL NULL NULL NULL 2 3
NULL NULL NULL NULL 1 2
select * from t1 inner join t2 on (t1.a = t2.a) right join t3 on (t1.a = t3.a and t2.b = t3.b and t3.a > t2.a and t3.a > t1.a);
a b a b a b
NULL NULL NULL NULL 3 4
NULL NULL NULL NULL 4 5
NULL NULL NULL NULL 1 2
NULL NULL NULL NULL 2 3
NULL NULL NULL NULL 1 2
select * from t1 inner join t2 on (t1.a = t2.a) right join t3 on (t1.a = t3.a and t2.b = t3.b and t3.b > t2.a and t3.a < t1.b);
a b a b a b
1 3 1 2 1 2
Expand All @@ -86,8 +86,8 @@ select * from t1 inner join t2 on (t1.a = t2.a) right join t3 on (t1.a = t3.a) l
a b a b a b a b
1 3 1 2 1 2 1 3
2 3 2 4 2 3 NULL NULL
NULL NULL NULL NULL 3 4 NULL NULL
NULL NULL NULL NULL 4 5 NULL NULL
NULL NULL NULL NULL 3 4 NULL NULL
select * from t1 inner join t2 on (t1.a = t2.a) right join t3 on (t1.a = t3.a) right join t4 on (t3.a = t4.a and t1.a = t4.a and t2.a = t4.a);
a b a b a b a b
1 3 1 2 1 2 1 3
Expand Down
158 changes: 158 additions & 0 deletions mysql-test/suite/tianmu/t/issue1784.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
--source include/have_tianmu.inc

--disable_warnings
DROP DATABASE IF EXISTS issue1784_test;

CREATE DATABASE issue1784_test;

USE issue1784_test;

### tianmu

## no value

create table t1 (age int) engine=tianmu;

select * from t1;

select age from t1;

select age, sum(age) from t1 group by age;

select age, sum(age) from (select * from t1) ta group by age;

select case when age is not null then age else 33 end, sum(age) from t1 group by age;

select case when age is not null then age else 33 end, sum(age) from (select * from t1) ta group by age;

## has value

insert into t1 values(1);

select * from t1;

select age from t1;

select age, sum(age) from t1 group by age;

select age, sum(age) from (select * from t1) ta group by age;

select case when age is not null then age else 33 end, sum(age) from t1 group by age;

select case when age is not null then age else 33 end, sum(age) from (select * from t1) ta group by age;

### innodb

## no value

drop table t1;

create table t1 (age int) engine=innodb;

select * from t1;

select age from t1;

select age, sum(age) from t1 group by age;

select age, sum(age) from (select * from t1) ta group by age;

select case when age is not null then age else 33 end, sum(age) from t1 group by age;

select case when age is not null then age else 33 end, sum(age) from (select * from t1) ta group by age;

## has value

insert into t1 values(1);

select * from t1;

select age from t1;

select age, sum(age) from t1 group by age;

select age, sum(age) from (select * from t1) ta group by age;

select case when age is not null then age else 33 end, sum(age) from t1 group by age;

select case when age is not null then age else 33 end, sum(age) from (select * from t1) ta group by age;

####

drop table t1;

SET sql_mode='STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION';

### tianmu

## no value

create table t1 (age int) engine=tianmu;

select * from t1;

select age from t1;

select age, sum(age) from t1;

select age, sum(age) from (select * from t1) ta;

select case when age is not null then age else 33 end, sum(age) from t1;

select case when age is not null then age else 33 end, sum(age) from (select * from t1) ta;

## has value

insert into t1 values(1);

select * from t1;

select age from t1;

select age, sum(age) from t1;

select age, sum(age) from (select * from t1) ta;

select case when age is not null then age else 33 end, sum(age) from t1;

select case when age is not null then age else 33 end, sum(age) from (select * from t1) ta;

### innodb

## no value

drop table t1;

create table t1 (age int) engine=innodb;

select * from t1;

select age from t1;

select age, sum(age) from t1;

select age, sum(age) from (select * from t1) ta;

select case when age is not null then age else 33 end, sum(age) from t1;

select case when age is not null then age else 33 end, sum(age) from (select * from t1) ta;

## has value

insert into t1 values(1);

select * from t1;

select age from t1;

select age, sum(age) from t1;

select age, sum(age) from (select * from t1) ta;

select case when age is not null then age else 33 end, sum(age) from t1;

select case when age is not null then age else 33 end, sum(age) from (select * from t1) ta;

## clean test database

DROP DATABASE issue1784_test;
32 changes: 32 additions & 0 deletions mysql-test/suite/tianmu/t/issue1864.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
--source include/have_tianmu.inc

--disable_warnings
DROP DATABASE IF EXISTS issue1864_test;

CREATE DATABASE issue1864_test;

USE issue1864_test;

create table t1(c1 decimal(5,2)) engine=tianmu;
insert into t1 values(111.22);

create table t2(id int) engine=tianmu;
insert into t2 values(11122);

select xxx.x from (select c1 as x from t1 union all select 1 as x from t2) xxx;

select xxx.x from ( select t1.c1 as x from t1 inner join t2 on t1.c1 != t2.id ) xxx;

CREATE TABLE cs1 (d1 DECIMAL(17), d2 DECIMAL(17,10), d3 DECIMAL(17,17)) engine=tianmu;

INSERT INTO cs1 VALUES (125, 1.25, 0.125);

INSERT INTO cs1 VALUES (-125, -1.25, -0.125);

select * from cs1;

select * from cs1 union select * from cs1;

SELECT d1, d1, d2 FROM cs1 UNION SELECT d2, d3, d3 FROM cs1;

DROP DATABASE issue1864_test;
Loading

0 comments on commit f180323

Please sign in to comment.