Skip to Content
Author's profile photo Hakan Haslaman

How to troubleshoot a “record update” which takes to much time

  Some of the things that happen when an update occurs are the following:

  1. If unique indexes exist (e.g., primary key), verify that that the new key (if changed) is unique.
  2. If RI is involved, make sure no foreign key relationships are violated.
  3. If there are BEFORE (or INSTEAD OF) triggers, fire those triggers.
  4. Update each modified index key.
  5. Write the record to the table.
  6. If RI is involved (e.g., cascade operations) modify all “child” tables (and recurse downward as necessary).
  7. If AFTER triggers exist, fire those.
  8. If replication involved, write the record to the replication queue.
  9. Unlock the record if necessary

Of those things, the potentially expensive ones are triggers and RI. A trigger could obviously run a long time (it is user defined), but it would not typically block other operations. RI is relatively expensive, but one update should not typically take longer than another. 

Here is what might be happening:

  1. Some user A causes an large index scan on this table. An obvious way this could happen is by setting a filter that covers most/all of the index (e.g., a query/filter with EMPID > 1″ which would cover the entire table. Setting such an AOF could end up reading the entire index (while holding a read lock). Another possibility would be reading the table in index order while a restrictive filter is set. Scanning from one record to the next record that passes the filter could read a large number of index pages.
  2. While user A scans the index, user B updates the table. It would block on that index scan while waiting for the write lock.

If the index is highly fragmented, an index scan (the first time through) could be very expensive. Once the index is cached, subsequent operations would be much faster (probably).

If this is the problem, it would make sense to re-index the table. And you might consider using a larger index page size (if you are using ADT tables). A larger page size can help mitigate the cost of large index scans on fragmented indexes.

Assigned Tags

      Be the first to leave a comment
      You must be Logged on to comment or reply to a post.