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

Implement bulk update with SaveChanges #35401

Open
roji opened this issue Jan 2, 2025 · 0 comments
Open

Implement bulk update with SaveChanges #35401

roji opened this issue Jan 2, 2025 · 0 comments

Comments

@roji
Copy link
Member

roji commented Jan 2, 2025

When multiple identical updates are performed on different rows via SaveChanges, we currently generate N SQL UPDATEs:

UPDATE foo SET bar = @v1 WHERE id = @id1;
UPDATE foo SET bar = @v2 WHERE id = @id2;
UPDATE foo SET bar = @v3 WHERE id = @id3;
...

We could explore identifying such identical updates and collapsing them into a single UPDATE statements, e.g.:

UPDATE foo
SET bar = CASE 
    WHEN id = @id1 THEN @v1
    WHEN id = @id2 THEN @v2
    WHEN id = @id3 THEN @v3
    ...
END
WHERE "Id" IN (@id1, @id2, @id3);

We'd need to explore how this actually performs across different databases etc. This is conceptually similar to what we already do for SQL Server for insertion (where multiple INSERTs are collapsed to a single MERGE), and to #27550 for bulk deletion.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant