我正在尝试规范化我的数据库。我已经分解了所有冗余数据,现在正在加入和插入新数据。我一次移植了100万行,到目前为止一直运行良好。现在,一百万行需要花费几天而不是几分钟,而且似乎无法读取成千上万行,而且永远也无法到达插入部分。
我有这个查询:
INSERT IGNORE INTO bbointra_normalized.entry (DATE,keyword,url,POSITION,competition,searchEngine) SELECT DATE(insDate) AS DATE,k.id AS kid ,u.id uid, POSITION, competition ,s.id AS sid FROM oldSingleTabels.tempData
INNER JOIN bbointra_normalized.keyword k ON tempData.keyword = k.keyword
INNER JOIN bbointra_normalized.searchEngine s ON tempData.searchEngine = s.searchEngine
INNER JOIN bbointra_normalized.urlHash u ON tempData.url = u.url
GROUP BY k.id, s.id, u.id ORDER BY k.id, s.id, u.id
说明:
id select_type table type possible_keys key key_len ref rows Extra
------ ----------- -------- ------ -------------------------------------------- ------------ ------- ---------------------------- ------ ----------------------------------------------
1 SIMPLE s index (NULL) searchEngine 42 (NULL) 539 Using index; Using temporary; Using filesort
1 SIMPLE k index (NULL) keyword 42 (NULL) 17652 Using index; Using join buffer
1 SIMPLE tempData ref keyword_url_insDate,keyword,searchEngine,url keyword 767 func 433 Using where
1 SIMPLE u ref url url 767 oldSingleTabels.tempData.url 1 Using index
显示INNODB状态:
--------------
ROW OPERATIONS
--------------
0 queries inside InnoDB, 0 queries in queue
1 read views open inside InnoDB
Main thread process no. 4245, id 140024097179392, state: waiting for server activity
Number of rows inserted 26193732, updated 0, deleted 0, read 3383512394
0.00 inserts/s, 0.00 updates/s, 0.00 deletes/s, 39676.56 reads/s
输入SQL:
CREATE TABLE `entry` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`insDate` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
`date` int(11) NOT NULL,
`project` int(11) NOT NULL,
`keyword` int(11) NOT NULL,
`url` int(11) NOT NULL,
`position` int(11) NOT NULL,
`competition` int(11) NOT NULL,
`serachEngine` int(11) NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `unikt` (`date`,`keyword`,`position`,`serachEngine`)
) ENGINE=InnoDB AUTO_INCREMENT=201 DEFAULT CHARSET=utf8 COLLATE=utf8_swedish_ci;
最佳答案
尝试删除GROUP BY和ORDER BY子句,这些子句处理起来很繁琐,而且似乎没有添加任何值。
如果表bbointra_normalized.entry上有索引,请尝试暂时删除这些索引,因为在插入许多行时更新索引是一个繁重的过程。
关于mysql - SELECT每天读取5万行/秒,从不插入,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/20582055/