hi erland.... thank you and happy holidays to you
the pk is not indexed at all at the moment. i'm not strong on database
is a mistake.
queuedate. it is used
select on the table. is it better to leave out the index and let the
Erland Sommarskog wrote:
> Derek (gepetto_2000@yahoo.com) writes:
> > i have a table that has no index on a date column and a regular index
> > on a group_id and another on a customer_id column. the group_id will
> > be somewhat volatile, lots
> > of updates and and deletes on this table based on this column.
> > this is the design i inherited and i need a little advice.
> >
> > table:
> > orderqueue (id int identity primary key, group_id int, customer_id int
> > not null, queuedate
> > datetime not null default getdate())
> >
> > clustered index on queuedate (new index i was going to add)
> > non clustered index on customer_id
> > non clustered index on group_id
>
> You did not say whether PK is clustered or not. But both id and queuedate
> are good choices for clustered indexes, since they are monotonically
> growing. But maybe it's better to use the id, and leave out queuedate
> as an un-indexed to keep down the number of indexes. One advantage of
> this is that id is four bytes, and an index on queuedate is would be
> twelve bytes (datetime + uniqifier), so this keeps down the size of
> the NC indexes. (Recall that the clustered index key is the row locator
> for the NC indexes.)
>
> > queries being issued
> >
> > select * from orderqueue where customer_id is null order by queuedate
>
> I assume that the WHERE condition is "group_id IS NULL"? Else the
> query does not make much sense, since customer_id is not nullable.
>
> It seems to me that the query would be more efficient, if the process
> querying this table, tracks the last id. When you could add
>
> AND id > @last_id
>
> > update orderqueue set group_id = @group_id where group_id is null
>
> As well as for this query. (Which would bring a change, since in the
> current process, it appears that rows inserted after the SELECT would
> also be assigned a group_id.)
>
> > the updates/deletes will be about 2:1 to selects. i didn't want to
> > cluster on group_id/queuedate because i was afraid of blocking on
> > the updates to the cluster index page.
>
> Yes, you would get a lot of page moves this way, since you also would
> have to update the index on customer_id and id. So keeping group_id
> out from the clustered index is a good idea.
>
> > what is the effect on a cluster index when a non-clustered index column
> > is updated (e.g. group_id is set to a value)?
>
> None. Of course, the data page is updated, but the index as such is not
> affected.
>
> > looking at query plan for the update, the majority of the time is being
> > spent by an update in actual updating of the cluster index data page....
> > is that "good"? one test i ran showed about 35% of the time seeking
> > rows and 65% of the time doing a "Clustered Index Update/Update". it
> > was an update of 5 rows out of 15,000.
>
> It's probably a good thing if the update takes more time than seeking.
> That indicates that the indexes are good for locating the rows.
>
> --
> Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se
>
> Books Online for SQL Server 2005 at
>
http://www.microsoft.com/technet/prodtechnol/sql/2005/downloads/books.mspx > Books Online for SQL Server 2000 at
>
http://www.microsoft.com/sql/prodinfo/previousversions/books.mspx