Subject | Re: [ib-support] Select max(id) is slow ? |
---|---|
Author | Lucas Franzen |
Post date | 2001-09-18T11:16:13Z |
Carsten Schäfer schrieb:
a) you can't be sure that select max ( id ) will return the value of the
inserted record, it will just return the value of the LAST inserted
record which might be a different one as you inserted.
b) the primary key is a ascending index, so MAX will be slow since it to
read all records of the table to get the higest value; if you ant to
speed it up, add a descending index on that field.
c) if you want to use the new id field for other pruposes (as adding
detail records), get the id on the client side and NOT on the server
side.
Hth
Luc.
>I'm not sure if I understand what you're doing.
> Hi,
> I have a normal auto-increment primary key (id_apos) on a table
> t_apos
> (generator gen_apos that is used in a before insert trigger).
> Now i want to put the new id that is given from the generator in my
> object that was inserted.
> I use 'select max (id_apos) from t_apos' to get the highest id from
> the table (insert and select in one transaction).
> This seems to be relative slow. (PLAN (T_APOS NATURAL)).
> Can i get the max(id_apos) somehow faster ? (query on the generator,
> stored procedure that returns the max(id_apos))
> I'm using Firebird Beta2 on Win2kSP2 with InterClient 2.
a) you can't be sure that select max ( id ) will return the value of the
inserted record, it will just return the value of the LAST inserted
record which might be a different one as you inserted.
b) the primary key is a ascending index, so MAX will be slow since it to
read all records of the table to get the higest value; if you ant to
speed it up, add a descending index on that field.
c) if you want to use the new id field for other pruposes (as adding
detail records), get the id on the client side and NOT on the server
side.
Hth
Luc.
>
> gruse
> Carsten
>
>
> To unsubscribe from this group, send an email to:
> ib-support-unsubscribe@egroups.com
>
>
>
> Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/