Database indexing optimization for financial queries#580
Open
mendarb wants to merge 1 commit intorohitdash08:mainfrom
Open
Database indexing optimization for financial queries#580mendarb wants to merge 1 commit intorohitdash08:mainfrom
mendarb wants to merge 1 commit intorohitdash08:mainfrom
Conversation
Analyze query patterns across all routes (expenses, dashboard, bills, reminders, insights) and add targeted single-column and composite indexes to eliminate full table scans on the most frequent queries: - expenses: (user_id, spent_at), (user_id, category_id), (user_id, expense_type, spent_at), (user_id, source_recurring_id, spent_at) - categories: (user_id, name) unique composite - bills: (user_id, active, next_due_date) - reminders: (user_id, sent, send_at), (user_id, bill_id, channel, send_at) - recurring_expenses: (user_id, active) - audit_logs: (user_id, created_at) - Single-column indexes on all user_id FK columns and timestamp columns Includes idempotent SQL migration script and 16 tests verifying index declarations at both the SQLAlchemy metadata and database engine levels. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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
002_add_indexes.sql) and 16 tests validating index declarations at both SQLAlchemy metadata and database engine levelsKey indexes added
ix_expenses_user_id_spent_atix_expenses_user_id_category_idix_expenses_user_id_type_spent_atix_expenses_user_id_recurring_spent_atix_categories_user_id_nameix_bills_user_id_active_dueix_reminders_user_id_sent_send_atix_reminders_user_id_bill_id_channel_send_atCloses #128
Test plan
test_db_indexes.pyall passing🤖 Generated with Claude Code