Blog Post

Friday Followup For December 6, 2013

,

lazy_superman

It’s Friday, time to look back at the most popular RealSQLGuy posts of the week. Because it’s Friday and you’re not doing any real work anyway.

Posts That Were Popular This Week

Comments That Were Posted This Week

  • David Ng on sp_BackupDatabases v1.2:
    Hi Tracy, is it possible to add notifications when the sub jobs are failing ?
  • realsqlguy on sp_BackupDatabases v1.2:
    Yep, it’s on my to-do list, along with logging to a table.
  • Mike Stuart on Using A Non-correlated Subquery To Avoid DISTINCT:
    Great example, all well and good… but *why* does query #3 perform better than the other two?? And, what do I need to learn from this so I can know when and how to apply it in my environment?
  • realsqlguy on Using A Non-correlated Subquery To Avoid DISTINCT:
    Great question. The answer is in the I/O statistics – logical reads specifically. The first two examples are doing over 2500 logical reads in order to return the resultset produced by joining all of the tables together. In those examples, I’ve asked SQL Server to combine the Product, Person, SalesOrderHeader, and SalesOrderDetail tables to produce a resultset. The second example goes further by removing duplicates from that resultset.

    The third example, the fast one, I’m not asking for those tables to be combined. I’m asking SQL Server to give me all of the Person records that are referenced somewhere in the resultset produced by combining Product, SalesOrderHeader, and SalesOrderDetail. I don’t care how many times a Person is referenced, I just want to know that it IS referenced. SQL doesn’t have to fetch as many rows to answer that question for me.

    Does that help?

This Week In History

Rate

You rated this post out of 5. Change rating

Share

Share

Rate

You rated this post out of 5. Change rating