sql - Is there any performance penalty with using INSERT OR REPLACE followed by a SELECT? -


i have 2 tables phraseid primary key in both , modified number of seconds since 1970. modified part of data load not required unless makes updating easier. if can without use insert or replace

phrasesource columns phraseid, text, modified phrase       columns phraseid, text, modified 

the phrasesource table contains 5010 rows (some new , changed rows) phrase table contains 5000 rows. update phrase table new , changed rows phrasesource. note application doesn't need show modified data added in case make easier inserting or updating.

here's came with. can let me know if way update , insert.

 insert or replace phrase(phraseid, text)  select ps.phraseid, ps.text phrasesource ps 

if there's better way (perhaps using modifed column contains number of seconds since 1970 when row last modified @ source) appreciate suggestions.

5000 rows nothing; delete , copy entire table.

if want minimize amount of changes written, can done modified column: first delete rows older, copy on new rows:

delete phrase modified < (select modified                   phrasesource                   phraseid = phrase.phraseid);  insert or ignore phrase(phraseid, text, modified) select phraseid, text, modified phrasesource; 

without modified, same can done comparing actual values:

delete phrase text not (select text                    phrasesource                    phraseid = phrase.phraseid);  insert or ignore phrase(phraseid, text) select phraseid, text phrasesource; 

Comments

Popular posts from this blog

python - How to insert QWidgets in the middle of a Layout? -

python - serve multiple gunicorn django instances under nginx ubuntu -

module - Prestashop displayPaymentReturn hook url -