Skip to content

Commit

Permalink
Fix search ISE on sparse relations
Browse files Browse the repository at this point in the history
  • Loading branch information
ackwell committed Aug 3, 2024
1 parent bed341b commit 793bd4f
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
5 changes: 5 additions & 0 deletions src/search/sqlite/database.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,11 @@ impl Database {
statement.offset(u64::try_from(offset).context("invalid offset")?);
}

if tracing::enabled!(tracing::Level::TRACE) {
let query_string = statement.to_string(SqliteQueryBuilder);
tracing::trace!(%query_string, "executing query");
}

let (query, values) = statement.build_rusqlite(SqliteQueryBuilder);

let connection = self.pool.get().await?;
Expand Down
7 changes: 3 additions & 4 deletions src/search/sqlite/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,11 @@ fn resolve_query(sheet_name: String, node: post::Node) -> Result<SelectStatement
Error::MalformedQuery(format!("joined sheet {} not referenced", relation.sheet))
})?;

let mut condition = Expr::col(relation.foreign_key)
.equals((base_alias.clone(), KnownColumn::RowId))
.into_condition();
let mut condition = Condition::all()
.add(Expr::col(relation.foreign_key).equals((base_alias.clone(), KnownColumn::RowId)));

if let Some(relation_condition) = relation.condition {
condition = Condition::all().add(condition).add(relation_condition);
condition = condition.add(relation_condition)
}

query.left_join(base_reference, condition);
Expand Down
6 changes: 4 additions & 2 deletions src/search/sqlite/vtable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -242,11 +242,13 @@ unsafe impl vtab::VTabCursor for IronworksTableCursor<'_> {

let iterator = match index_number {
Index::SCAN => Index::Scan(sheet.into_iter()),
Index::ROW_ID => match arguments.get::<Option<u32>>(0)? {
Index::ROW_ID => match arguments.get::<Option<i32>>(0)? {
None => Index::Never,
Some(row_id) if row_id < 0 => Index::Never,
Some(row_id) => Index::RowId(RowIdIndex {
sheet,
row_id,
row_id: u32::try_from(row_id)
.expect("row_id should always be >= 0 due to prior condition"),
subrow_id: 0,
}),
},
Expand Down

0 comments on commit 793bd4f

Please sign in to comment.