-
Notifications
You must be signed in to change notification settings - Fork 119
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
fix: naive take on adding an index #1466
Conversation
063f885
to
638b86f
Compare
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.
Hey @drewdelano
Can we know more about the motivation for this index? We currently have UNIQUE (user_id, source_cid)
for upload table, which already provides an index for user_id
behind the scenes. Here you filter out non deleted uploads, but I would say we don't need it unless we are experiencing slower queries with the already existing index.
@vasco-santos This is the issue I'm looking at: web3.storage/packages/db/index.js Line 437 in 112b178
We seem to be seeing a steady increase over time which in my mind points to indexing. This seems related to list all uploads from a given user (that aren't deleted). That said, it might be worth running that query against staging to see how long it takes to return. It's entirely possible I'm wrong here. |
@@ -0,0 +1 @@ | |||
CREATE INDEX IF NOT EXISTS upload_user_id_deleted_at_idx ON upload (user_id) WHERE deleted_at IS NULL; |
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.
CREATE INDEX IF NOT EXISTS upload_user_id_deleted_at_idx ON upload (user_id) WHERE deleted_at IS NULL; | |
CREATE INDEX CONCURRENTLY IF NOT EXISTS upload_user_id_deleted_at_idx ON upload (user_id) WHERE deleted_at IS NULL; |
This needs to concurrently so that the operation does not lock the database
We can definitely try it. Maybe the deleted is the key difference for users with a large number of uploads |
@vasco-santos @drewdelano why not test all this ( EXPLAIN ANALYZE in hand ) on one of your replicas? The indices are all replicated and identical. |
Yes, good call @ribasushi . I was thinking about trying that before we move forward here. @drewdelano does not have access so must be me to try it |
It looks like this helps a lot! @drewdelano
Before Index
After Index
|
@@ -0,0 +1 @@ | |||
CREATE INDEX IF NOT EXISTS upload_user_id_deleted_at_idx ON upload (user_id) WHERE deleted_at IS NULL; |
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.
Also name number will need to be updated
user_id on uploads should probably be indexed...
638b86f
to
56bd69f
Compare
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.
LGTM
user_id on uploads should probably be indexed...
completes #61