-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
Update: Relational: Potential optimization in MERGE SQL batching path? #8415
Comments
cc @divega |
Another comment from https://www.brentozar.com/archive/2017/05/case-entity-framework-cores-odd-sql/#comment-2398183:
MERGE [Weapons] USING (VALUES
(@p0, @p1, 0),
(@p2, @p3, 1),
(@p4, @p5, 2)
) AS i ([IsPointy], [Name], [_Position]) ON 1=0
WHEN NOT MATCHED THEN
INSERT ([IsPointy], [Name])
VALUES (i.[IsPointy], i.[Name])
OUTPUT INSERTED.[WeaponId], i._Position
INTO @inserted0; However this looks very similar to multi-row INSERT syntax, which turned out not to have deterministic order (#4080). |
@divega The Table Value Constructor pattern still allows for an explicit order sentinel and so it doesn't matter whether the order is deterministic. It looks to be a slightly cleaner syntax by omitting one TV. |
EDIT: Looks like @anpete beat me to the punch. The below confirms his findings. My reading of #4080 is that non-deterministic output from the multi-row INSERT caused the client to incorrectly reconcile inserted identities with their respective entities. Is that correct? If so, I think we'd be fine here, because the above construct still allows the explicit |
@anpete @zac-torkelson you are right. BTW, thanks for the feedback! |
@AndriySvyryd Thoughts on this for 2.0? Should it be punted for now? /cc @divega |
I think it can go in. These aren't breaking changes. |
I removed the |
@AndriySvyryd Nice! Can you share the query plans for both? |
Interesting, thanks for looking at this. Great to understand what's going on here. |
@anpete @AndriySvyryd should we close this issue as fixed then? I wonder whether we should still track offloading ORDER BY from the database server. Perhaps some benefit would be observable under load, but we don't have time to test it now. |
@divega Agree, it's hard for me to imagine that there is no scenario where this doesn't show an improvement. There is also some benefit in just having simpler SQL. |
We should close this and track further optimization in separate issues when we find scenarios that need improvement. |
Ok, created #8849 to track ORDER BY removal. Closing as fixed in preview2. |
(Based on feedback from https://www.brentozar.com/archive/2017/05/case-entity-framework-cores-odd-sql)
Right now when using the MERGE batch update path, we perform a final ORDER BY on the server to retrieve the store gen'd values in the correct batch order. However, it could be that the values are already in the correct order, so we could perform the ordering on the client, lazily, by detecting out of order rows when they occur. NB. This would sometimes require client buffering of the reader.
The text was updated successfully, but these errors were encountered: