-
Notifications
You must be signed in to change notification settings - Fork 219
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
Performance fix for related select #209
Conversation
24f6330
to
ea4ec78
Compare
c769b79
to
15d0551
Compare
If the relation column is in the same table, do not join with itself. We can only do this if the query has no pagination. 30% speed increase.
Not sure if I am missing something, but If I understand correctly you are trying to fix the case where we join even though only the id of the related node is requested AND this Id is inlined in the node above it in the query. For these cases we can get rid of the join and just return the inlined id. But on your data model the Id is inlined on Post and the fix should not affect that query since we still need to join in order to get the id. A query that should be affected would be this:
Here the author Id is already contained in Post and we can skip the join. Can you verify with the logging Postgres Docker image which SQL statements are produced before and after the change for the queries? |
There are also failures on CI with invalid SQL statements, I can look into these tomorrow, or we can do it together. |
This will fix the selection of post id, that is triggered in the end of the query. Master joins post by post due to the author id being in the same table. We don't need to join. |
Ah, ok then we are talking about different cases I think. I was talking about the join from Post to User in my query being unnecessary. |
Already fixed on my machine. Didn't push because needed to run. |
15d0551
to
a2d05b1
Compare
And now green tests. |
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.
Looks good to me.
If the relation column is in the same table, do not join with itself.
We can only do this if the query has no pagination, in the optimal case we can cut a big slice of the response time off.
Query:
Schema:
Data generated to psql 10 with sql-load-test with 3 000 000 users, 30 000 000 posts, 30 000 000 comments and 150 000 000 likes.
Green: master, purple: this PR, database psql, y-axis nanoseconds, x-axis requests per second:
Fixes #127