I have a stored procedure I'm trying to optimize which accepts a table variable as parameter. The table variable has a single column and is used to pass in a list of primary keys. When testing, I create a dummy table variable, run a bunch of INSERT statements to add dummy values to it, and pass it into the stored procedure. This works fine, but when I want to look at the actual query execution plan, SSMS compiles a query plan for all of the INSERT statements and the stored procedure. So, if I have 1000 dummy INSERT statements, SSMS will crash. Unfortunately, the table variable has to be executed in the same batch as the stored procedure, so I can't enable/disable query plans by batch.
Is there a way to compile the actual query plan for the stored procedure only, ignoring all INSERT statements in the batch?
Here's what it looks like:
DECLARE @dummyIds AS PrimaryKeyTable
INSERT INTO @dummyIds VALUES(1)
INSERT INTO @dummyIds VALUES(2)
...
INSERT INTO @dummyIds VALUES(1000)
EXEC MyStoredProc @dummyIds
If I executed that batch including the actual query plan, it would generate 1001 query plans, when I really only want the 1.
The SQL server instance is running SQL SERVER 2014.