Subject Re: [ib-support] Select max(id) is slow ?
Author Ann W. Harrison
At 11:48 AM 9/18/2001 +0200, Carsten Schäfer wrote:

>Now i want to put the new id that is given from the generator in my
>object that was inserted.

At the moment, the only way to do that is to change your trigger
so that it only adds the primary key if that field is null - that's
just for insurance and to take care of cases when they key isn't
needed. Set up a procedure to invoke the generator and use
that procedure from your program to get the value for the primary key.


>I use 'select max (id_apos) from t_apos' to get the highest id from
>the table (insert and select in one transaction).

First, yes that is slow. InterBase reads every row to get the MAX
unless you have a descending index on the field. Second, it's not
reliable, especially if you use the read-committed transaction mode.
Someone else may have stored a row after yours, and you'll get that
number rather than the one you stored.


Regards,

Ann
www.ibphoenix.com
We have answers.