SQL Server Central is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
Search:  
 
 

Index Statistics in SQL Server 7.0

By Alexander Chigrik, 2001/08/02

Total article views: 2923 | Views in the last 30 days: 1

SQL Server 7.0: Index Statistics Details

Alexander Chigrik
chigrik@hotmail.com


Introduction
Distribution Statistics
View Distribution Statistics
Update Distribution Statistics


Introduction

Sometimes it is difficult to determine which indexes to use when
processing a query. In this case, the query optimizer uses distribution
statistics.

SQL Server 7.0 can update distribution statistics automatically, so
in most cases it is not necessary to update distribution statistics
manually and you can rely on SQL Server decisions to update
distribution statistics.

In this article, I want to tell you about distribution statistics,
and about how you can view and update distribution statistics.

Distribution Statistics

In comparison with SQL Server 6.5, there are no distribution pages in
SQL Server 7.0: distribution statistics are stored as a long string of
bits across multiple pages in the same way image data is stored.
The pointer to to this distribution data is stored in the statblob
column in the sysindexes table.

The distribution statistics are used to determine which indexes to
use when processing a query or it is not possible to use an index and
the full table scan will be made.

SQL Server 7.0 can update distribution statistics automatically, so
it is not longer necessary to run UPDATE STATISTICS statement to
update statistics manually. The SQL Server decides to update
distribution statistics automatically by analyzing the value in the
rowmodctr column in the sysindexes table.

Now distribution statistics can store the statistics information not
only for the first column in index and not only for the indexed columns.
You can create the distribution statistics for unindexed columns with
the CREATE STATISTICS statement.

You can view or change the automatic UPDATE STATISTICS setting with
sp_autostats stored procedure. By default, SQL Server 7.0 will
automatically update distribution statistics.

View Distribution Statistics

You can use DBCC SHOW_STATISTICS statement to display the current
distribution statistics for the specified target on the specified
table.

This is the syntax:

DBCC SHOW_STATISTICS (table, target)
where table - is the table with which the index is associated. target - is the name of the object (index name or collection) for which to display statistics information. This is the example to view the index statistics for the aunmind index from the authors table in the pubs database:
USE pubs
GO
DBCC SHOW_STATISTICS (authors, aunmind)
GO

Update Distribution Statistics

To update distribution statistics, you can use UPDATE STATISTICS
statement.

This is the syntax (from SQL Server Books Online):

UPDATE STATISTICS table
    [
        index
        | (statistics_name[,...n])
    ]
    [    WITH
        [
            [FULLSCAN]
            | SAMPLE number {PERCENT | ROWS}]
        ]
        [[,] [ALL | COLUMNS | INDEX]
        [[,] NORECOMPUTE]
    ]
This is the example to update distribution statistics for the aunmind index from the authors table in the pubs database:
USE pubs
GO
UPDATE STATISTICS authors aunmind
GO
For more information, see: UPDATE STATISTICS (T-SQL) Notes 1. If you set to not automatically recompute distribution statistics, then you should manually run UPDATE STATISTICS statement periodically (when a large amount of data in an indexed column has been added, changed, or deleted). 2. After running TRUNCATE TABLE statement, the distribution statistics will also be deleted, so if you set to not automatically recompute statistics, then after adding new data, you should manually run UPDATE STATISTICS statement to recreate distribution statistics.

By Alexander Chigrik, 2001/08/02

Total article views: 2923 | Views in the last 30 days: 1
Your response
 
 
 
Like this? Try these...

Introducing IQReference

By Steve Jones | Category: Product Reviews
(not yet rated) | 3,120 reads

Reminiscing

By Steve Jones | Category: Miscellaneous
| 5,718 reads
Already registered?  

Free registration required

To read the rest of this article, and access thousands of other articles, we ask you to register on the site and subscribe to our newsletters.

Register

E-mail address:
Password:
Password (confirm):

  

Subscriptions

We ask you to register on the site and subscribe to our newsletters. Subscribing to our newsletters gets you:

  • ALL of our content (thousands of articles, scripts, and forum postings)
  • A daily newsletter (example)
  • A weekly news round up (example)
  • The opportunity to ask and answer questions in our forums
  • A daily Question of the Day to test and help you increase your knowledge of SQL Server.

We ask that you give the newsletter a try for a week. Over 200,000 SQL Server Professionals a day find it entertaining and useful. If not, you are welcome to unsubscribe at anytime.

Steve Jones
Editor, SQLServerCentral.com