I’m currently optimizing a solution which is used by different customers on both Native and SQL2005 and SQL2008. My focus so far has only been to ensure that Native and SQL both performed fine, but now I just encountered a difference between SQL2005 and SQL2008. I have two databases with the same data and same statistics and same collation settings; only difference is the SQL version. But the execution plans are different, so I guess SQL2008 is trying to be smarter than SQL2005. This should be a good thing, but in my case it picks a worse index for a specific SELECT. I’m quite sure I can adjust the indexes to fit with SQL2008, but that might destroy some of the execution plans for SQL2005. I’m currently considering to start using IndexHints to ensure both versions uses the same index, but I would like to avoid it.
Has anybody else encountered this problem and has any recommendations?
Regards
Peter
0
Comments
Indexhints should be used when all else fails.
No PM,please use the forum. || May the <SOLVED>-attribute be in your title!
Any chance of getting more information?
But, why it matter if all is working quickly? Or you want to say that some execution plan is too slow? ;-)
MVP - Dynamics NAV
My BLOG
NAVERTICA a.s.
I’m currently installing a new SQL2008 on a local server to ensure I can reproduce the problem on both rather clean servers.
Peter
You'll have to dive into the statistics (DBCC SHOWSTATISTICS) to see if they exactly match. You can also see in the real execution plan how SQL made the decision. Are all these exactly the same?
As Mark mentioned - the same data does not necessarily mean the same statistics. And this is the statistics and NOT the data what decides how execution plan will look like. I would add that even the same statistics does not warrant the same execution plans in different SQL versions.
If you want to compare/tune THE SAME database for performance, detach database from client server, make a copy of database files, and attach copied files to your server. It database is to big to copy it that way read How to generate a script of the necessary database metadata to create a statistics-only database in SQL Server 2005 and in SQL Server 2008 article to see how to duplicate database with statistics only for performance troubleshooting.
As for recommendation - in my opinion enforcing SQL to pick the same (fixed) index may not be good strategy in long term. Try rather to start enforcing recompilation of queries (add WITH RECOMPILE hint), if of course you have not many concurrent users and some free CPU power to waste on each query recompilation. Then try to analyze (and eventually compare) generated query plans.
Regards,
Slawek
Dynamics NAV, MS SQL Server, Wherescape RED;
PRINCE2 Practitioner - License GR657010572SG
GDPR Certified Data Protection Officer - PECB License DPCDPO1025070-2018-03
RIS Plus, LLC
I did an Index Rebuild of the SQL2008 database, and now it picks the same index as my SQL2005.
And I only agree about the comments with Index Hints. That’s why I asked for your help :-)
Thanks for your help, everybody.
Just a few final questions: How do I do that?
How can that be?
Peter
http://www.sql-server-performance.com/t ... is_p1.aspx
You can change the query to force an index and then analyse the differences.
select * from [CRONUS Nederland BV$Cust_ Ledger Entry] WITH (INDEX ("$2"))
where [Document Type] = 3 order by [Document No_]
just my two cents:
Once we ran a benchmark comparing SQL 2005 (STD) and SQL 2008 (STD) - same hardware, same database, same configuration etc..
We testes a crucial business processes.
Result: at average, all tested processed performed 20% faster on SQL 2008!
This, the new engine HAS improved! Some MS SQL PM once told me, that the new engine was improved to increase the performance of most queries by generating better QEP, but he admitted that few queries might perform slower, too ...
I have several customers who upgraded from SQL 2005 to 2008 and the throughout experience is an improvement of overall performance! Once in a while there are indeed few queries which perform worse than before, but so far we could fix all of that by either adding optimized indexes or changing the sorting in NAV.
Best regards,
Jörg
NAV/SQL Performance Optimization & Troubleshooting
STRYK System Improvement
The Blog - The Book - The Tool
Stryk: I know SQL2008 is often a bit faster, but I still expect my optimizations would be ok for both 2005 and 2008. I still expect that different data is more likely to cause different Execution Plans than different SQL versions.
Peter
SET STATISTICS IO ON
The the "Message" Tab of the Result-Output will show the "Reads" etc..
NAV/SQL Performance Optimization & Troubleshooting
STRYK System Improvement
The Blog - The Book - The Tool
I expect I need to assign the variables some values and then "execute" the cursor, but I don't know the syntax :oops:
Peter