Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PERF: Add index
id DESC, baked_version
ON posts
.
A scheduled job runs `Post.rebake_old` with a limit of 80 which does a look up for the latest posts that have not been baked to the latest version. Before this commit, the query would run using the primary key's index and does a reverse scan. However the query performance quicky becomes bad as more and more of the latest posts have been baked to the latest version.
- Loading branch information
4791d99
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is breaking the parallel ruby test. I'm not exactly sure about the reason.
topic.posts
method returns posts in reverse order. Checking...4791d99
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh ... I can explain why a filtered index is what we want here.
You are selecting more or less like so:
This is way of making this more efficient is by adding
That way as you reindex the index keeps on getting smaller until it has 0 size.
To grab the next id you just have to head to the first entry in the index.
Once you change that it is no longer there.
This index does not help...
Imagine you have the records
To find
3,1
you still got to scan the5,2
and4,2
, all the index placed does is replaced a table scan with an index scan. We should be seeking here which is way cheaper.4791d99
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://review.discourse.org/t/perf-add-index-for-rebake-old-to-posts/2721
4791d99
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Followed up :slight_smile: Thanks for the tip 👍