Skip to content

Performance improvements#83

Merged
raphaelm merged 4 commits into
masterfrom
performance202607
Jul 23, 2026
Merged

Performance improvements#83
raphaelm merged 4 commits into
masterfrom
performance202607

Conversation

@raphaelm

Copy link
Copy Markdown
Member

Fixes three performance issues on large databases:

  • We did not have an index on OrderPosition.server_id, which made typical lookups quite slow. We should have indexes on all server_id fields, they are cheap and prevent future problems.
  • We did not have indexes on all foreign keys used for joins. This is generally a best practice, databases like PostgreSQL would automatically create them. So let's create them! I see some speedups especially on Quota_Item table and the likes of it.
  • We had an index on Receipt(canceled) and ReceiptLine(canceled). This was a bad idea. There are only two possible values of this field (true / false) that usually have a ratio somewhere between 50:50 and 80:20. This means that utilizing the index to scan the table for all (non-)canceled lines only reduces the work by half. However, since SQLite's optimizer isn't too clever, it prevented using actually useful indexes. On a query like SELECT SUM(price) AS sum FROM ReceiptLine WHERE receipt = ? AND canceled = 0, SQLite would do a scan over the canceled = 0 index and then filter out tens of thosands of wrong receipts, instead of just scanning over the receipt = ? index and filter out 5 of 10 lines.

@raphaelm
raphaelm merged commit 3ae874b into master Jul 23, 2026
1 check passed
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.

2 participants