vendredi 27 novembre 2015

SQLite: insert OR update and get field value causes performance hit

I create the table in SQLite:

CREATE TABLE IF NOT EXISTS abc (abcID INTEGER, primeK TEXT NOT NULL PRIMARY KEY, b INTEGER)

Also I build other tables:

CREATE TABLE IF NOT EXISTS ref0 (abcID INTEGER)
CREATE TABLE IF NOT EXISTS ref1 (abcID INTEGER)
.
.
.
CREATE TABLE IF NOT EXISTS refn (abcID INTEGER)

Later I want to :

  1. create new table refnn (abcID INTEGER)
  2. insert number of records into abc
  3. for every record -

    3.1 generate new abcID 3.2 if a record with given primeK already exists then I want to retrieve the existing field abcID and put it into refnn; 3.3 Otherwise - put generated abcID to refnn

Table abc is indexed by all of its values

I found that when I do not retrieve the existing abcID value then the UPDATE performs fast enough. When I add SELECT statement to retrieve the abcID then the performance deteriorate severely. How can I achieve these goals without significant performance hit?

Aucun commentaire:

Enregistrer un commentaire