Answer the question
In order to leave comments, you need to log in
How to compare two huge tables (3 and 2 million rows) and update one of them?
Good day! There is a main table with products for 4 million rows (6 GB) and a second table with an updated assortment (~ 3 million rows, 4 GB). Table type - InnoDB. The set of table fields is the same.
Main product table:
CREATE TABLE `items` (
`aid` int(11) AUTO_INCREMENT,
`id` varchar(100),
`id_shop` tinyint(4),
`name` text,
`description` text,
`enabled` tinyint(1),
... еще 20 полей ...
PRIMARY KEY (`aid`),
KEY `se` (`id_shop`,`enabled`),
... еще много индексов ...
) ENGINE=InnoDB AUTO_INCREMENT=43657573 DEFAULT CHARSET=utf8
INSERT INTO items (id, id_shop, name) VALUES ('1', '2', '3')
ON DUPLICATE KEY
UPDATE name = 'new_name', description = 'new description'
Answer the question
In order to leave comments, you need to log in
Need UNIQUE KEY (`id`, `id_shop`) The
request will be something like this:
INSERT INTO `items` (`id`, `id_shop`, `name`, `description`, ...)
SELECT `id`, `id_shop`, `name` AS `new_name`, `description` AS `new_description`, ...
FROM `new_items`
ON DUPLICATE KEY UPDATE `name` = `new_name`, `description` = `new_description`, ...
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question