Subject Re: Mysterious timeout of exactly 60 seconds
Author Adam
Daniel,

Normally queries (or subselects) of the following form are unnecessary
and (relatively) expensive:

(select max(sortid) from table) + 1

It looks suspiciously similar to the function of a generator, but
instead of simply incrementing and fetching a value from a single
database page, it has to either

a) If a descending index exists on sortid, read that index from disk
(unless it is already in cache), then go and find the data page to
check that the max value is visible to your transaction etc.

or

b) Read every record from table and locate the largest sortid (which
is what I believe it was doing in your case, hence the exaggeration of
the slowdown as the table grew).

Now if the sole purpose of this column is to make sure that new
records default to the bottom (as your query implies), and to allow
you to move records up or down (order by sortid [desc]), then it does
not need to start at 1, nor does it matter if there are holes; a
generator will work fine and much faster.

Adam