Always Update: The Importance of Updating Sybase Statistics: Articles, Code and A Community of Database Experts
Always Update: The Importance of Updating Sybase Statistics: Articles, Code and A Community of Database Experts
SolarWinds - LogicalRead
HOME
SQL SERVER
ORACLE
DB2
SYBASE
VMWARE
SAP Sybase Adaptive Server Enterprise (ASE) uses a cost-based optimizer which balances the cost of finding the best query
execution plan with the costs of running the query in different ways. To do this, it checks a histogram that identifies the data
distribution, and uses this information to determine join orders, index selection, and more. You might think that the server would
keep this information up-to-date, but because of the resource cost, it does not. You will need to perform this critical task (updating
statistics) as often as your data skews.
NOTE
In high-volume environments, you can update statistics on a restored database, and then import them into the production server
using the optdiag utility, but thats a lot more work.
ASE provides a number of options for updating statistics, depending on the specific needs you have.
To update information about the distribution of key values in specified indexes, for all columns in an index, table, or partition, the
syntax is:
1 update
2
3
4
5
6
7
8
9
statistics table_name
[[ partitiondata_partition_name ] [ (column_list ) ] |
index_name[ partitionindex_partition_name ] ]
[ using step values ]
[ with consumers = consumers ][, sampling=Npercent ]
To update the statistics for all columns in an index, the syntax is:
To update all statistics information for a given table, the syntax is:
NOTE
To update statistics that are stored in systabstats table, such as rowcount, cluster ratios, and so on, the syntax is:
Performing update table statistics does not affect column statistics stored in sysstatistics.
We normally use update index statistics to get current statistics for all the columns in the indexes; we typically arent so concerned
about statistics for non-indexes columns (if youre going to search for something, index it, and if youre not going to search for
something, why use the resources to collect the statistics?)
Your situation, of course, may be different. Here are a few considerations when choosing which option will work best in your
circumstances:
1.
You can update statistics for a specific partition. This can be really useful if youre using semantic partitioning. Why?
Consider this: if you are partitioned by date, and have your most recent data on the current partition, you can choose to update
statistics for ONLY the more recent data, rather than the entire table of >1TB.
2.
You can update statistics for either a specific index or all of the indexes on a specific table. In general, you would run this
on an entire table; for very large tables, you can update statistics on just the columns that skew the most.
3.
You can change the number of histogram steps to create (the default is 20 steps). You can configure this at the server
level (new in late ASE 15). We typically build it into the scripts as a parameter so that changes of server-wide defaults at upgrade time dont undo our decision-making processes.
When you increase the steps, it changes the number of histogram points that the optimizer has to work with. When would you do
this? If you ever find your performance to be erratic, increasing the number of steps may be a good place to start.
Be sure to note that the random distribution of data doesnt imply a steady distribution of data; in practice, it often promises the
opposite.
1.
Using the consumers option, you can control the degree of parallelism, which can dramatically speed up the scans
(depending on whether youre already swamping your I/O subsystem). Of course, this is limited to the level of parallelism youve
already set up on your server.
2.
The sampling allows you to reduce the number of rows you have to scan in order to build the histogram. This can save a
lot of time if you have multi-terabyte tables or databases.
You can examine the statistics (including time since the last update) by querying the systabstats and sysstatistics table, or by using
the optdiag utility from the OS prompt.
Some have claimed the update statistics command causes blocking and contention. In earlier versions of ASE, this may have
sometime happened; however, in the newer releases of ASE, locking is minimal and this should not be a significant concern.
In general, if you are updating statistics for a table that has allpages locking defined, the server places an intent lock at the table
level, and a page lock on the page currently being scanned. (Locking level 1). Otherwise, it does not lock (that is, with dirty reads /
locking level 0).
As noted at the beginning, out-of-date statistics is a frequent cause of poor performance. Assess your circumstances and develop a
plan for keeping your statistics up to date, so that the query optimizer can do its job. Its more than worth the time youll invest.
FOLLOW LOGICALREAD
Contribute articles
Contact us
Give feedback
Home
SQL Server
Oracle
DB2
Sybase
VMware
About SolarWinds
Privacy Statement
Terms of Use