Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Index on Tables

Author  Topic 

satya068
Posting Yak Master

233 Posts

Posted - 2010-05-11 : 10:42:32
Hi,,

could anyone help me how to identify which tables in your database may need indexes?

in my databse there are 200 tables each contains aroud 15 columns and more than 1 million records in each table,now i need to increase the performance of the databse.


i have been through BOL but still struggling to solve the above quiers.

thanx

Satya

AndrewMurphy
Master Smack Fu Yak Hacker

2916 Posts

Posted - 2010-05-11 : 10:53:50
start with your msot actively used queries - use Profiler to identify these.
....and look at the "explain plan"s which indicate how they are executing. post some samples here and we can comment & educate you.
Go to Top of Page

satya068
Posting Yak Master

233 Posts

Posted - 2010-05-11 : 11:04:03
Hellow Andrew,

can i know know how to use profiler to identify the tables which required index please?

Satya
Go to Top of Page

AndrewMurphy
Master Smack Fu Yak Hacker

2916 Posts

Posted - 2010-05-12 : 07:14:08
Profiler can trace all activity on SQL. Use the generated trace to find "common" queries. Use business knowledge to identify "important" queries....and then use that information to prioritise which queries you tune.

Profiler itself will not tell you what needs tuning. There is a "wizard/utility" that will help but it's "advice" should be taken with a pinch of salt. Proper tuning will only come from education, experience and testing. We can help somewhat with the first of these if you follow my previosu advice...i.e post the execution/explain plans.
Go to Top of Page

denis_the_thief
Aged Yak Warrior

596 Posts

Posted - 2010-05-12 : 13:03:25
Indexing foreign Keys is a good one since that is what you usually join on. And may make deleting faster.

Try out this nasty Query for creating indexes on unindexed Foreign Keys! I think it only looks at one column of the FK.

select
'CREATE NONCLUSTERED INDEX [IX_' + table_name + '_' + name +'] ON [dbo].[' + table_name + '] ([' + name + '] ASC)',
*
from
(
select
object_name(object_ID) Table_Name,
object_name(Referenced_object_ID) Referenced_Table_Name,
(SELECT max(si.row_count) FROM sys.dm_db_partition_stats si
WHERE si.object_ID = T.object_ID and si.index_id < 2) Table_Count,
(SELECT max(si.row_count) FROM sys.dm_db_partition_stats si
WHERE si.object_ID = Referenced_object_ID and si.index_id < 2) Referenced_Table_Count,
*
from
(
select
(select max(referenced_object_ID) from sys.foreign_key_columns FKC
where FKC.parent_object_ID = C.object_ID and
FKC.Parent_Column_ID = C.Column_ID) referenced_Object_ID,
case
when exists
(select 1 from sys.index_columns IC
where C.Object_ID = IC.Object_ID and
C.Column_ID = IC.column_ID and Index_Column_ID = 1) then 1
else 0
end Indexed,
*
from
sys.columns c
where
exists
(select 1 from sys.foreign_key_columns FKC
where FKC.parent_object_ID = C.object_ID and
FKC.Parent_Column_ID = C.Column_ID)
) T
) T
where
Indexed = 0 and Table_Count > 1000 and Referenced_Table_Count > 1000
order by
Table_Count * power(Referenced_Table_Count, 0.7) desc
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2010-05-12 : 13:38:31
I use this a lot: http://sqlserverpedia.com/wiki/Find_Missing_Indexes

You have to be very careful with the output though. Only consider those with an impact over 1000000. Make sure you don't add "duplicate" indexes, and make sure that SQL Server has been up for a while when running the report since the DMVs get cleared after a restart.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

denis_the_thief
Aged Yak Warrior

596 Posts

Posted - 2010-05-12 : 14:02:42
quote:
Originally posted by tkizer

I use this a lot: http://sqlserverpedia.com/wiki/Find_Missing_Indexes

You have to be very careful with the output though. Only consider those with an impact over 1000000. Make sure you don't add "duplicate" indexes, and make sure that SQL Server has been up for a while when running the report since the DMVs get cleared after a restart.

Tara Kizer




Yes, I found this DMV helpful too. But not sure if it was just me but I had a lot of problems with it.

Advantages:
- SQL Server keeps track of this automatically - unlike Profiler or Wizard that you have to run
- Takes into consideration how often the indexed would be used - unlike my query above

Disadvantages (at least that I ran into)
- For some reason ignores simply queries (anyone know why?)
- Gave me a lot of variations of the same index
- Cost improvements are just estimates
- Sometimes even suggested adding an index that already existed!
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2010-05-12 : 14:43:21
I agree it has disadvantages, especially the variations of the same index (that's why I mentioned the "duplicate" issue in my last post). It really takes a good DBA to decide which indexes to actually add based upon the DMV output.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

denis_the_thief
Aged Yak Warrior

596 Posts

Posted - 2010-05-12 : 15:05:54
quote:
Originally posted by tkizer

I agree it has disadvantages, especially the variations of the same index (that's why I mentioned the "duplicate" issue in my last post). It really takes a good DBA to decide which indexes to actually add based upon the DMV output.





Has it ignored the simplier queries for you?

Any idea why would it ignore the simple queries? After all, a simple query between 2 huge tables with a missing index is important.
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2010-05-12 : 15:22:44
I haven't noticed it, but I think I read that this is a bug.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page
   

- Advertisement -