diff --git a/core/translate/optimizer/mod.rs b/core/translate/optimizer/mod.rs index a054bac3e..adc137389 100644 --- a/core/translate/optimizer/mod.rs +++ b/core/translate/optimizer/mod.rs @@ -6,7 +6,10 @@ use constraints::{ use cost::Cost; use join::{compute_best_join_order, BestJoinOrderResult}; use lift_common_subexpressions::lift_common_subexpressions_from_binary_or_terms; -use limbo_sqlite3_parser::ast::{self, Expr, SortOrder}; +use limbo_sqlite3_parser::{ + ast::{self, Expr, SortOrder}, + to_sql_string::ToSqlString as _, +}; use order::{compute_order_target, plan_satisfies_order_target, EliminatesSort}; use crate::{ @@ -45,6 +48,8 @@ pub fn optimize_plan(plan: &mut Plan, schema: &Schema) -> Result<()> { } } } + // When debug tracing is enabled, print the optimized plan as a SQL string for debugging + tracing::debug!(plan_sql = plan.to_sql_string(&crate::translate::display::PlanContext(&[]))); Ok(()) } diff --git a/vendored/sqlite3-parser/src/to_sql_string/expr.rs b/vendored/sqlite3-parser/src/to_sql_string/expr.rs index 0b9278b41..7727543da 100644 --- a/vendored/sqlite3-parser/src/to_sql_string/expr.rs +++ b/vendored/sqlite3-parser/src/to_sql_string/expr.rs @@ -146,11 +146,9 @@ impl ToSqlString for Expr { ret.push('.'); ret.push_str(context.get_column_name(*table, *column)); } - // TODO: not sure how to rewrite this - Expr::RowId { - database: _, - table: _, - } => todo!(), + Expr::RowId { database: _, table } => { + ret.push_str(&format!("{}.rowid", context.get_table_name(*table))) + } Expr::InList { lhs, not, rhs } => { ret.push_str(&format!( "{} {}IN ({})",