Skip to main content

Module feedback

Module feedback 

Source
Expand description

Cardinality Feedback for Query Optimization

This module implements a learning system that improves cardinality estimates by tracking the difference between estimated and actual row counts during query execution. When similar predicates are seen again, the correction factors are applied to produce more accurate estimates.

§How It Works

  1. During EXPLAIN ANALYZE, we record estimated vs actual row counts
  2. A fingerprint is computed for each predicate pattern (structure, not values)
  3. Correction factors are stored: correction = actual / estimated
  4. Future queries with similar patterns use the correction factor

§Example

-- First query: estimated 100, actual 1000 → correction = 10.0
EXPLAIN ANALYZE SELECT * FROM users WHERE status = 'active';

-- Later query: base estimate 50, corrected estimate 500
SELECT * FROM users WHERE status = 'pending';

Structs§

CardinalityFeedback
Cardinality feedback entry for a predicate pattern
FeedbackCache
Cache for cardinality feedback entries

Constants§

DEFAULT_DECAY_FACTOR
Default decay factor for exponential moving average
MAX_CORRECTION_FACTOR
Maximum correction factor to prevent extreme adjustments
MIN_CORRECTION_FACTOR
Minimum correction factor
MIN_SAMPLE_COUNT
Minimum sample count before applying feedback

Functions§

extract_column_from_predicate
Extract the column name from a simple predicate (col = value)
fingerprint_predicate
Compute a fingerprint for a predicate expression
global_feedback_cache
Get the global feedback cache