-
Notifications
You must be signed in to change notification settings - Fork 555
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
Improve book library page query performance for author sort order #4080
Conversation
…ng update triggers and indices
Nice! I also ran the new unit test over 300 times in a loop with no errors as a sanity check. |
I added the last commit to fix #4043 (unrelated to the other changes in the PR) This isn't the best possible fix in terms of query performance (crearing a denormalized libraryId column in podcastEpisodes, and changing the recent episodes query to use this column would result in a better performing query), but it does improve performance significanly on the library containing 130,000 episodes on my Synology ABS (~80-90% decrease in query time). |
I was able to fix it by using the ORDER BY in the GROUP_CONCAT introduced in an earlier sqlite version so I also updated sqlite3 to https://github.com/TryGhost/node-sqlite3/releases/tag/v5.1.7. Can you do some testing to see if this will work? I'm out of time today so won't be making any more changes |
Sure. The unit test also fails now - I'll check. |
OK, I did the following changes:
I've re-tested with existing and new databases, with emphasis on adding and removing multiple authors from the same book. |
Thanks! I did a bunch of testing as well. |
Brief summary
Similar to #3952, this significantly improves book library page query performance for the following sort orders:
Which issue is fixed?
No Issue. This is a continuation of my work on #2073
In-depth Description
To replace per-record subqueries, I added two denormalized columns to
libraryItems
,authorNamesFirstLast
, andauthorNames LastFirst
. These columns are kept indexed and are updated when the corresponding records inbookAuthors
/authors
are modified.Using the new columns in library page queries (instead of per-record subqueries and unindexed sorting) resulted in an optimized query plan, and significantly improved query performance.
How have you tested this?
Correctness
Performance
Tested on loading 72 consecutive page of 35 books each, on first-last author sort order, on an ABS docker container running on a Synology 920+ NAS.
Last-first author sort order results were similar.
All measurements are in ms.
Summary
Overall, we see a ~97% drop in mean and median query time.
Current (edge):
After denormalizing authorNames: