Allow IN
with subselect to be preparable
#51497
Merged
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.
Motivation / Background
This Pull Request has been created because I noticed that all SQL
IN
statements get automatically marked as non-preparable (Prepared Statements). But it seems like subselects should be preparable, at least to the extent that their Arel nodes are also preparable. With this change, the list of non-preparable Arel Nodes becomes:SqlLiteral
, because they can contain anything.In
when passed Arrays, because Arrays can contain an arbitrary number of items, as well as literal values and thus can have high variability and are therefore bad candidates for a Prepared Statement.NotIn
when passed Arrays, for the same reason asIn
HomogenousIn
which can only be passed ArraysDetail
This Pull Request changes Arel
Nodes
In
andNotIn
to only be marked aspreparable = false
when they are passed Arrays. Otherwise they do not modify the preparable collector state.Because Arel is not a public API, I have not created a changelog entry. Happy do so if requested.
Checklist
Before submitting the PR make sure the following are checked:
[Fix #issue-number]