Skip to content
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

Allow IN with subselect to be preparable #51497

Merged
merged 1 commit into from Apr 5, 2024

Conversation

bensheldon
Copy link
Contributor

@bensheldon bensheldon commented Apr 5, 2024

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 as In
  • HomogenousIn which can only be passed Arrays

Detail

This Pull Request changes Arel Nodes In and NotIn to only be marked as preparable = 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:

  • This Pull Request is related to one change. Unrelated changes should be opened in separate PRs.
  • Commit message has a detailed description of what changed and why. If this PR fixes a related issue include it in the commit message. Ex: [Fix #issue-number]
  • Tests are added or updated if you fix a bug or add a feature.
  • CHANGELOG files are updated for the changed libraries if there is a behavior change or additional feature. Minor bug fixes and documentation changes should not be included.

@matthewd matthewd merged commit dbb5c4a into rails:main Apr 5, 2024
4 checks passed
@bensheldon bensheldon deleted the preparable-in branch April 12, 2024 15:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants