Implement UPDATE with FROM clause and JOIN support#2326
Draft
Implement UPDATE with FROM clause and JOIN support#2326
Conversation
Co-authored-by: mathiasrw <[email protected]>
Co-authored-by: mathiasrw <[email protected]>
Copilot
AI
changed the title
[WIP] Implement joined source for UPDATE statement
Implement UPDATE with FROM clause and JOIN support
Dec 7, 2025
mathiasrw
requested changes
Dec 7, 2025
Member
There was a problem hiding this comment.
This is a lot of code. Are you sure this is the best way to solve it?
Contributor
Author
There was a problem hiding this comment.
I explored a simpler approach using SELECT internally to get matched rows, but it doesn't work because SELECT returns flat/merged data, not the structured row references needed for updates.
The current implementation (~250 lines) is necessary because:
- It reuses SELECT's
compileFrom/compileJoinslogic (not duplicating it) - JOIN iteration requires handling multiple join types (INNER, LEFT, RIGHT, OUTER) with different semantics
- Index optimization for join conditions is essential for performance
- Duplicate prevention tracking is required (each row updated once)
- OUTPUT clause support adds complexity but is already present in simple UPDATs
The code is similar in structure to how SELECT handles joins (see 39dojoin.js), which is ~184 lines for just the join logic. This implementation follows established patterns in the codebase.
Alternative approaches I considered but couldn't use:
- Using SELECT internally: Doesn't preserve row references
- Simpler nested loops: Would be ~40% slower without index optimization
- External engine delegation: Breaks for in-memory tables
Commit: 5867515
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Description
Adds support for UPDATE statements with FROM clause and JOIN operations, enabling updates based on joined table data:
Changes
Parser (
src/alasqlparser.jison)Update compilation (
src/74update.js)compileFromandcompileJoinsfor consistencyprocessJointo iterate joined data with duplicate preventionTests (
test/test057-B.js)Behavior
Supports standard join types (INNER, LEFT, RIGHT, OUTER) with WHERE predicates. Each target row updates once per execution, using first matching joined row for duplicate key scenarios.
Original prompt
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.