Errata

SQL Tuning

The errata list is a list of errors and their corrections that were found after the product was released.

The following errata were submitted by our customers and have not yet been approved or disproved by the author or editor. They solely represent the opinion of the customer.

Color Key: Serious technical mistake Minor technical mistake Language or formatting error Typo Question Note Update

Version Location Description Submitted by Date submitted
xiii
1st paragraph, 3rd sentence

"The SQL that most effects the load on a system and the productivity of its end users can usually be improved by a large factor, ..."

In this sentence, effects is confused with affects. The intent of the paragraph is to express which factor (SQL) negatively affects performance most. It isn't to declare that SQL brings load into existence or causes it to occur (except as a result of being poorly written or ill-tuned).

Anonymous  Dec 08, 2010 
Printed Page 27
2nd bullet point

You state "Keep in mind, though, that whichever alternative you test first will have an unfair disadvantage ... since the second experiment will find blocks cached by the first experiment." You then describe running the tests separated by a period of time in the hopes that blocks fall out of the cache.

What I have found useful in my own tuning exercises is to force the database server to flush its cache prior to execution. In Microsoft SQL Server, this is done with the commands "DBCC DROPCLEANBUFFERS" and "DBCC FREEPROCCACHE".

However, you need sysadmin privileges to do this, and is best done on a test system where flushing the cache won't have unfortunate side effects to performance on a production environment.

On a system where you are not a sysadmin and/or where testing MUST occur on a production system, your method is perfectly acceptable -- it is simply more time consuming.

Peter Kristolaitis  Jun 08, 2009 
Printed Page 34
second last paragraph

The statement

SELECT SUM(COUNT(Area_Code)*COUNT(Area_Code))/
(SUM(COUNT(Area_Code))*SUM(COUNT(*)))
FROM CUSTOMERS GROUP BY Area_Code;

is not valid in Microsoft SQL Server. It will fail with message

Cannot perform an aggregate function on an expression containing an aggregate or a subquery.

Anonymous   
Printed Page 34
2nd code example

Query to calculate weighted-average filter selectivity does not work in MS SQL Server due to nested aggregate functions.

Correct SQL is:

SELECT SUM( ni.cnt * ni.cnt ) / ( SUM( ni.cnt ) * AVG( c.cnt ) )
FROM (
SELECT COUNT( Last_Name ) cnt
FROM Customers
GROUP BY Last_Name ) ni
CROSS JOIN (
SELECT COUNT( * ) cnt
FROM Customers ) c

Matt Altieri  Feb 20, 2018 
Printed Page 76
points near bottom of page

"1. Drive into Orders ..."
should be
"1. Drive into Order_Details ...

Anonymous   
80
second piece of indented code, in fixed (Courier) font

The last line of the code snippet:

AND T1.Key4_ID+0*T4.Key4_ID=T5.Key5_ID ...

should read

AND T1.Key5_ID+0*T4.Key4_ID=T5.Key5_ID ...

i.e., please change the first reference to "Key4_ID" to "Key5_ID". Thanks.

Ted Persky  Dec 12, 2011 
Printed Page 116
2nd Paragraph

I have been reading the book SQL Tuning by Dan Tow on safaribooksonline.com.

Looks like the edition you have on that website has mistakes. For example whilst going through your book I came across the following in section 5.2.

"Using an index on the filter for E, the database must begin by touching 0.1 / C rows in the driving table E."

If C is the total number of rows in the employee table and we are applying "E.Exempt_Flag='Y'" filter on it.

Shouldn't the number of rows being touched in the table E be 0.1 * C?

Anonymous   
Printed Page 123
Q1

When executing the SQL statement in Q1, I receive the following error:

Msg 130, Level 15, State 1, Line 1
Cannot perform an aggregate function on an expression containing an aggregate or a subquery.

I have received this error in both SQL 2000 and SQL 2005 environments.

Anonymous   
Printed Page 125
4th bullet point

'Instead, you just need the percentage of rows that have a null foreign key and the two table counts.'
should read:
'Instead, you just need the percentage of rows that have a nonnull foreign key and the two table counts.'

Anonymous