Subject Re: [firebird-support] Re: DB-Inserts slow after 5000 inserts (with select)
Author Ann Harrison
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.


> This is the METADATA for the table:
>
> SET SQL DIALECT 3;
>
>
>
> /******************************************************************************/
> /***                                 Tables                                 ***/
> /******************************************************************************/
>
>
> CREATE GENERATOR GEN_PLAYER_ID;
>
> CREATE TABLE PLAYER (
>    PLAYERID           BIGINT NOT NULL,
>    PLAYERNAME         VARCHAR(255) NOT NULL,
>    PROVIDER_ID        INTEGER default -1 NOT NULL,
>    ISOWNPLAYER        SMALLINT DEFAULT 0 NOT NULL,
>    TOURNEYREALSYMBOL  SMALLINT DEFAULT 0 NOT NULL,
>    TOURNEYPMSYMBOL    SMALLINT DEFAULT 0 NOT NULL,
>    CASHREALSYMBOL     SMALLINT DEFAULT 0 NOT NULL,
>    CASHPMSYMBOL       SMALLINT DEFAULT 0 NOT NULL
> );
>
>
>
>
> /******************************************************************************/
> /***                           Unique Constraints                           ***/
> /******************************************************************************/
>
> ALTER TABLE PLAYER ADD CONSTRAINT UNQ1_PLAYER UNIQUE (PLAYERID,
> PLAYERNAME, PROVIDER_ID);
>
>
> /******************************************************************************/
> /***                              Primary Keys                              ***/
> /******************************************************************************/
>
> ALTER TABLE PLAYER ADD CONSTRAINT PK_PLAYER PRIMARY KEY (PLAYERID);
>
>
> /******************************************************************************/
> /***                              Foreign Keys                              ***/
> /******************************************************************************/
>
> ALTER TABLE PLAYER ADD CONSTRAINT FK_PLAYER_PROVIDER FOREIGN KEY
> (PROVIDER_ID) REFERENCES PROVIDER (PROVIDERID);
>
>
> /******************************************************************************/
> /***                                Triggers                                ***/
> /******************************************************************************/
>
>
> SET TERM ^ ;
>
>
>
> /******************************************************************************/
> /***                          Triggers for tables                           ***/
> /******************************************************************************/
>
>
>
> /* Trigger: PLAYER_BI */
> CREATE OR ALTER TRIGGER PLAYER_BI FOR PLAYER
> ACTIVE BEFORE INSERT POSITION 0
> AS
> BEGIN
>  IF (NEW.PLAYERID IS NULL) THEN
>    NEW.PLAYERID = GEN_ID(GEN_PLAYER_ID,1);
> END
> ^
>
>
> SET TERM ; ^
>
> 2011/6/14 Jens Saathoff <jensesaat@...>:
>> Hi!
>>
>> In my app i use firebird and the ibpp-c++-api for firebird. I'm
>> importing data from files. There is an import-routine, that first
>> checks if a row already exists.
>>
>> 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.
>>
>> Is the problem the select statement before?
>>
>> Any suggestions or ideas?
>>
>> Thank you very much!
>>
>
>
> ------------------------------------
>
> ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
>
> Visit http://www.firebirdsql.org and click the Resources item
> on the main (top) menu.  Try Knowledgebase and FAQ links !
>
> Also search the knowledgebases at http://www.ibphoenix.com
>
> ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
> Yahoo! Groups Links
>
>
>
>