mirror of
https://github.com/aljazceru/turso.git
synced 2026-02-06 00:34:23 +01:00
Merge 'Fix: JOIN USING should pick columns from left table, not right' from Jussi Saurio
Closes #3468 Closes #3479 Closes #3485
This commit is contained in:
@@ -3370,14 +3370,15 @@ pub fn bind_and_rewrite_expr<'a>(
|
||||
id.as_str()
|
||||
);
|
||||
}
|
||||
} else {
|
||||
let col =
|
||||
joined_table.table.columns().get(col_idx.unwrap()).unwrap();
|
||||
match_result = Some((
|
||||
joined_table.internal_id,
|
||||
col_idx.unwrap(),
|
||||
col.is_rowid_alias,
|
||||
));
|
||||
}
|
||||
let col =
|
||||
joined_table.table.columns().get(col_idx.unwrap()).unwrap();
|
||||
match_result = Some((
|
||||
joined_table.internal_id,
|
||||
col_idx.unwrap(),
|
||||
col.is_rowid_alias,
|
||||
));
|
||||
// only if we haven't found a match, check for explicit rowid reference
|
||||
} else if let Some(row_id_expr) = parse_row_id(
|
||||
&normalized_id,
|
||||
|
||||
@@ -362,3 +362,25 @@ do_execsql_test_on_specific_db {:memory:} left-join-where-clause-regression {
|
||||
select t.a, s.a from t left join s on t.a=s.a where s.a = 2;
|
||||
} {2|2
|
||||
2|2}
|
||||
|
||||
# Regression test for: https://github.com/tursodatabase/turso/issues/3468
|
||||
do_execsql_test_on_specific_db {:memory:} left-join-using-star-vs-explicit {
|
||||
create table t(a, tb);
|
||||
create table s(a, sb);
|
||||
insert into t values (1, 't1'), (2, 't2');
|
||||
insert into s values (1, 's1'), (3, 's3');
|
||||
select * from t left join s using(a);
|
||||
select a, tb, sb from t left join s using(a);
|
||||
} {1|t1|s1
|
||||
2|t2|
|
||||
1|t1|s1
|
||||
2|t2|}
|
||||
|
||||
do_execsql_test_on_specific_db {:memory:} left-join-using-null {
|
||||
create table t(a, b);
|
||||
create table s(a, b);
|
||||
insert into t values (1, null), (2, null);
|
||||
insert into s values (1, null), (2, null);
|
||||
select a, b from t left join s using (a, b);
|
||||
} {1|
|
||||
2|}
|
||||
|
||||
Reference in New Issue
Block a user