You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
nutrition_facts has only a PK index. At 1,032 rows this is fine — seq scans are <1ms. An index on (product_id) would be redundant since the PK already provides this.
No missing indexes identified. All JOIN paths used in v_master, API functions, and QA checks hit indexed columns.
No unused indexes detected. At 1,025 products, all indexes are small and maintenance overhead is negligible.
3. Scale Projections
Growth Scenarios
Metric
Current
5K Products
50K Products
Notes
v_master category query
4.5ms
~20ms
~100ms
Linear with category size
find_similar_products
6.6ms
~150ms
~3s
O(n²) Jaccard — bottleneck
api_search_products
7.8ms
~15ms
~50ms
pg_trgm GIN scales well
MV refresh (confidence)
31ms
~300ms
~3s
Linear
MV refresh (ingredient freq)
27ms
~200ms
~2s
Linear
Total index storage
~2MB
~20MB
~200MB
Linear
Identified Bottleneck: find_similar_products
The Jaccard similarity computation self-joins product_ingredient (~13 rows/product average). At 50K products:
Self-join produces ~13 × 650K = 8.5M comparisons per call
Mitigation: Pre-filter by category before Jaccard (already done when p_same_category = true)
Future fix: Pre-compute pairwise similarity as a materialized view for hot categories
4. Scale Readiness Checklist
✅ Already Done
Indexes on all JOIN columns and WHERE predicates
pg_trgm GIN indexes for text search
Materialized views for expensive aggregations
CONCURRENTLY refresh support on v_product_confidence
Category-scoped queries in all API functions
Pagination on all listing endpoints
No N+1 query patterns in views
🟡 Recommended at 5K+ Products
Add CONCURRENTLY support to mv_ingredient_frequency (unique index: idx_mv_ingredient_freq_id)
Set up periodic MV refresh — api_refresh_mvs() RPC (service_role only), recommended every 15 min or after pipeline runs
Add statement_timeout to PostgREST config — 5s for API roles, 30s for MV refresh functions