Skip to content

Commit 6c511d0

Browse files
committed
Only load the column names for queries executed by Connection::load()
We don't need to have column names for statements where we will only receive the number of affected rows. This should hopefully remove the performance impact of the previous fix for insert statements
1 parent 6576b08 commit 6c511d0

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

diesel/src/sqlite/connection/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ impl Connection for SqliteConnection {
8383
Self::Backend: QueryMetadata<T::SqlType>,
8484
{
8585
let mut statement = self.prepare_query(&source.as_query())?;
86-
let statement_use = StatementUse::new(&mut statement);
86+
let statement_use = StatementUse::new(&mut statement, true);
8787
let iter = StatementIterator::new(statement_use);
8888
iter.collect()
8989
}
@@ -94,7 +94,7 @@ impl Connection for SqliteConnection {
9494
T: QueryFragment<Self::Backend> + QueryId,
9595
{
9696
let mut statement = self.prepare_query(source)?;
97-
let mut statement_use = StatementUse::new(&mut statement);
97+
let mut statement_use = StatementUse::new(&mut statement, false);
9898
statement_use.run()?;
9999
Ok(self.raw_connection.rows_affected_by_last_query())
100100
}

diesel/src/sqlite/connection/stmt.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,15 +117,20 @@ impl Drop for Statement {
117117
pub struct StatementUse<'a: 'b, 'b> {
118118
statement: &'a mut Statement,
119119
column_names: Vec<&'b str>,
120+
should_init_column_names: bool,
120121
}
121122

122123
impl<'a, 'b> StatementUse<'a, 'b> {
123-
pub(in crate::sqlite::connection) fn new(statement: &'a mut Statement) -> Self {
124+
pub(in crate::sqlite::connection) fn new(
125+
statement: &'a mut Statement,
126+
should_init_column_names: bool,
127+
) -> Self {
124128
StatementUse {
125129
statement,
126130
// Init with empty vector because column names
127131
// can change till the first call to `step()`
128132
column_names: Vec::new(),
133+
should_init_column_names,
129134
}
130135
}
131136

@@ -146,10 +151,11 @@ impl<'a, 'b> StatementUse<'a, 'b> {
146151
_ => Err(last_error(self.statement.raw_connection())),
147152
}
148153
}?;
149-
if self.column_names.is_empty() {
154+
if self.should_init_column_names {
150155
self.column_names = (0..self.column_count())
151156
.map(|idx| unsafe { self.column_name(idx) })
152157
.collect();
158+
self.should_init_column_names = false;
153159
}
154160
Ok(res.map(move |()| SqliteRow::new(self)))
155161
}

0 commit comments

Comments
 (0)