pub struct DmlOptimizer<'a> { /* private fields */ }Expand description
DML cost-based optimizer
Provides optimization decisions for DML operations based on cost estimation.
Implementations§
Source§impl<'a> DmlOptimizer<'a>
impl<'a> DmlOptimizer<'a>
Sourcepub fn get_stats_with_fallback(&self) -> TableStatistics
pub fn get_stats_with_fallback(&self) -> TableStatistics
Get or compute table statistics with fallback for missing stats
When actual statistics are unavailable (new table, no ANALYZE run), this creates fallback statistics based on available metadata.
Sourcepub fn optimal_insert_batch_size(&self, total_rows: usize) -> usize
pub fn optimal_insert_batch_size(&self, total_rows: usize) -> usize
Determine optimal batch size for INSERT operations
Uses cost estimation to decide between small and large batch sizes. High-cost tables (many indexes) benefit from smaller batches to avoid index maintenance overhead accumulating.
§Arguments
total_rows- Total number of rows to insert
§Returns
Recommended batch size
Sourcepub fn should_chunk_delete(&self, rows_to_delete: usize) -> bool
pub fn should_chunk_delete(&self, rows_to_delete: usize) -> bool
Determine if DELETE should be chunked to avoid long locks
Large deletes on high-cost tables can cause long pauses due to index maintenance. Chunking allows other operations to proceed between chunks.
§Arguments
rows_to_delete- Number of rows to be deleted
§Returns
true if delete should be chunked, false for single operation
Sourcepub fn delete_chunk_size(&self) -> usize
pub fn delete_chunk_size(&self) -> usize
Get recommended chunk size for chunked deletes
Sourcepub fn should_trigger_early_compaction(&self) -> bool
pub fn should_trigger_early_compaction(&self) -> bool
Check if early compaction should be triggered
Based on the current deleted ratio, determines if compaction should be triggered sooner than the default 50% threshold.
§Returns
true if early compaction is recommended
Sourcepub fn compute_indexes_affected_ratio(
&self,
changed_columns: &HashSet<usize>,
schema: &TableSchema,
) -> f64
pub fn compute_indexes_affected_ratio( &self, changed_columns: &HashSet<usize>, schema: &TableSchema, ) -> f64
Compute the ratio of indexes affected by an UPDATE operation
This is used for UPDATE cost estimation. If the update only touches non-indexed columns, the ratio is 0.0 and index maintenance is skipped.
§Arguments
changed_columns- Set of column indices being modifiedschema- Table schema for looking up index column info
§Returns
Ratio of indexes affected (0.0 to 1.0)
Sourcepub fn estimate_update_cost(
&self,
row_count: usize,
indexes_affected_ratio: f64,
) -> f64
pub fn estimate_update_cost( &self, row_count: usize, indexes_affected_ratio: f64, ) -> f64
Sourcepub fn index_info(&self) -> Option<&TableIndexInfo>
pub fn index_info(&self) -> Option<&TableIndexInfo>
Get the current table index info (for external use)
Auto Trait Implementations§
impl<'a> Freeze for DmlOptimizer<'a>
impl<'a> !RefUnwindSafe for DmlOptimizer<'a>
impl<'a> Send for DmlOptimizer<'a>
impl<'a> Sync for DmlOptimizer<'a>
impl<'a> Unpin for DmlOptimizer<'a>
impl<'a> !UnwindSafe for DmlOptimizer<'a>
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
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>
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>
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