Subject | Re: [firebird-support] Re: DB-Inserts slow after 5000 inserts (with select) |
---|---|
Author | Jens Saathoff |
Post date | 2011-06-15T17:00:02Z |
Hi!
Thank you all for your help. Its really nice to get some answers. :-)
Now, i made the UNQ on playername and provider_id, playername is the first.
After some testing it is the fastest option.
In my c++-code i use gen_id to get the id for the row to insert, after
removing that it is much faster.
After inserting all players i select the the id for each player that was
inserted and fill a std:map<string, int64> to hold the id for the player in
mem. That neccessary because it's much faster than selecting the id from db
on demand.
What can i do with "page buffer"? What it's useful for? Which value is the
best? What does it do?
Thank you very much. I'm a FB-beginner.
Jens
2011/6/15 Svein Erling Tysv�r <svein.erling.tysvaer@...>
Thank you all for your help. Its really nice to get some answers. :-)
Now, i made the UNQ on playername and provider_id, playername is the first.
After some testing it is the fastest option.
In my c++-code i use gen_id to get the id for the row to insert, after
removing that it is much faster.
After inserting all players i select the the id for each player that was
inserted and fill a std:map<string, int64> to hold the id for the player in
mem. That neccessary because it's much faster than selecting the id from db
on demand.
What can i do with "page buffer"? What it's useful for? Which value is the
best? What does it do?
Thank you very much. I'm a FB-beginner.
Jens
2011/6/15 Svein Erling Tysv�r <svein.erling.tysvaer@...>
>[Non-text portions of this message have been removed]
>
> At 11:05 AM 15/06/2011, Ann Harrison wrote:
> >>Jens,
> >>
> >>>> Example: SELECT id From PLAYER WHERE name='thename'
> >>>>
> >>>> If no record exists and the id returned is 0 i'm inserting the data.
> >>>>
> >>>> After 5000 inserts the inserts getting slow. I start with 2000 records
> >>>> in 10 seconds, after 5000 inserts it slows down to 100 records in 10
> >>>> seconds.
> >>
> >>
> >>You need an index on PLAYERNAME, or you need to make PLAYERNAME
> >>the first item in the unique constraint UNQ1_PLAYER. Firebird cannot use
> >>the second or subsequent columns in an index unless it has values for all
> >>the preceding columns.
> >
> >As Ann suggests....also consider the UPDATE OR INSERT syntax if you are
> using
> >Firebird 2.1 or higher (but *still* improve that index!)
>
> Another thing (unless you use UPDATE OR INSERT) is that using parameters
> and preparing once is far superior to issuing a new statement each time. So,
> rather than
>
> SELECT id From PLAYER WHERE name='thename';
> ...
> SELECT id From PLAYER WHERE name='anothername';
> ...
> SELECT id From PLAYER WHERE name='yetanothername';
> ...
>
> it is better to do
>
> SELECT id From PLAYER WHERE name=:name;
> Prepare;
> Params[0].AsString:='thename';
> First;
> ...
> Close;
> Params[0].AsString:='anothername';
> ...
> Params[0].AsString:='yetanothername';
> ...
>
> (of course, you'd typically do this in a 'while not eof' loop in most
> programming languages).
>
> By the way, I hope you either simplified your problem quite a bit or that
> it is a small system - it would be strange to be denied participating in any
> game due to another player having the same name as me (well, my name is
> unique, so I don't have that problem, but many names are shared by several
> persons on this globe).
>
> HTH,
> Set
>
>
>