If you like me - Knowing which Build you should have deployed when we look @ the myriad of Service Packs & Cumulative Updates possible, it can quickly become confusing
What actions should I do to "PATCH" a server to the appropriate build, So here is a quick script that can easily be updated as new builds are made available, and easily customized for your own environments
-- This Script only reports on your current version and recommends your course of action - Usualy disclaimer of using script in your environments..
-- As per Aarons article - please ensure this is suitable for you environment http://www.microsoft.com/technet/security/Bulletin/MS11-049.mspx
Aaron's article: http://sqlblog.com/blogs/aaron_bertrand/archive/2011/06/14/security-updates-for-all-supported-versions-of-sql-server.aspx#comments
*** Updated script [ 24th April 2012 ] ***
--added CU1 (RTM) SQL 2012
--added CU6 (SP1) SQL Server 2008R2
--added CU4 (SP3) SQL Server 2008
Glenn Berry Reconmended I add a few links:
Listing of SQL Server Builds: http://sqlserverbuilds.blogspot.co.nz/
The SQL Server 2008 R2 builds that were released after SQL Server 2008 R2 Service Pack 1 was released http://support.microsoft.com/kb/2567616
SQL Server 2008 builds that were released after SQL Server 2008 SP3 was released http://support.microsoft.com/kb/2629969
The SQL Server 2012 builds that were released after SQL Server 2012 was released http://support.microsoft.com/kb/2692828
;With CTE_SQLEditions([Major],[Minor],[Build],[BuildMinor])
AS
(
select
parsename(convert(varchar,serverproperty ('productversion')),4) As Major,
parsename(convert(varchar,serverproperty ('productversion')),3) As Minor,
parsename(convert(varchar,serverproperty ('productversion')),2) As Build,
parsename(convert(varchar,serverproperty ('productversion')),1) As Buildminor
)
Select @@SERVERNAME, *
,CASE
WHEN Major = 9 --
SQL 2005
THEN
CASE
WHEN Build
< 5000 THEN 'Upgrade to Service Pack 4 (9.0.5000), also consider applying
the latest CU3 for SP4'
WHEN Build
= 5000 THEN 'SP4 Installed, Consider apply latest CU3 for SP4(9.0.5266)'
WHEN Build
= 5254 THEN 'SP4-CU1 installed, Consider apply latest CU3 for
SP4(9.0.5266)'
WHEN Build
= 5259 THEN 'SP4-CU2 installed, Consider apply latest CU3 for
SP4(9.0.5266)'
WHEN Build
= 5266 THEN '** SP4-CU3 installed, Watch for newer CU releases for SP4'
END
WHEN Major = 10 And Minor = 0 -- SQL 2008
THEN
CASE
WHEN Build
< 5416 THEN 'Upgrade to Service Pack 3 (10.0.5416), also consider
applying the latest CU4 for SP3'
WHEN Build
= 5416 THEN 'SP3 Installed, Consider apply latest CU2 for SP3(10.0.5768)'
WHEN Build
= 5776 THEN 'SP3-CU1 installed, Consider apply latest CU2 for
SP3(10.0.5775)'
WHEN Build
= 5768 THEN 'SP3-CU2 installed, Consider apply latest CU2 for
SP3(10.0.5775)'
WHEN Build
= 5770 THEN 'SP3-CU3 installed, Consider apply latest CU2 for
SP3(10.0.5775)'
WHEN Build
= 5775 THEN '** SP3-CU4 installed, Watch for newer CU releases for SP3'
END
WHEN Major = 10 And Minor = 50 -- SQL 2008 R2
THEN
CASE
WHEN Build
< 2500 THEN 'Upgrade to Service Pack 1 (10.50.2500), also consider
applying the latest CU6 for SP1'
WHEN Build
= 2500 THEN 'SP1 Installed,also Consider apply latest CU6 for SP1
(10.50.2811)'
WHEN Build
= 2769 THEN 'SP1-CU1 installed, Consider apply latest CU6 for SP1
(10.50.2811)'
WHEN Build
= 2772 THEN 'SP1-CU2 installed, Consider apply latest CU6 for SP1
(10.50.2811)'
WHEN Build
= 2789 THEN 'SP1-CU3 installed, Consider apply latest CU6 for SP1
(10.50.2811)'
WHEN Build
= 2796 THEN 'SP1-CU4 installed, Consider apply latest CU6 for SP1
(10.50.2811)'
WHEN Build
= 2806 THEN 'SP1-CU5 installed, Consider apply latest CU6 for SP1
(10.50.2811)'
WHEN Build = 2811 THEN '** SP1-CU6 installed,
Watch for newer CU releases for SP1'
END
WHEN Major = 11 And Minor = 0 -- SQL 2012
THEN
CASE
WHEN Build
< 1103 THEN 'CTP1 Installed, Consider moving to the RTM (11.00.2100)
Release'
WHEN Build
= 1440 THEN 'CTP3 Installed, Consider moving to the RTM (11.00.2100)
Release'
WHEN Build
= 1750 THEN 'RC0 Installed, Consider moving to the RTM (11.00.2100)
Release'
WHEN Build
= 1913 THEN 'RC1 Installed, Consider moving to the RTM (11.00.2100)
Release'
WHEN Build = 2100 THEN 'RTM Installed, Consider
apply latest CU1 for RTM (11.00.2316)'
WHEN Build = 2316 THEN 'Cumulative Update #1 fo
the RTM of SQL Server.'
END
END AS [Reconmendations]
FROM CTE_SQLEditions
Hello
So was very exicited to have my 24HOP session on SQL Sever 2012 Memory
Unfortunately I had the Demo gods decided that I should be paid a few visits.. and caused me to drop my connections for 10-15 minutes (several reboots later)
I have attached the PPT slide (PDF) for those who want it
I had to rush through the demo's as I lost 10-15 minutes and will redo this session as a camtasia recording to give this session again in one contigous recording
The demo scripts will also be made available as well - I will add some comment for these to help explain their purposes
Slide deck PDF 24HOP_NeilHambly_2012MemoryArch.zip
24 Hours of PASS
The
Spring 2012 SQLPASS 24 hours of PASS event is a WHOLE DAY {Yes 24 hours’ worth}
of SQL session exploding right onto computer screen’s near you
When:
21st March 2012 - 1 session every hour on the hour for a full 24 hours
The
full agenda contains all the exciting details for each of the sessions &
the speakers delivering the session
But
just in case, the ones you can't make it too on the day, you can watch them at
a later time
But
you'll be attending mine LIVE of course {and don’t shake your head, nod instead}
Session 12 @ 11:00 GMT Neil
Hambly "SQL Server 2012
Memory Management"
http://www.sqlpass.org/24hours/spring2012/SessionsbySchedule/SessionDetails.aspx?sid=2582
I
do feel very fortunate & honored
to have been selected to present my session @ this great event
I’ll
also try to stay awake and watch as many as I can during the day and night
PRESS RELEASE FROM PASS
Registration Opens for 24 Hours of PASS, Featuring Closed Captioning in 15 Languages
Top SQL Server & BI
Experts to Deliver 24 Free Back-to-Back Webcasts Focusing on SQL Server 2012
CHICAGO, IL –
February 16, 2012 – Catch up on your sleep while you can. The
Professional Association for SQL Server (PASS) is bringing an exceptional
lineup of SQL Server and business intelligence (BI) experts directly to your
computer March 21 for the free, nonstop
Registration opened today for the series of 24 live, back-to-back
webcasts, which for the first time will feature live closed captioning in 15
languages.
No matter where you are in the world, you’ll gain access to best
practices and expert tips delivered directly to your computer by some of the industry’s most knowledgeable and top-rated speakers, including MVPs and community and Microsoft experts from around
the world.
“Thanks to Rob Farley and his 24 Hours of PASS
team, we have an excellent speaker lineup and a rich mix of sessions that deliver deep SQL Server
2012 guidance as well as core SQL Server, BI, and professional development
information that’s valuable no matter what release you’re on,” said PASS Vice
President of Marketing Thomas LaRock.
“We are also thrilled to offer closed captioning
for our global community as part of the IBTalk platform. The unique format of
24 Hours of PASS is about bringing database professionals together around the
world, and I encourage anyone who wants to learn more about SQL Server to
attend as many sessions as possible.”
In
addition to extensive coverage of SQL Server 2012, the event presentations will explore Integration Services,
PowerShell, performance tuning, data warehousing, data mining, high
availability, T-SQL, cloud computing, and more. Each session will also feature
a live Q&A segment.
Co-sponsored by Microsoft and SQL Sentry, the webcasts begin at
00:00 GMT on March 21 (8pm ET on March 20 in the US). To determine what time each session will air in your region, see
our time
zone guide. The sessions you sign up for will automatically be added
to your Outlook calendar at the correct time for your time zone.
Learn
more about 24 Hours of PASS: SQL Server 2012 at http://www.sqlpass.org/24hours/spring2012/
and
register today
for your favorite sessions.
About PASS
The Professional Association for SQL Server (PASS) is an
independent, not-for-profit association dedicated to supporting, educating, and
promoting the Microsoft SQL Server community.
From
local user groups and virtual chapters to Webcasts and the annual PASS
Summit—the largest gathering of SQL Server professionals in the world—PASS
enables knowledge sharing, in-depth learning, access to the Microsoft SQL
Server team, and the ability to influence the direction of SQL Server
technologies. The PASS mission is to empower the global SQL Server community to
connect, share, and learn.
For
more information about PASS and the benefits of its free membership, visit the
PASS Web site at http://www.sqlpass.org.
All
brand names, product names, and trademarks belong to their respective holders.
SQL RALLY 2012 (Dallas)
The
normal session selections are just about to be announced (think this is happening
in the next day or 2) I'm hoping to be one of them ......... fingers crossed – Stay
tuned folks for news on those sessions
****** NEWS FLASH 17-02-2012 ******
Results are in and <Drum roll> YES one of my submissions has been accepted for SQL Rally it is the most popular one I have @ the moment
Sesison is named "Compression - Define your Strategy"
I'm presenting this popular Compression Session @ 3 events on 3 consecutive Saturday's during March
1. SQL Saturday #115 {Lisbon, Portugal} on 17th March + Portugal's Technical Launch SQL SERVER 2012
2. SQL Saturday #105 {Dublin, Ireland} on 24th March + Ireland's Technical Launch SQL SERVER 2012
3. SQLBits X (10) {London, UK} on 31st March + United Kingdom's Technical Launch SQL SERVER 2012
Also not forgetting my 24HOP session @ 11:00 GMT on 21st March http://www.sqlpass.org/24hours/spring2012/SessionsbySchedule/SessionDetails.aspx?sid=2582
I must like doing thing's in 3 as I've 3 Pre-Cons I'm attending @ these above events & 3 SQL exams between now and end of March !
P.S Community voting for some specially selected SQL RALLY session's opens today and until Friday 24th Feb 1PM PST ...Please take a few minutes to cast your votes
****** NEWS FLASH 17-02-2012 ******
I
was indeed fortunate & extremely pleased that my Pre-Con submission for SQL Rally was chosen for inclusion in
the community voting round, and sadly even though it didn't manage to
finally secure a TOP 2 spot, those went to 2 VERY deserving winner submission's
(Congrats
to the winners these look like they will be really awesome pre-cons to attend)
Demystifying
Database Administration Best Practices
Database Administration (DBA)
Argenis
Fernandez (Coinstar), Robert
Davis (Microsoft Corp.)
How
to be a DBA - A Utility Belt of tools
Database Administration (DBA)
Tjay
Belt (Imagine Learning), Chris
Shaw (AMS)
I'm
going to this event , maybe will see you there and will enjoy soaking up all
the great SQL knowledge and community vibe as well as catching up with my #sqlfamily friends
Who
knows I might have even had found time to try my hand @ MCM Exam & Lab
before the conference
I
have some scheduled pre-requisite exams later in Feb & March {Wish me luck}
As the builds progress
we have gotten more and more wait_types
These where the number
of wait_types in each version so far
- 202 SQL Server 2005
- 484 SQL Server 2008
- 490 SQL Server 2008 R2
- 631 CTP3
- 646 RC0 (15 more as listed below)
These 15 are the ones I
have not encountered before in any pre 2012 RCO builds - What are they ??
[Sorry] For now I just
can't tell you as I simply do not have the resources to fully explain their purpose { Some of their purpose can be deduced by its name }
and none
of these as yet show me any values other than 0 (zero)
Select *
from sys.dm_os_wait_stats
WHERE Wait_type in
('DTCPNTSYNC','HADR_CONNECTIVITY_INFO','HADR_FILESTREAM_FILE_CLOSE','HADR_SYNCHRONIZING_THROTTLE'
,'HADR_TIMER_TASK','PREEMPTIVE_HADR_LEASE_MECHANISM','PWAIT_EVENT_SESSION_INIT_MUTEX','PWAIT_REPLICA_ONLINE_INIT_MUTEX'
,'RESOURCE_GOVERNOR_IDLE','SCAN_CHAR_HASH_ARRAY_INITIALIZATION','SP_SERVER_DIAGNOSTICS_BUFFER_ACCESS'
,'WAIT_XTP_GUEST','WAIT_XTP_TASK_SHUTDOWN','WAIT_XTP_TRAN_COMMIT','XTPPROC_PARTITIONED_STACK_CREATE')
As I learn more and try
out the AlwaysON feature I’m sure some of these may start to show some numbers
SQL Server like other software unfortunately has bugs, and thankfully these are often resolved in the subsequent Service Packs & Hotfixes released
One such bug was the incorrect growth of the log file, if the growth increment was any multiple of 4GB - it doesn't grow with the expected growth size
For those who didn't know
As log growths are split in a number of equally sized number of VLFs, with that number of VLFs dependent on the overall growth increment size
For a growth increment that is less than 64MB, this will grow the file in 4 VLFs (equally sized), and with a growth increment size between 64MB to 1GB this is in 8 VLFs, finally for the growths > 1GB this is in 16 VLFs
Paul Randal blogged on this bug way back in May 2010 - that's when I learned about the 4GB increment issue
http://www.sqlskills.com/BLOGS/PAUL/post/Bug-log-file-growth-broken-for-multiples-of-4GB.aspx
I recommend that you also read this entry VLFs by Kimberly http://www.sqlskills.com/BLOGS/KIMBERLY/post/Transaction-Log-VLFs-too-many-or-too-few.aspx#ixzz1lXeN9jNy
Subsequently my growths have been primarily in 2GB Growths, thus 16 VLFs each being 128MB (Once this hotfix is in place I can perhaps use the 4GB interval I want larger VLFs)
Finally a Connect item can help highlight such issues and ultimately even get us a fix - I try to review these regularly and vote for those you agree should be resolved
http://connect.microsoft.com/SQLServer/feedback/details/481594/log-growth-not-working-properly-with-specific-growth-sizes-vlfs-also-not-created-appropriately
Well for SQL Server 2008R2 this is being now addressed with the SP1+CU4 or CU11, details are documented in this KB http://support.microsoft.com/kb/2633151
It doesn't seem that there is also a fix for SQL Server 2008 - if this does become known I blog those details also
Things
are getting real BUZY for me on the SQL Events front already {I have plans to
do a lot of SQL Events this year, to even try to match my huge 2011 tally)
I
have to try to find time to plan and organize all the various tasks needed to
just fit it all in {need to get my travel plans sorted .I will have to try
using Tripit as Jen Stirrup has recommended
and
I still need to find a few evenings to run some local User-Group events in
London over the next few months
I'm Looking for companies to be
hosts for our User-Group evenings - So would you like to have a SQL User-Group
event in London @ your own location (Ideal for your SQL Team to attend)
it
just needs a room capable of seating 30-100 people for ~ 3 hours (6-9PM) during
a mid-week evening (Tuesday - Thursday's) and not be difficult for the attendee's to get to.. close to a tube station (within 5-10 minutes) is always helpfull
We'll
provide the speakers (you can help choice the topics for the evening) and we also provide the
dinner & refreshments + SWAG for the attendee's - interested please email
me @ Neil.Hambly@Hotmail.co.uk
So
with this many event's already in my Calendar over the next few Months, it is
going to be very exciting time but a tad exhausting as well
I
will get to see so many of my SQL Friends over these events and undoubtedly meet
a few new ones
Feb 2012
13th Online MCM Overview event
Robert L Davis (MCM Program Lead) hosts this 90 minute session on the MCM cert
23rd SQL UG (North Acton, London)
Presenting on Extended Events & Hosting the Evening
March 2012
7th Online "Virtual launch SQL Server 2012"
Whole day of events (30) .. should be a real fun day {have it booked off to watch a lot of this without distractions}
16th- 17th SQLSat #115 Lisbon, Portugal
Confirmed Speaker "Compression" + a LT on WMI
21st @ 11AM GMT 24 Hours of PASS Virtual event http://www.sqlpass.org/24hours/spring2012/
Confirmed Speaker "SQL SERVER 2012 Memory Manangement"
22nd -24th SQLSat #105 Dublin, Ireland
Confirmed Speaker "Compression"
29th- 31st SQLBits X London
Confirmed Speaker "Compression" + Volunteer + attending Adam's Pre-Con (excellent)
April 2012
19th SQL Server User Group (London) @ IMGROUP EC4Y 8DP
Another of our User-Group Events, this one I'm just the host of and have Tony Rogerson MVP speaking and another from IMGROUP on BIGDATA topic
http://www.sqlserverfaq.com/events/384/London-UG-meeting-on-BI-topics-With-Tony-Rogerson-MVP-and-a-session-on-BIG-Data-from-IMGROUP.aspx
20th - 21st SQLSat #107 Houston, USA
Still awaiting outcome of my submissions & Idera ACE 2012 competition
May 2012
9TH - 12TH SQLRally Dallas, USA
Confirmed Speaker "Compression"
14th - 18th SQLSkills IE2 Course London
Attending this week 2 IE2 course, having done week 1 IE1 in July 2011
21st - 25th SQL Relay 2012
Our UK week long series of full day SQL Events (Roadshow with SQL 2012 focus) I'll be @ the London Event @ least , perhaps others as well
24th - 26th SQLDay Wroclaw, Poland
Confirmed Speaker with "Why are we Waiting.." session that I did that @ SQLPASS Summit 2011
I'm only there on the Saturday 26th as in UK for the Thursday/Friday Sessions
Have more planned for June onwards... but that is a story for another day
As some of you probably know - I do speak a lot of SQL conference's, but getting session submissions picked can be tough @ times (especially for the larger events)
Sometimes there are community voting rounds .. for a few precious slots @ these larger events
I now have one of those voting rounds for my Pre-Con submission @ the next SQLRally event May 8th - May 11th in Dallas, TX (this is one of the largest SQL Conferences)
My Pre-Con submission "Performance Trace & Event Collection in SQL Server" was selected for the voting round (that in itself is a big deal)
So please can I kindly ask if you can you spare just a minute of your time & vote for my session
(it will be tough competition to secure one of the spots)
http://www.sqlpass.org/sqlrally/2012/dallas/CommunityChoice.aspx
Just Login (free to register if not already a member) and selected the session(s) you want to vote for - The voting ends 9th Feb 5PM (CST)
For those interested my upcoming confirmed events I'll be presenting @ (some outside of UK) as follows
- London 23rd FEB @ UK SQL User-Group (North Acton) ..Presenting on Extended Events (replacement for Profiler)
"Effective Data Management Using Data Compression" session I have presented before @ SQL-in-the-City (Red-Gate) conference
- Lisbon (Portugal) Mar 17th @ SQLSaturday #115
- Dublin (Ireland) Mar 24th @ SQLSaturday #105 - Also Ireland SQL 2012 Technical launch
- London April 1st @ SQLBits X - Also UK SQL 2012 Technical launch
"Why are we Waiting.." Session I one I did @ SQLPASS (that had 310 attendees, 9th highest session attendance of the conference from 160 sessions)
- Wroclaw (Poland) May 26th @ SQLDay
THANK YOU for your support
Following on my from posting on Cardinality earlier this month, As I will likely want a way to quickly evaluate the stats history for a database
http://sqlblogcasts.com/blogs/neilhambly/archive/2012/01/14/show-me-some-cardinality.aspx
I can of course automate the processs with something like the following script - which can be run against a database to provide a summary of the statistics for a given database
Have a Happy Stats day
SET NOCOUNT ON
CREATE TABLE #STATS
(
TABLE_CATALOG VARCHAR(128)
,TABLE_SCHEMA VARCHAR(128)
,TABLE_NAME VARCHAR(128)
,STATISTICS_CATALOG VARCHAR(128)
,STATISTICS_SCHEMA VARCHAR(128)
,STATISTICS_NAME VARCHAR(128)
,STATISTICS_TYPE INT
,COLUMN_NAME VARCHAR(128)
,COLUMN_GUID VARCHAR(128)
,COLUMN_PROPID VARCHAR(128)
,ORDINAL_POSITION INT
,SAMPLE_PCT INT
,LAST_UPDATE_TIME DATETIME
,NO_OF_RANGES INT
,COLUMN_CARDINALITY INT
,TUPLE_CARDINALITY INT
,TABLE_CARDINALITY INT
,AVG_COLUMN_LENGTH INT
)
GO
DECLARE @DBName VARCHAR(64), @SchemaName VARCHAR(64), @TableName VARCHAR(64), @IndexName VARCHAR(64)
DECLARE curStats CURSOR FAST_FORWARD READ_ONLY FOR
SELECT
QUOTENAME(DB_NAME()) AS DBName,
QUOTENAME(Schema_name(SO.schema_id)) AS SchemaName,
QUOTENAME(OBJECT_NAME(SO.OBJECT_ID)) AS TableName,
SI.name AS IndexName
FROM sys.indexes SI
INNER JOIN
sys.objects SO ON SI.object_id = SO.object_id
WHERE SI.name IS NOT NULL
AND Schema_name(SO.schema_id) NOT LIKE 'sys'
AND SO.type = 'U'
OPEN curStats
FETCH NEXT FROM curStats INTO @DBName,
@SchemaName, @TableName,
@IndexName
WHILE @@FETCH_STATUS = 0
BEGIN
DECLARE @SQLCmd NVARCHAR(2000)
SELECT @SQLCmd =
'INSERT #STATS EXEC (' + CHAR(39) + 'DBCC SHOW_STATISTICS ('
+ CHAR(39) + CHAR(39) + @DBname + '.' + @SchemaName + '.' + @TableName
+ CHAR(39) + CHAR(39) + ',' + CHAR(39) + CHAR(39) + @IndexName + CHAR(39)
+ CHAR(39) + ') WITH STAT_HEADER JOIN
DENSITY_VECTOR' + CHAR(39) + ');'
--SELECT @SQLCmd
EXEC (@SQLCmd)
FETCH NEXT FROM curStats INTO @DBName,
@SchemaName, @TableName,
@IndexName
END
CLOSE curStats
DEALLOCATE curStats
GO
SELECT *
FROM #STATS
WHERE SAMPLE_PCT <> 100 OR
LAST_UPDATE_TIME < GETDATE()-1
ORDER BY TABLE_SCHEMA ASC, TABLE_NAME ASC, STATISTICS_NAME ASC, ORDINAL_POSITION ASC
SET NOCOUNT OFF
I know I'm a Geek @ heart and I do get that "Ooooh" moment when I find something different in a release (and I haven't just read it in a blog, book or another source)
One such moment occured last week, I'm in a Study group fro the MCM on Yammer ( https://www.yammer.com/sqlmcmstudygroup )
One of our Members: Matin Carins {who is a newly minted MCM @ that} Posted a question that got a lot of responses, I thankfully even managed to answer the question correctly
, it was to do with unshrinkable Trans logs .. answer is available in the thread if your intrested
Anyway my post here is that we used fn_dblog to review the contents of the Trans log and I tried the example Script that Martin posted up and ran this on a SQL 2008R2 and also my 2012 RC0 builds
The results clearly showed some speed improvements when run on 2012 RC0
(but this wasn't the main highlight for me .. that was that output of the fn_dblog)
The screen shot below shows the excact same Query that was run on the 2 builds.. both created a new database and inserted some dummy data to do the backup & Trans log shrink tests
Results on the LEFT are for the 2012 RC0 build (11.0.1750) and the results on the RIGHT are for the 2008 R2 Build (10.50.2500)
Noticed we have a new Column RecoveryUnitID (I haven't explored this one yet.. but will do so)
and also the query that provide the breakdown of operations has many more results {again intresting to investigate @ a later datetime when I have some spare time)
And finally the 2012 RC0 has less used pages (216 vs 256) and less active VLFs - so again this looks worthy of further investigations
Below are segments of the script that provided these results
DBCC SHRINKFILE(ActiveVLFDemo_Log,1,TRUNCATEONLY)
DBCC LOGINFO
SELECT Operation,COUNT(*) FROM fn_dblog(NULL,NULL)
GROUP BY
Operation HAVING
COUNT(*) > 1
ORDER BY
COUNT(*) DESC

In the word
of data – Cardinality issues is one issue you will already have encountered or
will do @ some stage, having statistical information up to date is vital for the
Query optimizer choosing a good query plan
So @ times you may have to explore
the Tuple Cardinality & Table Cardinality values
In the screen
shot below the top set of values is after a Statistics update has been run, set
below was the previous
UPDATE STATISTICS schemaname.tablename WITH FULLSCAN, INDEX

·
The TUPLE_CARDINALITY = TABLE_CARDINALITY for 1st
row {Note: This is a Clustered Primary Key index}
·
2nd - 4th records are for
another non-clustered index which has 2 columns
o 2nd
& 3rd rows represent these 2 columns (Notice the ORDINAL_POSITION)
o 4th
is the non-clustered internal CI key
·
TUPLE_CARDINALITY values had considerable different
values before/after the statistics update
o 2nd
row has TUPLE_CARDINALITY = 33
§
Matches the number of distinct values for leading key column
for nc index
o 3rd
rows has TUPLE_CARDINALITY = 1058
§
Matches the number of distinct values for both columns
in the nc index
o 4th
rows, TUPLE_CARDINALITY = 30496916
§
Previously was 229923 that’s just 0.75% of the table
rows ** That was
my Red flag **
§
After update it now Matches the number of distinct
values for CI key
So clearly something was not as accurate as it could be and the
clustered & non-clustered indexes tuples seemed to be a long way from the
values I expected them to be
The following code was used to capture these values
DROP TABLE
#STATS
GO
CREATE TABLE
#STATS
(
TABLE_CATALOG VARCHAR(128)
,TABLE_SCHEMA VARCHAR(128)
,TABLE_NAME VARCHAR(128)
,STATISTICS_CATALOG VARCHAR(128)
,STATISTICS_SCHEMA VARCHAR(128)
,STATISTICS_NAME VARCHAR(128)
,STATISTICS_TYPE INT
,COLUMN_NAME VARCHAR(128)
,COLUMN_GUID VARCHAR(128)
,COLUMN_PROPID VARCHAR(128)
,ORDINAL_POSITION INT
,SAMPLE_PCT INT
,LAST_UPDATE_TIME DATETIME
,NO_OF_RANGES INT
,COLUMN_CARDINALITY INT
,TUPLE_CARDINALITY INT
,TABLE_CARDINALITY INT
,AVG_COLUMN_LENGTH INT
)
GO
INSERT #STATS EXEC ('DBCC
SHOW_STATISTICS (''<dbname>.<schemaname>.<tablename>'',''<clusteredindexname>'')
WITH STAT_HEADER JOIN DENSITY_VECTOR');
INSERT #STATS EXEC ('DBCC SHOW_STATISTICS
(''<dbname>.<schemaname>.<tablename>'',''<nonclusteredindexname>'')
WITH STAT_HEADER JOIN DENSITY_VECTOR');
Just replace the values to suit your requirments
<dbname>.<schemaname>.<tablename>
<clusteredindexname>
<nonclusteredindexname>
I have used the DBCC SHOW_STATISTICS WITH
STAT_HEADER JOIN DENSITY_VECTOR other options are avialable, however these would not have
given me the information I wanted
-
WITH STAT_HEADER
-
WITH DENSITY_VECTOR
- WITH HISTOGRAM
I would look to evaluate the accuracy of the statistics on a
table as part of any performance troubleshooting, if values are not as expected
this may be an area to investigate further
This technique could also be used to gather statistics metrics
easily @ some regular intervals for baselining purposes
More Posts
Next page »