-
-
Notifications
You must be signed in to change notification settings - Fork 5.9k
Use subquery to instead In #10874
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
Merged
guillep2k
merged 5 commits into
go-gitea:master
from
lunny:lunny/use_sub_query_instead_in
Mar 30, 2020
Merged
Use subquery to instead In #10874
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
415c179
Use subquery to instead In
lunny 355b0c7
Support excludedLabelNames on issues options
lunny 9ba4136
Fix tests
lunny 056842e
Merge branch 'master' into lunny/use_sub_query_instead_in
zeripath 769aa8e
Merge branch 'master' into lunny/use_sub_query_instead_in
lunny File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
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.
@guillep2k can we do better here? I'm suspicious that this
In
could be quite expensive.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.
WHERE EXISTS (SELECT ...)
is the equivalent idiom, but depending on the engine it could be better optimized.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 all depends on how sophisticated the engine is. Some engines will rearrange the whole query and be very clever on optimizing the access... others will just take your statement more or less literally, and therefore your syntax might influence the results drastically. And versions are important too. I read from time to time "XX SQL now takes this construct and treats it like xxx for better performance".
Formally,
WHERE EXISTS (SELECT ...)
is equivalent toIN (SELECT ....)
; but if the engine is not too smart,EXISTS
is a kind of join that is more optimizable than a plain LOOP JOIN (e.g. using a HASH JOIN).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.
But performing the
IN()
in a subquery is definitely more performant thatSELECT ids
, and then `SELECT ... WHERE ... IN(id list).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.
Like @guillep2k said, it depends on the database engine. The sub query maybe cached or not. It may be faster than before or not. But it will give the right result however many there are labels. But for
In
withid
, when there are over 500 variables, database will return error.