Skip to content

Commit

Permalink
sqld: use unexpanded SQL for top queries
Browse files Browse the repository at this point in the history
... so that we don't distinguish between different bound values
when tracking queries, and instead only gather information
about the raw query string that may contain wildcards, like:
 INSERT INTO t VALUES (?, ?, ?);
  • Loading branch information
psarna committed Oct 23, 2023
1 parent 4fcddf8 commit b375291
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions libsql-server/src/connection/libsql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -606,7 +606,7 @@ impl<W: WalHook> Connection<W> {

drop(qresult);

self.update_stats(&stmt);
self.update_stats(query.stmt.stmt.clone(), &stmt);

Ok((affected_row_count, last_insert_rowid))
}
Expand Down Expand Up @@ -640,7 +640,7 @@ impl<W: WalHook> Connection<W> {
Ok(())
}

fn update_stats(&self, stmt: &rusqlite::Statement) {
fn update_stats(&self, sql: String, stmt: &rusqlite::Statement) {
let rows_read = stmt.get_status(StatementStatus::RowsRead);
let rows_written = stmt.get_status(StatementStatus::RowsWritten);
let rows_read = if rows_read == 0 && rows_written == 0 {
Expand All @@ -652,9 +652,8 @@ impl<W: WalHook> Connection<W> {
self.stats.inc_rows_written(rows_written as u64);
let weight = (rows_read + rows_written) as i64;
if self.stats.qualifies_as_top_query(weight) {
let query = stmt.expanded_sql().unwrap_or("<unknown>".into());
self.stats
.add_top_query(crate::stats::TopQuery::new(query, rows_read, rows_written));
.add_top_query(crate::stats::TopQuery::new(sql, rows_read, rows_written));
}
}

Expand Down

0 comments on commit b375291

Please sign in to comment.