Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Do I need an Index?

Status
Not open for further replies.

sheila11

Programmer
Joined
Dec 27, 2000
Messages
251
Location
US
Hi All,

My Stored Proc is returning results in about 20 milliseconds. Should I be placing an Index on the table that this SP is querying?

What is the duration that I can use as a benchmark, beyond which I should start adding Indexes to tables?

TIA,
Sheila
 
Try running this query

Code:
SELECT object_name(s.object_id) AS TableName, COL_NAME(s.object_id, sc.column_id) AS ColumnName,
		* 
	FROM sys.stats s
		JOIN sys.stats_columns sc ON s.object_id = sc.object_id AND s.stats_id = sc.stats_id
	WHERE object_name(s.object_id) NOT LIKE 'sys%' 
	ORDER BY 1,2

to see what indexes may be suggested by optimizer.
 
Thanks, Markros.

It gives me a list of over three hundred columns. Some of them are Primary Key ID columns.

I am surprised, because most stored procs are returning in less than 6 milliseconds. If the DB needed so many indexes, wdn't the Stored Procs have shown much poorer performance?

Sheila
 
The only way to know if a query needs an index added is to look at the execution plan. You could be querying a set of very large tables and have a query take 20 minutes when indexed.

Denny
MVP
MCSA (2003) / MCDBA (SQL 2000)
MCTS (SQL 2005 / SQL 2005 BI / SQL 2008 DBA / SQL 2008 DBD / SQL 2008 BI / MWSS 3.0: Configuration / MOSS 2007: Configuration)
MCITP (SQL 2005 DBA / SQL 2008 DBA / SQL 2005 DBD / SQL 2008 DBD / SQL 2005 BI / SQL 2008 BI)

My Blog
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top