Clustered index update

  • Hi

    On our website when someone views a members image we update a field called visits which is just a counter that shows how many times an image has been viewed.

    The sql statement looks like this : -

    update images set visits=visits+1 where (username=@username) AND (mykey=@mykey)

    However I have noticed that looking at the execution plan a clustered index update is taking place which is taking up 86%.

    Anyone know why this might be?

    Thanks

    Matt

  • The "clustered index" is, for all intents and purposes, the table itself. I would expect that to the majority of the work on a simple update.

    In other words, this is normal and expected.

    You'll want to take a look at how clustered indexes work. If you'll be administering or performance tuning, you'll need to know about them.

    - Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC
    Property of The Thread

    "Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon

  • Also be aware that the execution plan adds up to 100%, so something will take up resources. If you have the index on fields that the update can use, then the resource usage should be minimal.

  • Also, also, be cognizant of the fact that just becuase you have a high cost in an execution plan, doesn't mean that the process itself is very high cost. Execution plan costs are just estimates and do not represent measures that you can use to determine performance.

    "The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood"
    - Theodore Roosevelt

    Author of:
    SQL Server Execution Plans
    SQL Server Query Performance Tuning

  • Thanks for all your replies

Viewing 5 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic. Login to reply