Skip to content

perf(db): add composite indexes for high-frequency financial queries#780

Open
bkennedyshit wants to merge 1 commit intorohitdash08:mainfrom
bkennedyshit:feat/db-indexing
Open

perf(db): add composite indexes for high-frequency financial queries#780
bkennedyshit wants to merge 1 commit intorohitdash08:mainfrom
bkennedyshit:feat/db-indexing

Conversation

@bkennedyshit
Copy link
Copy Markdown

Closes #128

What

Adds 6 composite SQLAlchemy indexes targeting the most common query patterns in FinMind's financial data layer.

Indexes Added

Index Table Columns Query Pattern
ix_expenses_user_spent expenses user_id, spent_at Dashboard date-range aggregations
ix_expenses_user_category expenses user_id, category_id Category breakdown reports
ix_expenses_user_type expenses user_id, expense_type Income vs expense splits
ix_recurring_user_active recurring_expenses user_id, active Active recurring expense fetches
ix_bills_user_due bills user_id, due_date Upcoming bills lookups
ix_categories_user categories user_id Per-user category list

Implementation

  • Alembic migration 003_add_performance_indexes.py with upgrade() and downgrade()
  • models_indexed.py — ORM-level Index() definitions for SQLAlchemy awareness
  • Tests — verify index definitions exist and queries execute without error

Testing

pytest packages/backend/tests/test_db_indexes.py -v

…ohitdash08#128)

- ix_expenses_user_spent: covers dashboard date-range aggregations
- ix_expenses_user_category: covers category breakdown queries
- ix_expenses_user_type: covers income vs expense splits
- ix_recurring_user_active: covers active recurring expense fetches
- ix_bills_user_due: covers upcoming bills lookups
- ix_categories_user: covers per-user category list queries

Includes Alembic migration (003_add_performance_indexes) and model-level
Index() definitions for ORM awareness. Tests verify index presence and
query smoke tests pass.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Database indexing optimization for financial queries

1 participant