Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce indexes to db tables, greatly improving performance. #5424

Merged
merged 6 commits into from
Mar 24, 2025

Conversation

dbrant
Copy link
Member

@dbrant dbrant commented Mar 21, 2025

This is a bit of a facepalm moment:
Our database tables of HistoryEntry and PageImage didn't have indexes set up! Adding indexes to tables (especially tables that will grow very large) is super important for performance when making queries or doing migrations.

I tested migrating a HistoryEntry table with 10000 entries. With our current db structure, the migration takes about 12 seconds, which accounts for the ANRs that we have seen from a small number of users.
With this new structure with indexing, the migration (with 10000 entries) takes 100 milliseconds.

Note that adding indexes will necessitate another db version bump (to 28), and I added two new migration paths, 27→28 and 26→28, simply because version 27 is already in the wild (in our Beta version). But really the 26→28 migration will be the one that occurs in production, and this is the one that is now optimized for efficiency.

@dbrant dbrant added the High Priority Priority code review needed label Mar 21, 2025
@Williamrai
Copy link
Collaborator

I switched branch from the main to dbIndexes to test and then i got this this error view.
Image1

I did fresh install and added some history entry to have some data and then switched to this branch, then i saw this error view.
Image2

@dbrant
Copy link
Member Author

dbrant commented Mar 21, 2025

I switched branch from the main to dbIndexes to test and then i got this this error view.
I did fresh install and added some history entry to have some data and then switched to this branch, then i saw this error view.

Whoops, absolutely right. I removed an unnecessary index creation statement from the 27→28 migration, which should fix this issue.

Copy link
Collaborator

@cooltey cooltey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me! Will let @Williamrai to merge it if it looks good to you too.

@Williamrai Williamrai merged commit d245712 into main Mar 24, 2025
1 check passed
@Williamrai Williamrai deleted the dbIndexes branch March 24, 2025 19:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
High Priority Priority code review needed
Development

Successfully merging this pull request may close these issues.

3 participants