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

Is it Possible to use the functions without Holdlock #41

Closed
nafberger opened this issue Apr 24, 2018 · 2 comments
Closed

Is it Possible to use the functions without Holdlock #41

nafberger opened this issue Apr 24, 2018 · 2 comments
Labels

Comments

@nafberger
Copy link

sometimes the Holdlock creates trouble with other processes and creates deadlocks. whats the benefit of using it and can it be turned off?

@borisdj
Copy link
Owner

borisdj commented May 4, 2018

HOLDLOCK is used for Concurrency Issues:
https://www.mssqltips.com/sqlservertip/3074/use-caution-with-sql-servers-merge-statement/
MERGE *looks* like it will take care of concurrency for you, because implicitly it seems to a single, atomic statement. However, under the covers, SQL Server really does perform the different operations independently. This means that you could end up with race conditions or primary key conflicts when multiple users are attempting to fire the same MERGE statement concurrently. Dan Guzman went into a lot of detail in his blog post a few years ago, but basically this means that unless you use a HOLDLOCK hint on your MERGE target, your statement is vulnerable to race conditions. In reviewing customer code and questions out in the community, I don't recall ever coming across a HOLDLOCK hint naturally, except in cases where someone was demonstrating the very race condition I'm talking about.

It can work without it but I am not sure if then you could encounter these Concurrency Issues.
If you think your use case would better without if I could change this so that using HOLDLOCK would be an option in BulkConfig.

Also check: HOLDLOCK required in MERGE with UPDATE and UPSERT anti-pattern.

@borisdj
Copy link
Owner

borisdj commented May 15, 2018

BulkConfig WithHoldlock added.

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

No branches or pull requests

2 participants