Press "Enter" to skip to content

Avoid OPENJSON in Cursor Declarations

Joe Obbish has a public service announcement:

I found a few stored procedures with single plan cache entries over 500 MB of memory each according to sys.dm_exec_cached_plans while optimizing the plan cache in production. The stored procedures were relatively simple and both execution plans were less than 1 MB when saved as sqlplan files. I was confused, offended, and confused.

Read on to learn how this happened, see an example of it in action, and how you can avoid it in your own environment.