Comments on: SQL 2014 Cardinality Estimator: Why You Should Care – Part 2 https://thomaslarock.com/2014/07/sql-2014-cardinality-estimator-care-part-2/ Thomas LaRock is an author, speaker, data expert, and SQLRockstar. He helps people connect, learn, and share. Along the way he solves data problems, too. Fri, 20 Jan 2017 18:01:47 +0000 hourly 1 https://wordpress.org/?v=6.7.1 By: ThomasLaRock https://thomaslarock.com/2014/07/sql-2014-cardinality-estimator-care-part-2/#comment-12768 Mon, 18 May 2015 22:03:00 +0000 http://thomaslarock.com/?p=11491#comment-12768 In reply to Jaime Martinez Lafargue.

Jaime,

Yes, it’s quite possible, as the estimate for TVF optimization changed in 2012 (I believe). These links provide more details:

http://blogs.msdn.com/b/psssql/archive/2014/04/01/sql-server-2014-s-new-cardinality-estimator-part-1.aspx

http://blogs.msdn.com/b/psssql/archive/2010/10/28/query-performance-and-multi-statement-table-valued-functions.aspx

HTH

]]>
By: Jaime Martinez Lafargue https://thomaslarock.com/2014/07/sql-2014-cardinality-estimator-care-part-2/#comment-12767 Mon, 18 May 2015 14:50:00 +0000 http://thomaslarock.com/?p=11491#comment-12767 Hi Thomas,

I am using SQL Server 2014 and experiencing a weird behavior related to Compatibility Levels and (I think) Cardinality Estimator.

The problem is that a query gets a much worse execution plan with Compatibility Level set to 110 or 120 than with CL set to 100 (SQL 2008).

I could expect some queries performing worse with CL 120 due to the new Cardinality Estimator, but I am somehow confused because the execution plan changes when I switch from 100 to 110, but it is the same for 110 and 120.

The query involves a scalar UDF in the WHERE clause (I am currently trying to refactor the query and avoid that). The estimates for that query with CL 100 were correct, since only a row was affected each time and, thus, the UDF was executed only once. But with CL 110 and 120 the execution plan shows hight values for estimated rows and this makes the UDF to be evaluated many times, and it is hurting performance.

I have guessed that this might be related to the problem with Ascending Keys, and I was lucky before, with CL 100, because it made SQL Server estimate just one (or zero) row, while now it estimates that new rows exist over the max value in the histogram.

But had this changed already for SQL Server 2012 or for SQL Server 2014 with CL = 110?

Thanks a lot and Kind Regards,

Jaime

]]>
By: The Real SQL Server 2014 Power Feature (It May Not Be Hekaton) - SQLRockstar - Thomas LaRock https://thomaslarock.com/2014/07/sql-2014-cardinality-estimator-care-part-2/#comment-11613 Tue, 26 Aug 2014 20:21:06 +0000 http://thomaslarock.com/?p=11491#comment-11613 […] recall that earlier this year I did a 2-part post on the new CE. You can click to read Part1 and Part2. I’ve also presented on this topic at TechEd and SQL Bits. If you haven’t had a chance […]

]]>
By: ThomasLaRock https://thomaslarock.com/2014/07/sql-2014-cardinality-estimator-care-part-2/#comment-11123 Thu, 03 Jul 2014 15:38:00 +0000 http://thomaslarock.com/?p=11491#comment-11123 In reply to TheSQLGuru.

Kevin,

Thanks for reading, and THANK YOU for the detailed comments! I’m going to reply to each of your points, not because I am looking to debate but because I want to offer additional thoughts that I feel may add more value to the above post.

1) Glad you agree! While the extra RAM available for Standard edition is a wonderful thing, none of that matters if the CE is building you a sub-optimal plan. That’s why in my first post I talked about how the CE is a lot like our DNA: we can’t see it, but it’s there, and it makes you you, and it’s not a trivial piece of code.

2) Fair point, and that was my thinking behind the comment “I’d prefer to use the new CE until my data forces me to revert to the legacy CE for some query”.

3) Yes, this is a mess right now! If users have been using the 2389 and 2390 traceflags then they should be aware of the issues between versions and know what updates they need. I didn’t want to dive into this in this post, as I think the topic deserves it’s own post entirely.

Your link wasn’t working, so I am putting it here again: http://support.microsoft.com/kb/2952101

Thanks again Kevin!

]]>
By: TheSQLGuru https://thomaslarock.com/2014/07/sql-2014-cardinality-estimator-care-part-2/#comment-11122 Thu, 03 Jul 2014 09:19:00 +0000 http://thomaslarock.com/?p=11491#comment-11122 1) I agree that the new CE is a significant enhancement in SQL 2014! However, I personally think that for most of the installed instances out there the increase in max RAM to 128GB in the Standard Edition is the most important new feature by far, and the tempdb eager-write back-off is a reasonably-close second.

2) I think there will be a fair bit of pain from the over-estimation issue as more queries switch from nested loop/index seek plans to scans/hashes “earlier” than they would have otherwise given the same statistics on the old CE. Those plans can be SIGNIFICANTLY slower from many perspectives including memory grant (with potentially deadly tempdb spills), physical IO and even CPU. The massive amounts of LOGICAL IOs that come from a high-row-count loop/seek plan are just that – logical – and are typically very fast to iterate, result in fewer physical IOs, require far smaller memory grants and are less prone to locking/blocking issues (as long as they stay at the row/page level with their locks).

3) Beware the ascending key issue. There is a bug in SQL 2014 that was supposedly fixed in CU2 (http://support.microsoft.com/kb/2952101). I say supposedly because Dave Ballantyne posted in the Data Platform Advisors Yammer group questioning the patches’ effectiveness. (https://www.yammer.com/bpdtechadvisors/#/Threads/show?threadId=414052667).

Best,

Kevin

]]>
By: SQL 2014 Cardinality Estimator: Why You Should Care – Part 2 - SQL Server - SQL Server - Toad World https://thomaslarock.com/2014/07/sql-2014-cardinality-estimator-care-part-2/#comment-11121 Thu, 03 Jul 2014 03:16:35 +0000 http://thomaslarock.com/?p=11491#comment-11121 […] SQL 2014 Cardinality Estimator: Why You Should Care – Part 2 is a post from: SQLRockstar – Thomas LaRock […]

]]>
By: SQL 2014 Cardinality Estimator: Why You Should Care - SQLRockstar - Thomas LaRock https://thomaslarock.com/2014/07/sql-2014-cardinality-estimator-care-part-2/#comment-11118 Thu, 03 Jul 2014 03:02:56 +0000 http://thomaslarock.com/?p=11491#comment-11118 […] is the first of two posts on the new Cardinality Estimator in SQL Server […]

]]>