Module db_optimize

Module db_optimize 

Source
Expand description

Database-specific optimizations.

This module provides performance optimizations tailored to each database:

  • Prepared statement caching (PostgreSQL, MySQL, MSSQL)
  • Batch size tuning for bulk operations
  • MongoDB pipeline aggregation
  • Query plan hints for complex queries

§Performance Characteristics

DatabaseOptimizationTypical Gain
PostgreSQLPrepared statement cache30-50%
MySQLMulti-row INSERT batching40-60%
MongoDBBulk write batching50-70%
MSSQLTable-valued parameters30-40%

§Example

use prax_query::db_optimize::{PreparedStatementCache, BatchConfig, QueryHints};

// Prepared statement caching
let cache = PreparedStatementCache::new(100);
let stmt = cache.get_or_prepare("find_user", || {
    "SELECT * FROM users WHERE id = $1"
});

// Auto-tuned batching
let config = BatchConfig::auto_tune(payload_size, row_count);
for batch in data.chunks(config.batch_size) {
    execute_batch(batch);
}

// Query hints
let hints = QueryHints::new()
    .parallel(4)
    .index_hint("users_email_idx");

Structs§

BatchConfig
Configuration for batch operations.
CachedStatement
A cached prepared statement entry.
IndexHint
An index hint.
JoinHint
A join method hint.
MongoPipelineBuilder
A builder for combining multiple MongoDB operations into a single pipeline.
PreparedStatementCache
A cache for prepared statements.
PreparedStatementStats
Statistics for prepared statement cache.
QueryHints
Query plan hints for optimizing complex queries.

Enums§

IndexHintType
Type of index hint.
JoinMethod
Join methods.
PipelineStage
A MongoDB aggregation pipeline stage.

Functions§

global_statement_cache
Global prepared statement cache.