feat: Database indexing optimization for financial queries (#128)#432
Open
lalalic wants to merge 1 commit intorohitdash08:mainfrom
Open
feat: Database indexing optimization for financial queries (#128)#432lalalic wants to merge 1 commit intorohitdash08:mainfrom
lalalic wants to merge 1 commit intorohitdash08:mainfrom
Conversation
…08#128) Adds comprehensive indexing strategy across all tables with 20+ targeted indexes to improve performance of high-frequency financial queries. Key improvements: - Expense queries: composite indexes for user+date, user+category+date, user+type, and trigram index for text search - Bill queries: partial index for active upcoming bills - Reminder queries: partial index for pending unsent reminders - Category/user indexes for common lookup patterns - Performance monitoring API with index coverage analysis, benchmarks, and table statistics New files: - app/db/026_indexing_optimization.sql - 20+ index definitions - app/models.py - SQLAlchemy index declarations on all models - app/services/indexing.py - coverage analysis, benchmarks, statistics - app/routes/indexing.py - admin API endpoints - docs/db-indexing-optimization.md - comprehensive documentation - tests/test_indexing.py - 27 tests API endpoints: - GET /admin/db/indexes - list all indexes - GET /admin/db/coverage - query pattern coverage report - GET /admin/db/statistics - table row counts - POST /admin/db/benchmark - run query benchmarks 27 tests covering index verification, coverage analysis, and API Closes rohitdash08#128
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Implements comprehensive database indexing optimization for financial queries, addressing issue #128. Adds 20+ targeted indexes across all application tables with a performance monitoring API.
What it does
Index Strategy
Adds optimized indexes following the "equality → range → sort" principle for maximum query efficiency:
Expenses (highest volume):
idx_expenses_user_date— Primary listing (every page load)idx_expenses_user_category_date— Category reportsidx_expenses_user_date_amount— Monthly totals and SUM queriesidx_expenses_notes_trgm— Full-text search (GIN trigram)idx_expenses_user_type— Income vs expense filteringBills & Reminders:
idx_bills_user_due— Upcoming bills dashboard (partial: active only)idx_reminders_pending— Cron job unsent reminders (partial)All other tables — Categories, users, ad impressions, audit logs, subscriptions
Performance Monitoring
/admin/db/indexes/admin/db/coverage/admin/db/statistics/admin/db/benchmarkFiles Changed
app/db/026_indexing_optimization.sqlapp/models.pyIndex()declarations on 6 modelsapp/services/indexing.pyapp/routes/indexing.pyapp/routes/__init__.pytests/conftest.pytests/test_indexing.pydocs/db-indexing-optimization.mdTesting
Index Coverage Report Example
{ "total_patterns": 9, "covered": 8, "missing": 1, "coverage_percentage": 88.9 }Closes #128