-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Perform runtime fragment splicing in Ecto #4697
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
greg-rychlewski
merged 1 commit into
elixir-ecto:master
from
greg-rychlewski:runtime_splice
Jan 11, 2026
+57
−44
Merged
Changes from all commits
Commits
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
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
Oops, something went wrong.
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.
This is the weirdest part. Because we use
length(params)to set the parameter indexes and we don't know how many are in here until runtime.Doing it this way keeps parameter counting in the rest of the builder the same and planner cleans everything up anyways.
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 has been a while, so can you please remind me how it works in this case?
fragment(..., splice(^foo), ^bar)How do we know the parameter position for^bar? I guess the planner goes increment all parameters later on, whenever it sees aspliceor anin?Uh oh!
There was an error while loading. Please reload this page.
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.
Yeah basically like that.
To be more specific, when normalizing a query the
prewalkfunction in the planner has an accumulator that keeps track of the current query parameter number. The counter is initialized to 0 for queries and initialized to the current parameter count when doing stuff like insert_all or conflict queries. Whenever the prewalker sees a query parameter it just increments the parameter counter.For
:inand the current implementation of:splicethey have a bit of a trick in the prewalker. Since we don't know the length of the list at compile time we treat the whole list as one query parameter then in the prewalker it shifts the counter by the length of the list. See here for :in and here for :splice. Then in the adapter it sees the AST for these things and does the actual splicing of the SQL text. The parameter list itself is spliced by the planner here.