The structure of the new_table
is that it will never insert new rows, but will only update the existing ones.
Currently I am using the following query. Is there any way to optimize this (in terms of performance) to achieve faster updates of the rows?
INSERT INTO new_table (hash, pages, visits, last_visit)
SELECT A.hash, COUNT(B.id), A.visits, MAX(B.timestamp)
FROM audience A
JOIN behaviour B ON B.hash = A.hash
GROUP BY A.hash
ON DUPLICATE KEY UPDATE
new_table.pages=VALUES(pages),
new_table.visits=VALUES(visits),
new_table.last_visit=VALUES(last_visit)