perf: add missing indexes on member_account_id and velocity account_id#701
Draft
sandipndev wants to merge 1 commit intomainfrom
Draft
perf: add missing indexes on member_account_id and velocity account_id#701sandipndev wants to merge 1 commit intomainfrom
sandipndev wants to merge 1 commit intomainfrom
Conversation
d5f9e7f to
7add0e8
Compare
Contributor
📊 Performance ReportCommit: 7add0e8 Cala Performance Benchmark Results (non-representative)Criterion Benchmark Results (single-threaded)
Load Testing Results (parallel-execution)
Note: Performance results may vary based on system resources and database state. Last updated by commit 7add0e8 |
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
Add two missing database indexes that are hit on every
post_transaction_in_opcall:idx_cala_account_set_member_accounts_member_idoncala_account_set_member_accounts(member_account_id)idx_cala_velocity_account_controls_account_idoncala_velocity_account_controls(account_id)Why these matter
Two queries run on every single cala transaction post:
1.
fetch_mappings_in_op— finds which account sets each account belongs to:2.
find_for_enforcement— finds velocity controls for accounts:Without indexes, PostgreSQL does a sequential scan of the entire table for each query. With 1000 loans in lana-bank,
cala_account_set_member_accountshas ~14,000 rows (14 accounts per loan). Every transaction post — including every interest accrual — scans all 14,000 rows to find the ~2-3 matching ones.With the index, it's an index lookup — O(log n) instead of O(n). The benefit grows with data volume. At 10,000 loans with daily accruals, you'd have 140,000+ rows being scanned on every single transaction post.
Benchmark (lana-bank, 100 loans parallel=10)
Test plan
Found via autonomous performance investigation using autoresearch on the lana-bank loan workflow
🤖 Generated with Claude Code