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
| Database | Optimization | Typical Gain |
|---|---|---|
| PostgreSQL | Prepared statement cache | 30-50% |
| MySQL | Multi-row INSERT batching | 40-60% |
| MongoDB | Bulk write batching | 50-70% |
| MSSQL | Table-valued parameters | 30-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§
- Batch
Config - Configuration for batch operations.
- Cached
Statement - A cached prepared statement entry.
- Index
Hint - An index hint.
- Join
Hint - A join method hint.
- Mongo
Pipeline Builder - A builder for combining multiple MongoDB operations into a single pipeline.
- Prepared
Statement Cache - A cache for prepared statements.
- Prepared
Statement Stats - Statistics for prepared statement cache.
- Query
Hints - Query plan hints for optimizing complex queries.
Enums§
- Index
Hint Type - Type of index hint.
- Join
Method - Join methods.
- Pipeline
Stage - A MongoDB aggregation pipeline stage.
Functions§
- global_
statement_ cache - Global prepared statement cache.