I have a SQL like this:
INSERT INTO table1 (column1, column2) (
SELECT column3, column4 FROM table2 WHERE column5 = 'value'
);
- The
table1has 3,500,000 rows. - The
table2has 900,000 rows. SELECT column3, column4 FROM table2 WHERE column5 = 'value'returns NO registers (ZERO) and takes ~0.004 seconds.INSERT INTO table1 (column1, column2) VALUES ('value', 'value')takes ~0.004 seconds as well.
But when I combine both in an INSERT INTO SELECT statement, as shown above, it takes ~7.7 seconds. Is there an explanation? And is there a solution?