0
\$\begingroup\$

After populating the stock_tmp table, i'm running these SQL queries via legacy mysqli wrapper code. I don't think this code needs additional locks to prevent people from seeing incorrect data. Is that correct?

DELETE FROM stock WHERE ean NOT IN (SELECT ean FROM stock_tmp);
REPLACE INTO stock SELECT * FROM stock_tmp;
\$\endgroup\$

1 Answer 1

1
\$\begingroup\$
INSERT INTO stock SELECT * FROM stock_tmp AS tmp
ON DUPLICATE KEY UPDATE ean=tmp.ean, etc=tmp.etc;

Is 10+% faster than REPLACE INTO and does not change all AUTO_INCREMENT data. Source.

10+ times faster is this:

RENAME TABLE stock TO stock_swp,
stock_tmp TO stock,
stock_swp TO stock_tmp;

The implied locking should be sufficient in any case.

\$\endgroup\$

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.