Technical Note #16: Index Tuning
Technical Note #16: Index Tuning
com
Index Tuning
This TechNote discusses general methods for tuning indexes for better
performance in Siebel applications using SQL Server.
In general clustered indexes tend to be the most efficient types of indexes for a
number of reasons. For example, if the query causes data to be scanned, then
there are no extra reads from the index page to the data page. See SQL Server
Books Online for a more detailed explanation. Non-clustered indexes tend to be
more efficient for seek type queries and index covering techniques.
CAUTION Your business is allowed to remove indexes on the EIM_* tables. Adding or changing a base
table index requires Siebel approval. Consult with Siebel Expert Services when you need to add or change
a base table index. Siebel can detect if base table indexes have changed by running the utility dbchck which
compares the Siebel data dictionary to the SQL Server data dictionary. If changes have been made without
Siebel approval, your warranty may be voided.
Tools
There are a number of tools that help with performance tuning and optimizing.
Profiler: SQL Profiler gives a SQL Server kernel view of the query. It is a
powerful tool, and should be used carefully because it can use a lot of CPU. The
results should be saved to a file. This file can be created as a table and analyzed.
Filter on the SPID or CLIENT PROCESS.
Trace: Level 8 EIM Trace shows network times. It does not display plans, and
does not always show the hints used.
Index Tuning Wizard: The Index Wizard will not suggest better indexes when
it is used with Siebel databases. Siebel builds indexes for nearly every possible
configuration. It does show what indexes are being used. With this information
you can deduce which indexes are not being used.
Query Analyzer: SQL Query Analyzer gives a SQL Server kernel view of the
query and can be run from the command prompt with isqlw.exe.
There are several tools within the SQL Query Analyzer that are useful:
• SET STATISTCIS PROFILE shows the plans with their costs
• SET STATISTICS IO shows the only the io.
• DBCC DBREINDEX reorganizes indexes. See the section on fragmentation
below for a query that generates DBCC commands.
Microsoft Technical Champs for Siebel www.siebelonmicrosoft.com
-- si.indid = 1
select count(*)
from sysobjects
where
name like 'S_%'and
type = 'U'
-- 1172 tables
-- remove every thing out of the temp table that is not a clustered index
select *
from
(
(
#all_idx as a right outer join sysobjects as so
on
-- outer join and match ones that DO and DO NOT match into one
-- result set
a.name=so.name)
)
where
-- just give me tables
so.type = 'U' and
-- just pull out the siebel tables
so.name like 'S_%' and
-- just show me the ones without a clustered index. --- it "is null"
-- because it does not exist in the temp table.
a.name is NULL
order by
-- sort by name
so.name
UPDATE dbo.S_INSITM1_FN_IF
SET T_INS_ITEM__UNQ = 'Y'
FROM dbo.S_INSITM1_FN_IF T1
WHERE (T_INS_ITEM__EXS = 'Y' AND
(SELECT MIN(ROW_ID)
FROM dbo.S_INSITM1_FN_IF T2
WHERE (T2.T_INS_ITEM__EXS = 'Y' AND
Microsoft Technical Champs for Siebel www.siebelonmicrosoft.com
*/
sp_help S_INSITM1_FN_IF
/*
S_INSITM1_FN_IF_U1
clustered, unique located on SIEB_DATA
T_INSITEMCO_INSITE, T_INSITEMCO_CONTAC, IF_ROW_STAT_NUM, T_INSITEMCO__STA, MS_IDENT
S_INSITM1_FN_IF_original_U1
non-clustered, unique located on SIEB_IND
IF_ROW_BATCH_NUM, ROW_ID
*/
sp_help S_INSITM1_FN_IF
/*
S_INSITM1_FN_IF_U1
clustered, unique located on SIEB_DATA
T_INSITEMCO_INSITE, T_INSITEMCO_CONTAC, IF_ROW_STAT_NUM, T_INSITEMCO__STA, MS_IDENT
S_INSITM1_FN_IF_FEM000
non-clustered, unique located on SIEB_IND
T_INS_ITEM__RID, ROW_ID, T_INS_ITEM__EXS, IF_ROW_BATCH_NUM, IF_ROW_STAT_NUM,
T_INS_ITEM__STA
S_INSITM1_FN_IF_original_U1
non-clustered, unique located on SIEB_IND
IF_ROW_BATCH_NUM, ROW_ID
*/
Index Covering
Index covering is a term used when an index contains all the columns in the
ORDER BY and WHERE clauses from a query. With index covering, the query can
find all columns needed to satisfy the query in the index page and it does not
have to access the data page.
Here is an example of a query that can be improved with index covering:
SET STATISTICS IO ON
GO
SET STATISTICS PROFILE ON
GO
Set
SELECT MIN(A)
FROM TAB_0
WHERE
X=’12’ AND
Y=’M’ AND
Z > 58
These queries show that the index is not selective. You will also see this in DBCC
SHOW_STATISTICS as well.
Column X has the most distinct values in the query, (582,938 in a table with
582,959 rows), but it doesn't appear in the index.
To create an index with index covering:
create index TAB_0_NC0 on TAB_0(X,Z,Y,A)
Column X is first in the index so that SQL Server can seek the information rather
than scanning the index for a range of values and then going to the data page
and retrieving the remainder of the result set.
Microsoft Technical Champs for Siebel www.siebelonmicrosoft.com
It could very easily be “cheaper” for the database to scan the 100% NULL non-
clustered index than to table scan all the data pages of the table.
Generally speaking, 100% NULL indexes will probably never be used, but there
are always exceptions to the rule. Set a bench mark before removing the 100%
NULL index, then use SQL Server Profiler to help diagnose long running queries
and see if it’s needed to put the 100% NULL index back.
Since many indexes could be 100% NULL, you need to focus on just the large
tables that may yield the best results.
To find the tables with the most rows, run the following query:
Select top 100 object_name(id), rows
From sysindexes
Where object_name(id) like ‘S_%’
Order by rows desc
Go
This query will show you the top 100 Siebel tables with the most rows.
To find which indexes are 100% NULL:
UPDATE STATISTICS on the table with FULL SCAN
Microsoft Technical Champs for Siebel www.siebelonmicrosoft.com
Note: See Books Online for specific syntax on the DBCC and SP_ commands
If both results are the same, then you know that every value in that column is
NULL.
dbcc show_statistics(s_fn_need, 2)
where
object_name(si.id) like 'S_%' and
rows > 2000
-- order by object_name(si.id)
order by rows
go
Supplemental Reading
TechNote 6 - Index Creation Performance During Data Loading
SQL Server Books-On-Line