Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
Support optimized select for top-level query #2235
base: master
Are you sure you want to change the base?
Support optimized select for top-level query #2235
Changes from 22 commits
2f13537
290e464
03d4124
cacc576
d49f0ec
6f1a04a
ed0bee9
3ef48bd
23237a1
1b73b78
bcf8f8c
6ca50ae
c9a7343
7e75f24
45d12f1
cd30eea
fa6f99a
7bc7c76
f983dec
25e0ecc
abf875f
61ed5cd
768b28b
6e21e28
0990919
deabb67
667f222
6b456f6
c3ff536
9ec7c71
ee2442f
3221dd2
982f4c1
5cd2304
e5b0715
2d9f386
aafd02c
f0c4846
5171228
1d570bf
f385f5d
b170698
2aa0e4a
f4fb5d8
24ee8d4
0635733
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
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.
Shouldn't this throw?
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.
In some cases,
$selectColumns
will be empty, and it shouldn’t throw exceptions because this is an expected behavior.Use the above schema as an example. The
posts: [Post!]!
will not be optimized due to empty$selectColumns
. In the current implementation, the@hasMany
directive is a must-have directive to let the optimized select work normally.The optimized select is an improvement feature, even if this function is not working normally due to insufficient directives, it shouldn’t break original queries.
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.
In this example, the query would have to select the users
id
so thatposts
can be resolved without@hasMany
, right?In that case, I believe this check is insufficient in order to not break the query. If the client queries an additional field from
User
,$selectColumns
would no longer be empty and result inSELECT name FROM users
, thus breaking the resolution ofposts
.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.
What does this do?
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.
We only want to replace
*
withid
. The sub-query and bindings should be preserved.From
testOrderByRelationCount()
query dump:
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.
I do not understand why you need to first get and then re-set the bindings. As far as I can tell,
->select()
only clearscolumns
andbindings['select']
.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.
Do you mean it only needs to re-set the
bindings['select']
but not the wholebindings
?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.
I think these 3 lines and
$bindings = $query->getRawBindings();
are completely unnecessary.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.
The above schema is the case. Before
->select()
, the raw query is below. The subquery has a select bindingcleaning
thatname != ?
needs. If we don't re-set the bindings, it will throwIlluminate\Database\QueryException: SQLSTATE[HY093]: Invalid parameter number
. Because the select bindings were clear by->select()
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.
That sounds reasonable then. Saves unnecessary work and is more explicit about what is happening and why.
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.
does not match the signature
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.
We should consider starting this setting with
false
and wait for reports of forgotten edge cases to come in.