You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
create table t(a Int64, b Int64) engine = TinyLog;
insert into t values(1,1);
insert into t values(2,2);
create table s(a Int64, b Int64) engine = TinyLog;
insert into s values(1,1);
Right(expected) result: select a, b, s_a, s_b from t all left join (select a,b,a s_a, b s_b from s) using (a,b)
a
b
s_a
s_b
1
1
1
1
2
2
0
0
select a,b,s_a,s_b from t all left join (select a, b, a s_a, b s_b from s) s on (s.a = t.a and s.b = t.b)
a
b
s_a
s_b
1
1
1
1
2
2
0
0
Wrong (unexpected) results
select * from t all left join s using (a,b)
a
b
a
b
1
1
1
1
2
2
2
2
select t.*, s.* from t all left join s on (s.a = t.a and s.b = t.b)
a
b
a
b
a
b
a
b
1
1
1
1
1
1
1
1
2
2
2
2
2
2
2
2
select * from t all left join (select a s_a, b s_b from s) on (s_a = t.a and s_b = t.b)
a
b
s_a
s_b
1
1
1
1
2
2
2
2
select a,b,s_a,s_b from t all left join (select a,b, a s_a, b s_b from s) on (s_a = t.a and s_b = t.b)
changed the title [-]Left outer join requires to rename columns to get right result.[/-][+]Left outer join requires to rename columns to get a correct result.[/+]on Sep 16, 2018
changed the title [-]Left outer join requires to rename columns to get a correct result.[/-][+]Left outer join requires to rename columns to get the correct result.[/+]on Sep 16, 2018
create table t(a Int64, b Int64) engine = TinyLog;
insert into t values(1,1);
insert into t values(2,2);
create table z(c Int64, d Int64, e Int64) engine = TinyLog;
insert into z values(1,1,1);
Wrong result select * from t all left join z on (z.c = t.a and z.d = t.b)
Everything except select t.*, s.* from t all left join s on (s.a = t.a and s.b = t.b) is expected.
You can refer to Backward incompatible changes of 18.12.13 CHANGELOG
I did not mean that something wrong with the last version.
I mean it works and always worked incompatible with other SQL databases.
psql
create table t(a int, b int); insert into t values (1,1); insert into t values (2,2);
create table s(a int, b int);
insert into s values (1,1);
select * from t left outer join s using (a,b);
a | b
---+---
1 | 1
2 | 2
select t.*, s.* from t left outer join s using (a,b);
a | b | a | b
---+---+---+---
1 | 1 | 1 | 1
2 | 2 | |
select * from t left outer join s on t.a=s.a and t.b=s.b;
a | b | a | b
---+---+---+---
1 | 1 | 1 | 1
2 | 2 | |
mysql
create table t(a int, b int); insert into t values (1,1); insert into t values (2,2);
create table s(a int, b int); insert into s values (1,1);
select * from t left outer join s using (a,b);
+------+------+
| a | b |
+------+------+
| 1 | 1 |
| 2 | 2 |
+------+------+
select t.*, s.* from t left outer join s using (a,b);
+------+------+------+------+
| a | b | a | b |
+------+------+------+------+
| 1 | 1 | 1 | 1 |
| 2 | 2 | NULL | NULL |
+------+------+------+------+
select * from t left outer join s on (t.a = s.a and t.b = s.b);
+------+------+------+------+
| a | b | a | b |
+------+------+------+------+
| 1 | 1 | 1 | 1 |
| 2 | 2 | NULL | NULL |
+------+------+------+------+
One more test.
There is a very useful use-case find all rows in T which are "not-exists" in S using semi-join.
mysql
create table t(a int, b int, c varchar(100)); insert into t values (1,1,'a'); insert into t values (2,2,'b');
create table s(a int, b int, c varchar(100)); insert into s values (1,1,'a');
select t.* from t left outer join s on (t.a = s.a and t.b = s.b) where s.a is null and s.b is null;
+------+------+------+
| a | b | c |
+------+------+------+
| 2 | 2 | b |
+------+------+------+
select t.* from t left outer join s using (a,b) where s.a is null and s.b is null;
+------+------+------+
| a | b | c |
+------+------+------+
| 2 | 2 | b |
+------+------+------+
psql
select t.* from t left outer join s on (t.a = s.a and t.b = s.b) where s.a is null and s.b is null;
a | b | c
---+---+---
2 | 2 | b
select t.* from t left outer join s using (a,b) where s.a is null and s.b is null;
a | b | c
---+---+---
2 | 2 | b
CH:
create table t(a Int64, b Int64, c String) engine = TinyLog;
insert into t values(1,1,'a'),(2,2,'b');
create table s(a Int64, b Int64, c String) engine = TinyLog;
insert into s values(1,1,'a');
select t.* from t all left join s on (s.a = t.a and s.b = t.b) where s.a = 0 and s.b = 0;
Received exception from server (version 18.10.3):
Code: 47. DB::Exception: Received from localhost:9000, ::1. DB::Exception: Unknown identifier: default.s.b.
create table z(d Int64, e Int64, f String) engine = TinyLog; insert into z values(1,1,'a');
select a,b,c from (select a,b,c,d,e,f from t all left join z on (z.d = t.a and z.e = t.b)) where d=0 and e=0;
0 rows in set. Elapsed: 0.003 sec.
Am I right that only unsolved issue here is incorrect result with 'join_use_nulls = 1'?
use test;
drop table if exists t;
drop table if exists s;
create table t(a Int64, b Int64) engine = TinyLog;
create table s(a Int64, b Int64) engine = TinyLog;
insert into t values(1,1), (2,2);
insert into s values(1,1);
set join_use_nulls = 0;
select * from t all left join s using (a,b) format PrettyCompact;
select t.*, s.* from t all left join s using (a,b) format PrettyCompact;
select * from t all left join (select a,b,a s_a, b s_b from s) using (a,b) format PrettyCompact;
set join_use_nulls = 1;
select * from t all left join s using (a,b) format PrettyCompact;
select t.*, s.* from t all left join s using (a,b) format PrettyCompact; -- NULLs expected
select * from t all left join (select a,b,a s_a, b s_b from s) using (a,b) format PrettyCompact;
drop table t;
drop table s;
I did typo and got
select * from t left outer join s on (t.a=s.a and t.b = s.a);
DB::Exception: Not found column dw.s.a in block. There are only columns: dw.s.b.
Actually the problem that * with using should not return columns from right table at all.
Current behaviour * with using is return all columns from left and right table except duplicates. It's almost like MySQL workd with using(). So this result (master) is correct: all the columns except duplicates.
create table t(a Nullable(Int64), b Nullable(Int64), c Nullable(String)) engine = Memory;
create table s(a Nullable(Int64), b Nullable(Int64), c Nullable(String)) engine = Memory;
insert into t values(1,1,'a'), (2,2,'b');
insert into s values(1,1,'a');
select * from t all left join (select a,b,a s_a, b s_b from s) using (a,b)
┌─a─┬─b─┬─c─┬──s_a─┬──s_b─┐
│ 1 │ 1 │ a │ 1 │ 1 │
│ 2 │ 2 │ b │ ᴺᵁᴸᴸ │ ᴺᵁᴸᴸ │
└───┴───┴───┴──────┴──────┘
Then if I replace * with t., s. I've got expected NULLs in right table (if a and b are nullables)
select t.*, s.* from t all left join (select a,b,a s_a, b s_b from s) s using (a,b) format PrettyCompact;
┌─a─┬─b─┬─c─┬──s.a─┬──s.b─┬──s_a─┬──s_b─┐
│ 1 │ 1 │ a │ 1 │ 1 │ 1 │ 1 │
│ 2 │ 2 │ b │ ᴺᵁᴸᴸ │ ᴺᵁᴸᴸ │ ᴺᵁᴸᴸ │ ᴺᵁᴸᴸ │
└───┴───┴───┴──────┴──────┴──────┴──────┘
The same with JOIN ON.
select t.*, s.* from t all left join (select a,b,a s_a, b s_b from s) s on t.a = s.a and t.b = s.b format PrettyCompact;
┌─a─┬─b─┬─c─┬──s.a─┬──s.b─┬──s_a─┬──s_b─┐
│ 1 │ 1 │ a │ 1 │ 1 │ 1 │ 1 │
│ 2 │ 2 │ b │ ᴺᵁᴸᴸ │ ᴺᵁᴸᴸ │ ᴺᵁᴸᴸ │ ᴺᵁᴸᴸ │
└───┴───┴───┴──────┴──────┴──────┴──────┘
I did typo and got ... DB::Exception
It's totally another issue. So the issues are:
If join_use_nulls = 1 we have default values instead of NULLs sometimes. (this issue)
changed the title [-]Left outer join requires to rename columns to get the correct result.[/-][+]JOIN return default values when NULLs are expected (join_use_nulls = 1)[/+]on Feb 5, 2019
Activity
[-]Left outer join requires to rename columns to get right result.[/-][+]Left outer join requires to rename columns to get a correct result.[/+][-]Left outer join requires to rename columns to get a correct result.[/-][+]Left outer join requires to rename columns to get the correct result.[/+]den-crane commentedon Sep 16, 2018
Wrong result
select * from t all left join z on (z.c = t.a and z.d = t.b)zhang2014 commentedon Sep 17, 2018
Everything except
select t.*, s.* from t all left join s on (s.a = t.a and s.b = t.b)is expected.You can refer to Backward incompatible changes of 18.12.13 CHANGELOG
den-crane commentedon Sep 17, 2018
I did not mean that something wrong with the last version.
I mean it works and always worked incompatible with other SQL databases.
psql
create table t(a int, b int); insert into t values (1,1); insert into t values (2,2);
create table s(a int, b int);
insert into s values (1,1);
mysql
create table t(a int, b int); insert into t values (1,1); insert into t values (2,2);
create table s(a int, b int); insert into s values (1,1);
zhang2014 commentedon Sep 17, 2018
OK,Two questions, and I'll try to fix that : )
SELECT t.*, s.* FROM t ALL LEFT JOIN s ON (s.a = t.a and s.b = t.b).USING.den-crane commentedon Sep 17, 2018
One more test.
There is a very useful use-case find all rows in T which are "not-exists" in S using semi-join.
mysql
psql
CH:
Join aliases and duplicating columns fixes.
Fixed strange code #3145
Miscellaneous #3145
Miscellaneous #3145
Miscellaneous #3145
Attempt to fix use-after-free, try 1 #3145
Fixed code that was out of style #3145
3 remaining items
4ertus2 commentedon Feb 1, 2019
Am I right that only unsolved issue here is incorrect result with 'join_use_nulls = 1'?
5th query result is wrong. It should be the same as 6th one.
den-crane commentedon Feb 1, 2019
5, 3, 6 have wrong results.
current result
expected result
den-crane commentedon Feb 1, 2019
19.1.6. still wrong with table qualifiers
den-crane commentedon Feb 1, 2019
I think 3d and 6 also wrong and they have 2 issues.
Actually the problem that * with using should not return columns from right table at all.
den-crane commentedon Feb 1, 2019
And let's remove a setting asterisk_left_columns_only
It's broken in master anyway and has no sense.
den-crane commentedon Feb 1, 2019
I did typo and got
select * from t left outer join s on (t.a=s.a and t.b = s.a);
DB::Exception: Not found column dw.s.a in block. There are only columns: dw.s.b.
4ertus2 commentedon Feb 5, 2019
Then if I replace * with t., s. I've got expected NULLs in right table (if a and b are nullables)
The same with JOIN ON.
It's totally another issue. So the issues are:
Are there any other issues here? If so lets make own tickets for them.
[-]Left outer join requires to rename columns to get the correct result.[/-][+]JOIN return default values when NULLs are expected (join_use_nulls = 1)[/+]den-crane commentedon Feb 5, 2019
some examples https://den-crane.github.io/CHvsPG.html
[-]JOIN return default values when NULLs are expected (join_use_nulls = 1)[/-][+]JOIN unexpected results[/+]