Merge 'translate/select: Fix rewriting Rowid expression when no btree table exists in joined table refs ' from Preston Thorpe

closes https://github.com/tursodatabase/turso/issues/3667

Reviewed-by: Jussi Saurio <jussi.saurio@gmail.com>

Closes #3754
This commit is contained in:
Preston Thorpe
2025-10-16 14:22:51 -04:00
committed by GitHub
2 changed files with 26 additions and 9 deletions

View File

@@ -3495,14 +3495,18 @@ pub fn bind_and_rewrite_expr<'a>(
));
}
// 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,
referenced_tables.joined_tables()[0].internal_id,
|| referenced_tables.joined_tables().len() != 1,
)? {
*expr = row_id_expr;
return Ok(WalkControl::Continue);
} else {
let is_btree_table = matches!(joined_table.table, Table::BTree(_));
if is_btree_table {
if let Some(row_id_expr) = parse_row_id(
&normalized_id,
referenced_tables.joined_tables()[0].internal_id,
|| referenced_tables.joined_tables().len() != 1,
)? {
*expr = row_id_expr;
return Ok(WalkControl::Continue);
}
}
}
}

View File

@@ -1060,4 +1060,17 @@ do_execsql_test_in_memory_any_error limit-column-reference-error {
do_execsql_test select-binary-collation {
SELECT 'a' = 'A';
SELECT 'a' = 'a';
} {0 1}
} {0 1}
# https://github.com/tursodatabase/turso/issues/3667 regression test
do_execsql_test_in_memory_error_content rowid-select-from-clause-subquery {
CREATE TABLE t(a);
SELECT rowid FROM (SELECT * FROM t);
} {"no such column: rowid"}
do_execsql_test_on_specific_db {:memory:} rowid-select-from-clause-subquery-explicit-works {
CREATE TABLE t(a);
INSERT INTO t values ('abc');
SELECT rowid,a FROM (SELECT rowid,a FROM t);
} {1|abc}