Skip to content

Commit 420958f

Browse files
authored
Merge pull request #7973 from MicrosoftDocs/CompileLock8KBParam_pijocoder_010225
AB#3293: SQL Plan with Parameter greater than 8KB isn't persisted, thus compile lock
2 parents da46f98 + a1ba61d commit 420958f

1 file changed

Lines changed: 6 additions & 3 deletions

File tree

support/sql/database-engine/performance/troubleshoot-blocking-caused-compile-locks.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
---
22
title: Troubleshoot blocking issues caused by compile locks
33
description: This article describes how to troubleshoot and resolve blocking issues caused by compile locks.
4-
ms.date: 09/12/2024
4+
ms.date: 01/08/2025
55
ms.custom: sap:SQL resource usage and configuration (CPU, Memory, Storage)
6+
ms.reviewer: jopilov
67
---
78
# Troubleshoot blocking issues caused by compile locks
89

@@ -83,9 +84,11 @@ The solution is to drop and create the procedure by using the same letter case a
8384

8485
### Stored procedure is invoked as a Language event
8586

86-
If you try to execute a stored procedure as a Language Event instead of as an RPC, SQL Server must parse and compile the language event query, determine that the query is trying to execute the particular procedure, and then try to find a plan in cache for that procedure. To avoid this situation in which SQL Server must parse and compile the language event, make sure that the query is sent to SQL as an RPC.
87+
If you try to execute a stored procedure as a Language Event instead of as an RPC, SQL Server must parse and compile the language event query, determine that the query is trying to execute the particular procedure, and then try to find a plan in cache for that procedure. To avoid this situation in which SQL Server must parse and compile the language event, make sure that the query is sent to SQL Server as an RPC. For example, in .NET code, you can use `SqlCommand.CommandType.StoredProcedure` to ensure an RPC event.
8788

88-
For more information, see the **System Stored Procedures** section in the Books Online article **Creating a Stored Procedure**.
89+
### Stored procedure or sp_executesql uses a string parameter greater than 8 KB
90+
91+
If you call a stored procedure or [sp_executesql](/sql/relational-databases/system-stored-procedures/sp-executesql-transact-sql) and pass a string parameter larger than 8 KB, SQL Server uses a binary large object (BLOB) data type to store the parameter. As a result, the query plan for this execution isn't persisted in the plan cache. Therefore, each execution of the stored procedure or `sp_executesql` has to acquire a compile lock to compile a new plan. This plan is discarded when the execution is complete. For more information, see the note in [Execution plan caching and reuse](/sql/relational-databases/query-processing-architecture-guide#execution-plan-caching-and-reuse) regarding string literals larger than 8 KB. To avoid the compile lock in this scenario, reduce the size of the parameter to less than 8 KB.
8992

9093
## References
9194

0 commit comments

Comments
 (0)