While "throw more memory at it" can help some database performance issues, at least temporarily, if your bottlenecks are very CPU bound rather than memory and/or IO bound then adding more memory will have very little effect. There is sometimes more to optimisation than preferring seeks over scans and so forth, sometimes an index scan is more efficient than many executions of seek operations, and the cost estimates upon which the percent figures you are looking at are calculated are that (estimates) at best (a useful guide but sometimes far from at all accurate). My confusion comes from the article only mentioning stored procedures as a solution. The basic idea is that the server has to guess the data type of your parameters and its guesses pollute the cache. SELECT += 'EXEC sp_refreshview '''++''''+CHAR(10) FROM sys.objects WHERE IN ('V') ĮXEC execute plans show 80+ percent of the run time is on a clustered index seek so I don't think there is much more I can do to optimise the stored procedures. Maybe you can try adding OPTION (RECOMPILE) after the query statement in the stored procedureand see if it works. This article warns of the performance pitfalls of using parametrised queries rather than stored procedures. 1 EXEC StoredProcedureName parameters WITH RECOMPILE This method will recompile the stored procedure as soon as the stored procedure executes it. You can similarly mark them as needing to be reassessed to make sure stored plans and other meta-data is not stale with sp_refreshview, by small modifications to either the cursor or ad-hoc SQL methods shown above: DECLARE NVARCHAR(MAX) = '' Here are two easy methods: Method 1: WITH RECOMPILE You can recompile your stored procedure while you execute it. SELECT += 'EXEC sp_recompile '''++''''+CHAR(10) FROM sys.objects WHERE IN ('P', 'FN', 'IF') ĮXEC I find this form sometimes throws people due to looking set-based but building the string up iteratively, and not being a standard SQL pattern)Īnother set of objects that might be a similar concern here is views. Or you could produce ad-hoc SQL and run that via EXEC, takes less code which might be marginally more efficient: DECLARE NVARCHAR(MAX) = '' You can run sp_recompile on everything by using a cursor to produce ad-hoc SQL for each and run it, if you think that will help: DECLARE C CURSOR FOR (SELECT FROM sys.objects WHERE IN ('P', 'FN', 'IF'))
0 Comments
Leave a Reply. |