Quiz on indexes and query performance tuning

Q1. Which of the following does DBCC DROPCLEANBUFFERS do?

  •  Removes all clean buffers from the buffer pool and clears the execution plan cache
  • Flushes modified pages from the buffer pool to disk
  • Removes all clean pages from the buffer pool
  • Clears the execution plan cache
Removes all clean pages from the buffer pool

Q2. Where can you see Query Time Stats in an execution plan with the most recent release of SQL Server Management Studio?

Note: these are only available in SQL Server 2014 SP2 and higher

  •  In estimated query execution plans
  •  In actual query execution plans
  •  In cached query execution plans
  •  In estimated and actual query execution plans
Actual Execution Plans

Q3. In our “slow” query, which of the following best describes the problem with statistics on dbo.FirstNameByBirthDate_1966_2015?

  •  SQL Server used the histogram of the index statistics on FirstNameId, but it only used a default sampling and the values weren’t correct
  •  That table only has the FirstNameId column, and SQL Server didn’t know Matthew’s FirstNameId
  •  SQL Server used the histogram of the index statistics on FirstNameId, but the statistics were out of date
  •  SQL Server looked up the wrong FirstNameId value in the histogram when it used the statistics
That table only has the FirstNameId column, and SQL Server didn’t know Matthew’s FirstNameId. SQL Server didn’t know Matthew’s FirstNameId. Looking that up requires running a query, and SQL Server can’t currently run a query as part of the optimization process. (And optimization needs to be VERY FAST, so that wouldn’t make a whole lot of sense.)

Q4. Why didn’t rewriting the query using a CTE make it faster?

  •  We forgot to make the CTE recursive
  •  The CTE is not executed first: it’s all still just one query
  •  We didn’t use a RECOMPILE hint in the CTE
  •  CTEs are bad for performance
The CTE is not executed first: it’s all still just one query. CTEs can be useful in queries. In this case, the CTE rewrite is just a logically different way of phrasing the same query. The portion of the query inside the CTE isn’t executed in a separate step, it’s all still optimized as a single query, and has the same problem with “FirstNameId” being anonymous.

Q5. Which of the following are downsides for using recompile hints to allow SQL Server to “sniff” the value of a local variable in a stored procedure?

Choose all that apply

  •  Recompile can drive up CPU utilization
  •  Recompile makes monitoring performance using the query plan cache much harder
  •  Recompile is not supported by Microsoft
  •  Recompile does not work in stored procedures
Recompile makes monitoring performance using the query plan cache much harder, Recompile can drive up CPU utilization

Q6. What is one thing to be aware of if you execute the built-in sp_recompile procedure against a table in SQL Server, to force any query that references the table to get a fresh plan the next time it runs?1

  •  It clears out the entire execution plan cache
  •  It requires a schema modification lock on the table
  •  It will recreate the table
  •  It doesn’t work for stored procedures
It requires a schema modification lock on the table

Q7. Which of the following should you consider when writing Dynamic SQL?

Choose all that apply

  •  How plan reuse will perform when run for different parameter values (if it is parameterized Dynamic SQL)
  •  How the Dynamic SQL can be debugged and edited later on
  •  How many execution plans will be generated
  •  Whether or not it’s best to use sp_executesql in your case
All of these should be considered
Back to: Why Creating an Index Can Slow Down A Query (1 hour 30 minutes) > Summing up - and a quiz!

Share a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Menu