-
-
Notifications
You must be signed in to change notification settings - Fork 10.5k
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
Improved performance fetching posts #20460
Conversation
ref https://linear.app/tryghost/issue/ONC-111 - added composite index to posts_tags for post_id,tag_id for faster lookup - added composite index to posts for updated_at; this is commonly used by get helpers on the front end to display data like the latest posts In testing, this provided a very dramatic improvement for simple get helper requests like 'filter="id:-{{post.id}}+tag:sampleTag" limit="3"' which are by default sorted by updated_at desc. I'm not entirely clear why when sorting by published_at we do not need a composite index - so far it doesn't seem to be necessary. This should cover the primary cases for get helpers - the latest posts with a given tag or set of tags.
It looks like this PR contains a migration 👀 General requirements
Schema changes
Data changes
|
@daniellockyer @mike182uk I removed the previous PR's This led to the following get helper for 125k posts going from 12s to 20ms when the query was run on the db. See here for more details. The overall get helper time is not that fast because there's a lot of other queries run at the same time (relations, member check, etc).
|
I'm not sure why the test is failing with the following. I can add and drop the index locally just fine within TablePlus. Error: alter table |
Ok, the issue is that MySQL will change the foreign key-generated index to the composite index, likely as a sort of optimization, but it is not an irreversible procedure. We can create an index on |
Do we have a sense of how long this will take to run on a large table? |
@ErisDS I ran this locally with 125k rows in |
@ErisDS This only took 8s on a staging site 👍. Same large dataset. |
Confirmed this index is helping with get helpers on staging after running. |
ref https://linear.app/tryghost/issue/ONC-111
In testing, this provided a very dramatic improvement for simple get helper requests like 'filter="id:-{{post.id}}+tag:sampleTag" limit="3"' which are by default sorted by updated_at desc. I'm not entirely clear why when sorting by published_at we do not need a composite index - so far it doesn't seem to be necessary. This should cover the primary cases for get helpers - the latest posts with a given tag or set of tags.