mysql - SELECT 读取 50 000 行/s 几天从不插入

标签 mysql sql database-design database-migration

我正在尝试规范化我的数据库。我已经分解了所有冗余数据,现在正在加入并插入新数据。我一直在一次移植 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 子句,它们处理起来很繁重而且似乎没有增加任何值(value)。

如果表 bbointra_normalized.entry 上有索引,请尝试暂时删除这些索引,因为在插入许多行时更新索引是一个繁重的过程。

关于mysql - SELECT 读取 50 000 行/s 几天从不插入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20582055/

相关文章:

php - 按降序从表中删除一个值 PHP(可能吗?)

google-app-engine - Google App Engine Datastore 和其他 NoSQL 数据库的无模式设计指南

MongoDB - 多少数据是太多的数据?

php - 在 QUERY 中使用 strtotime

php - 如何将用户与最近的地址匹配?

php - 在 Laravel 中按数据透视表 created_at 排序

design-patterns - 数据库模式

php - Mysql,Php,Laravel 复选框错误

mysql - 对 2 列进行查询,就好像它们是一列一样

sql - 多个联合 MS Access