Determine if a query should be cached based on its pattern and hints
(&self, pattern: &QueryPattern, hints: &OptimizationHints)
| 165 | |
| 166 | /// Determine if a query should be cached based on its pattern and hints |
| 167 | fn should_cache_query(&self, pattern: &QueryPattern, hints: &OptimizationHints) -> bool { |
| 168 | use crate::query::{QueryPattern, QueryComplexity}; |
| 169 | |
| 170 | match pattern { |
| 171 | // Always cache these patterns - high reuse potential |
| 172 | QueryPattern::SimpleSelect | |
| 173 | QueryPattern::SimpleInsert | |
| 174 | QueryPattern::SimpleUpdate | |
| 175 | QueryPattern::SimpleDelete | |
| 176 | QueryPattern::BatchInsert | |
| 177 | QueryPattern::CountQuery | |
| 178 | QueryPattern::ExistsQuery | |
| 179 | QueryPattern::MaxMinQuery => true, |
| 180 | |
| 181 | // Cache medium complexity queries if they use prepared statements |
| 182 | QueryPattern::GroupByAggregation | |
| 183 | QueryPattern::OrderByLimit | |
| 184 | QueryPattern::JoinWithWhere | |
| 185 | QueryPattern::SubqueryExists => { |
| 186 | hints.use_prepared_statement |
| 187 | }, |
| 188 | |
| 189 | // Only cache complex queries if explicitly recommended |
| 190 | QueryPattern::NestedSubquery | |
| 191 | QueryPattern::UnionQuery | |
| 192 | QueryPattern::ComplexQuery => { |
| 193 | hints.cache_result && hints.complexity != QueryComplexity::Complex |
| 194 | }, |
| 195 | } |
| 196 | } |
| 197 | |
| 198 | /// Extract enhanced metadata including optimization information |
| 199 | fn extract_enhanced_metadata( |
no outgoing calls
no test coverage detected