pub struct OdbcBufferSettings {
pub batch_size: usize,
pub max_column_size: Option<usize>,
}
Available on crate feature
odbc
only.Expand description
Configuration for ODBC buffer settings that control memory usage and performance characteristics.
These settings affect how SQLx fetches and processes data from ODBC data sources. Careful tuning of these parameters can significantly impact memory usage and query performance.
ยงBuffered vs Unbuffered Mode
The buffer settings control two different data fetching strategies based on max_column_size
:
Buffered Mode (when max_column_size
is Some(value)
):
- Fetches rows in batches using columnar buffers for better performance with large result sets
- Pre-allocates memory for all columns and rows in each batch using
ColumnarAnyBuffer
- WARNING: Long textual and binary field data will be truncated to
max_column_size
- Better for high-throughput scenarios where memory usage is acceptable
- Uses
batch_size
to control how many rows are fetched at once
Unbuffered Mode (when max_column_size
is None
):
- Fetches rows in batches using the
next_row()
method for memory efficiency - Processes rows in batches of
batch_size
but without pre-allocating columnar buffers - No data truncation - handles variable-sized data dynamically
- More memory efficient than buffered mode but potentially slower
- Better for scenarios where data sizes vary significantly or memory is constrained
Fieldsยง
ยงbatch_size: usize
The number of rows to fetch in each batch during bulk operations.
Performance Impact:
- Higher values reduce the number of round-trips to the database but increase memory usage
- Lower values reduce memory usage but may increase latency due to more frequent fetches
- Typical range: 32-512 rows
- Used in both buffered and unbuffered modes
Memory Impact:
- In buffered mode: Each batch allocates buffers for
batch_size * number_of_columns
cells - In unbuffered mode: Each batch processes
batch_size
rows without pre-allocation - For wide result sets, this can consume significant memory
Default: 128 rows
max_column_size: Option<usize>
The maximum size (in characters) for text and binary columns when the database doesnโt specify a length.
Performance Impact:
- When
Some(value)
: Enables buffered mode with batch fetching and pre-allocated buffers - When
None
: Enables unbuffered mode with batched row-by-row processing - Higher values ensure large text fields are fully captured but increase memory allocation
- Lower values may truncate data but reduce memory pressure
- Affects VARCHAR, NVARCHAR, TEXT, and BLOB column types
Memory Impact:
- When
Some(value)
: Directly controls buffer size for variable-length columns - When
None
: Minimal memory allocation per row, no truncation - Setting too high can waste memory; setting too low can cause data truncation
- Consider your data characteristics when tuning this value
Default: Some(4096)
Trait Implementationsยง
Sourceยงimpl Clone for OdbcBufferSettings
impl Clone for OdbcBufferSettings
Sourceยงfn clone(&self) -> OdbcBufferSettings
fn clone(&self) -> OdbcBufferSettings
Returns a duplicate of the value. Read more
1.0.0 ยท Sourceยงfn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moreSourceยงimpl Debug for OdbcBufferSettings
impl Debug for OdbcBufferSettings
Sourceยงimpl Default for OdbcBufferSettings
impl Default for OdbcBufferSettings
Sourceยงfn default() -> OdbcBufferSettings
fn default() -> OdbcBufferSettings
Returns the โdefault valueโ for a type. Read more
Sourceยงimpl PartialEq for OdbcBufferSettings
impl PartialEq for OdbcBufferSettings
impl Copy for OdbcBufferSettings
impl Eq for OdbcBufferSettings
impl StructuralPartialEq for OdbcBufferSettings
Auto Trait Implementationsยง
impl Freeze for OdbcBufferSettings
impl RefUnwindSafe for OdbcBufferSettings
impl Send for OdbcBufferSettings
impl Sync for OdbcBufferSettings
impl Unpin for OdbcBufferSettings
impl UnwindSafe for OdbcBufferSettings
Blanket Implementationsยง
Sourceยงimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Sourceยงfn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Sourceยงimpl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Sourceยงimpl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Sourceยงimpl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Sourceยงimpl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Sourceยงfn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key
and return true
if they are equal.Sourceยงimpl<T> IntoEither for T
impl<T> IntoEither for T
Sourceยงfn into_either(self, into_left: bool) -> Either<Self, Self> โ
fn into_either(self, into_left: bool) -> Either<Self, Self> โ
Converts
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSourceยงfn into_either_with<F>(self, into_left: F) -> Either<Self, Self> โ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> โ
Converts
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more