Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

If SQL is used directly or created by NHibernate, with possibly big "where in / not in ([1 to 100 parameters])" conditions, does it make sense to fill up parameters to certain limits, to have a limited number of query plans?

Parameters are int/number, DBMS is MSSQL or Oracle. The queries are called via sp_executesql/executeimmediate to enforce query plan caching.

Normally, such a query would have up to 100 query plans for the same query. Several such queries might quickly fill up the cache, or result in poor performance by not using cached query plans at all.

A user may fill up the parameter list by repeating the last value, until a certain number of parameters is reached?

As far as I know, MSSQL and Oracle identify known queries by string equality, resulting in a different query plan for each different number of parameters.

(values would of course be parameters and not concatenated numbers).

SELECT * FROM MyTable WHERE Id in (4001, 4002, 4003, ... , 4055, 4056)

with 56 parameters, change to:

SELECT * FROM MyTable WHERE Id in (4001, 4002, 4003, ... , 4055, 4056, 4056, 4056, 4056, 4056)

having 60 parameters by repeating value 4056, with all long "in" lists having lengths of 50, 60, 70, 80, 90, 100. Only less than 10 params will be left.

For such a query with up to 100 parameters, there would be 10 query plans for 10 to 100 parameters, plus 9 query plans for 1 to 9 parameters (no fill).

share|improve this question

1 Answer

If you have a large number of query parameters that all represent the same value type, they should be a column in a table, not a parameter list.

If they are sufficiently static, put them in a filter table and do:

SELECT t.*
FROM MyTable t
INNER JOIN FilterTable f ON t.Id = f.Id

If they are completely dynamic, then use a Table Valued Parameter. In SQL Server 2008 I am able to pass table-valued parameter to my stored procedure from NHibernate.How to achieve the same in Oracle

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.