-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Select extra node in pagination relations for free hasNextPage
query
#4908
base: master
Are you sure you want to change the base?
Select extra node in pagination relations for free hasNextPage
query
#4908
Conversation
…t ordering of selections
Hey, thanks for getting this started! I think this would be a great improvement. One catch right now is that SQL queries are dependent on the order of selections in the GraphQL document. If It'd be nice to make this behavior independent of the client's ordering of fields, but I'm not sure the best way to do it. One way to do it would be to always load the nodes -- even when only Another approach might be to somehow initialize a lookahead (https://graphql-ruby.org/queries/lookahead.html) and use it to investigate what fields are selected. I think you'd have to do that in here somehow: graphql-ruby/lib/graphql/schema/field/connection_extension.rb Lines 24 to 61 in 4e241f8
But I'm not sure the best way to get the graphql-ruby/lib/graphql/execution/interpreter/runtime.rb Lines 305 to 314 in 4e241f8
Let me know what you think -- maybe we can find a way to work up a lookahead if we need one... |
Apologies for the delayed response and thanks for the new test! Great catch. I totally agree that the most correct behavior is to make the optimized behavior independent of client ordering. But I'm not a huge fan of always loading the nodes. I tried that approach initially before this PR and thought that it was a mess keeping the details straight between the ActiveRecord relation connection, the base relation connection, and the base connection. And it'd still be a performance regression for the no-nodes edge case which I assumed was common enough given the test suite coverage. The lookahead approach sounds really interesting and the direction that'd allow both optimizations to co-exist. A bit out of my wheelhouse, but I'll keep looking in that direction! |
This reverts commit 74b16aa.
@rmosolgo What do you think about always evaluating At a higher level it would be something like evaluating results by descending complexity which makes some intuitive sense to me. I made a terribly inefficient and partial but test passing proof-of-concept of what I mean here: mtollie#3 |
The goal of this PR is to implement modifying the query generated by
nodes()
to add an extra row to the query limit and returned rows. This row is thrown away, but its existence is used to infer the value of@has_next_page
.Hopefully this isn't a crazy suggestion but more of an answer to
active_record_relation_connection_spec.rb
The assumption is that fetching 1 extra row is cheaper and more efficient (e.g. fewer round trips, warmer cache, more efficient index than that chosen for
relation_count()
) than aSELECT COUNT(*) ... LIMIT 1 ...
would be. Another assumption is thathasNextPage
will actually be wanted in the future by the query. For our use case in a full-text search context this is definitely true but open to suggestions!Also somewhat unsure about the placement and desired generalizability of this function. It works fine put in the base
relation_connection
class but might have undesired side effects.