DmlOptimizer

Struct DmlOptimizer 

Source
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>

Source

pub fn new(db: &'a Database, table_name: &'a str) -> Self

Create a new DML optimizer for a table

§Arguments
  • db - Database reference for metadata lookups
  • table_name - Name of the table being operated on
§Returns

DmlOptimizer instance with cost estimation configured

Source

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.

Source

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

Source

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

Source

pub fn delete_chunk_size(&self) -> usize

Get recommended chunk size for chunked deletes

Source

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

Source

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 modified
  • schema - Table schema for looking up index column info
§Returns

Ratio of indexes affected (0.0 to 1.0)

Source

pub fn estimate_update_cost( &self, row_count: usize, indexes_affected_ratio: f64, ) -> f64

Estimate the cost of an UPDATE operation

§Arguments
  • row_count - Number of rows to update
  • indexes_affected_ratio - Ratio of indexes affected (from compute_indexes_affected_ratio)
§Returns

Estimated cost in arbitrary units

Source

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<G1, G2> Within<G2> for G1
where G2: Contains<G1>,

Source§

fn is_within(&self, b: &G2) -> bool