0

If a query is executed with 10 parameters in an IN clause, and then the same query is executed again but with 20 parameters, can the database server reuse the execution plan from the first run, or is a fresh execution plan having to be created each time?

riceball
  • 403
  • 2
  • 15

1 Answers1

0

I just did a quick check in SQL Server and it looks like each query did indeed receive its own query plan when I added/removed values from the IN clause.

This code will show you the query plans currently cached. You can adjust the check on text to narrow it down to your own specific queries and then see if new rows show up as you execute additional versions of the queries.

SELECT TOP 10
    text,
    *
FROM
    sys.dm_exec_cached_plans AS CP
CROSS APPLY sys.dm_exec_sql_text(CP.plan_handle) ST
WHERE
    text LIKE 'select * from dbo.My_Table where%'
Tom H
  • 46,766
  • 14
  • 87
  • 128