Subject Re: [firebird-support] Large row count in tables
Author Aage Johansen
roar4711 wrote:
> ...
<<
Problem is that insert times are starting to take a long time, up to
4 minutes. Also upon startup a query is done to determine the last
added record (time wise, select MAX(Time) from XYZ), this also a
length process and very memory consuming (just a hair short of using
all of the 4 GB process space).
>>

I just saw Elkin's idea of a descending index on TIME, and that may
be a better solution than mine (but here goes, anyway)!:

No one is stopping you from adding a primary key!
If the max(time) is in the "last added record" this might be food for thought.
Let's say you
alter table XXX
add PK not null primary key
Then create a generator,
create generator GEN_XXX_ID
and a BeforeInsert trigger to fill the PK field.
Note: The "not null" can be a small hurdle - at least you have to
fill the PKs at once (before you make the next backup). Initial
filling can be done by
update XXX
set PK = gen_id(GEN_XXX_ID,1)

Now, to find the "last added record", you
select gen_id(GEN_XXX_ID,0) from rdb$database
which takes "no time" at all. Depending on which component set you
use, you may have even simpler ways to fetching the value.
You'll now have the primary key of the "last added" record.

OtToMH, untested, rather late ...

--
Aage J.