pub struct BatchConfig {
pub batch_size: usize,
pub max_payload_bytes: usize,
pub multi_row_insert: bool,
pub use_copy: bool,
pub parallelism: usize,
}Expand description
Configuration for batch operations.
Fields§
§batch_size: usizeNumber of rows per batch.
max_payload_bytes: usizeMaximum payload size in bytes.
multi_row_insert: boolWhether to use multi-row INSERT syntax.
use_copy: boolWhether to use COPY for bulk inserts (PostgreSQL).
parallelism: usizeParallelism level for bulk operations.
Implementations§
Source§impl BatchConfig
impl BatchConfig
Sourcepub const fn default_config() -> Self
pub const fn default_config() -> Self
Default batch configuration.
Sourcepub fn for_database(db_type: DatabaseType) -> Self
pub fn for_database(db_type: DatabaseType) -> Self
Create configuration optimized for the given database.
Sourcepub fn auto_tune(
db_type: DatabaseType,
avg_row_size: usize,
total_rows: usize,
) -> Self
pub fn auto_tune( db_type: DatabaseType, avg_row_size: usize, total_rows: usize, ) -> Self
Auto-tune batch size based on row size and count.
This calculates an optimal batch size that:
- Stays within the max payload size
- Balances memory usage vs round-trip overhead
- Adapts to row size variations
§Example
use prax_query::db_optimize::BatchConfig;
use prax_query::sql::DatabaseType;
// Auto-tune for 10,000 rows averaging 500 bytes each
let config = BatchConfig::auto_tune(
DatabaseType::PostgreSQL,
500, // avg row size in bytes
10_000, // total row count
);
println!("Optimal batch size: {}", config.batch_size);Sourcepub fn batch_ranges(&self, total: usize) -> impl Iterator<Item = (usize, usize)>
pub fn batch_ranges(&self, total: usize) -> impl Iterator<Item = (usize, usize)>
Create an iterator that yields batch ranges.
§Example
use prax_query::db_optimize::BatchConfig;
let config = BatchConfig::default_config();
let total = 2500;
for (start, end) in config.batch_ranges(total) {
println!("Processing rows {} to {}", start, end);
}Sourcepub fn batch_count(&self, total: usize) -> usize
pub fn batch_count(&self, total: usize) -> usize
Calculate the number of batches for a given total.
Trait Implementations§
Source§impl Clone for BatchConfig
impl Clone for BatchConfig
Source§fn clone(&self) -> BatchConfig
fn clone(&self) -> BatchConfig
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 BatchConfig
impl Debug for BatchConfig
Source§impl Default for BatchConfig
impl Default for BatchConfig
impl Copy for BatchConfig
Auto Trait Implementations§
impl Freeze for BatchConfig
impl RefUnwindSafe for BatchConfig
impl Send for BatchConfig
impl Sync for BatchConfig
impl Unpin for BatchConfig
impl UnwindSafe for BatchConfig
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