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
 General SQL Server Forums
 Database Design and Application Architecture
 indexes help

Author  Topic 

esthera
Master Smack Fu Yak Hacker

1410 Posts

Posted - 2007-01-30 : 01:36:37
I'm noticing my queries are slower.
i want to try to improve performance

will indexes help if there are specific fields that I search by often?
can you recommend an article that explains this?

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-01-30 : 01:41:59
quote:
Originally posted by esthera

will indexes help if there are specific fields that I search by often?
YES!
If you can afford the space, create a covering/covered index. This will make the SELECTs very fast, but DELETEs and UPDATEs much slower because the index need to be recalculated.

A covering/covered index contains all the columns present in the most frequent query.


Peter Larsson
Helsingborg, Sweden
Go to Top of Page

esthera
Master Smack Fu Yak Hacker

1410 Posts

Posted - 2007-01-30 : 01:49:57
my problem is that this is a very active db --- inserts are very often. -- selects are also often. deletes and updates much less -- will the above affect the inserts?

how do I go about doing this?
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-01-30 : 02:02:03
It depends what the INSERTs are. If you for example has a clustered index, and only new records are inserted (in the meaning of no backdating), the covered index is still fast, because the index as expanded only at the end and data is added.
If inserts is "in the middle" of the index, the index has to be reorganized every now and then.

Try to create an index for the columns at least in the WHERE clause.


Peter Larsson
Helsingborg, Sweden
Go to Top of Page

esthera
Master Smack Fu Yak Hacker

1410 Posts

Posted - 2007-01-30 : 02:28:41
how do I create indexes from enterprise manager and wuold this be clustered or unclusetered?
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-01-30 : 02:31:57
It depends on the frequence of the SELECTs vs the frequence of the INSERTs.
If you have only one column in the WHERE part, try to make that column as clustered.

In EM, you simply right-click the table and select DESIGN TABLE.
Now click the "Table And Index properties" button in the toolbar. Switch to the "Indexes/Keys" tab.


Peter Larsson
Helsingborg, Sweden
Go to Top of Page

esthera
Master Smack Fu Yak Hacker

1410 Posts

Posted - 2007-01-30 : 04:42:09
so i can have as many clustered indexes as I need (say if I put 4 columns for this table that is often search)
this will slow down inserts or not?
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-01-30 : 05:16:38
Only one clustered index per table is allowed.


Peter Larsson
Helsingborg, Sweden
Go to Top of Page

esthera
Master Smack Fu Yak Hacker

1410 Posts

Posted - 2007-01-30 : 05:30:10
so what's the difference between clustered adn unclustered?
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-01-30 : 05:48:45
Copied from Books Online
quote:
Using Clustered Indexes
A clustered index determines the physical order of data in a table. A clustered index is analogous to a telephone directory, which arranges data by last name. Because the clustered index dictates the physical storage order of the data in the table, a table can contain only one clustered index. However, the index can comprise multiple columns (a composite index), like the way a telephone directory is organized by last name and first name.

A clustered index is particularly efficient on columns that are often searched for ranges of values. After the row with the first value is found using the clustered index, rows with subsequent indexed values are guaranteed to be physically adjacent. For example, if an application frequently executes a query to retrieve records between a range of dates, a clustered index can quickly locate the row containing the beginning date, and then retrieve all adjacent rows in the table until the last date is reached. This can help increase the performance of this type of query. Also, if there is a column(s) that is used frequently to sort the data retrieved from a table, it can be advantageous to cluster (physically sort) the table on that column(s) to save the cost of a sort each time the column(s) is queried.

Clustered indexes are also efficient for finding a specific row when the indexed value is unique. For example, the fastest way to find a particular employee using the unique employee ID column emp_id is to create a clustered index or PRIMARY KEY constraint on the emp_id column.



Note PRIMARY KEY constraints create clustered indexes automatically if no clustered index already exists on the table and a nonclustered index is not specified when you create the PRIMARY KEY constraint.


Alternatively, a clustered index could be created on lname, fname (last name, first name), because employee records are often grouped and queried in this way rather than by employee ID.


Peter Larsson
Helsingborg, Sweden
Go to Top of Page

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2007-01-30 : 05:49:33
Why don't you google it. There are numerous links on this topic out there.

Harsh Athalye
India.
"The IMPOSSIBLE is often UNTRIED"
Go to Top of Page

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2007-01-30 : 10:36:39
if you're using sql server 2005
look into
INCLUDE ( column [ ,... n ] )
part of the create index statement.

it lets you add columns to the leaf level of the nonclustered index.
this way you don't need a covering index while maintaining the speed.



Go with the flow & have fun! Else fight the flow
blog thingie: http://weblogs.sqlteam.com/mladenp
Go to Top of Page
   

- Advertisement -