做一個簡單的查詢像MySQL的很慢有20萬條記錄
select state, count(state) as cnt from big_data where status=0 group by state
大約需要20秒。這裏是我的表格def:
CREATE TABLE `NewTable` (`id` bigint(22) NOT NULL AUTO_INCREMENT ,
`city` varchar(32) CHARACTER SET latin1 COLLATE latin1_swedish_ci NOT NULL ,
`state` varchar(2) CHARACTER SET latin1 COLLATE latin1_swedish_ci NOT NULL ,
`miles_away` int(5) NOT NULL ,
`member_id` int(11) NOT NULL ,
`gender` varchar(17) CHARACTER SET latin1 COLLATE latin1_swedish_ci NOT NULL ,
`profile` varchar(128) CHARACTER SET latin1 COLLATE latin1_swedish_ci NOT NULL ,
`status` varchar(1) CHARACTER SET latin1
COLLATE latin1_swedish_ci NOT NULL ,
PRIMARY KEY (`id`,
`city`,
`state`,
`miles_away`,
`member_id`,
`gender`,
`profile`,
`status`),
UNIQUE INDEX `id` (`id`) USING BTREE ,
UNIQUE INDEX `profile` (`profile`) USING BTREE ,
INDEX `city` (`city`) USING BTREE ,
INDEX `state` (`state`) USING BTREE ,
INDEX `miles_away` (`miles_away`) USING BTREE ,
INDEX `member_id` (`member_id`) USING BTREE ,
INDEX `gender` (`gender`) USING BTREE ,
INDEX `status` (`status`) USING BTREE)
ENGINE=InnoDB
DEFAULT CHARACTER SET=latin1 COLLATE=latin1_swedish_ci
AUTO_INCREMENT=12889691
ROW_FORMAT=COMPACT;
即使是基於主鍵的簡單ID查找需要那麼長時間。我的服務器有72個內核(第4代至強ES2690與64GB RAM)
這裏解釋的截圖:
multi threads http://gaysugardaddyfinder.com/shot.PNG
幫助!
這不是從EXPLAIN輸出。運行'EXPLAIN選擇狀態,計數(狀態)...'。這將顯示優化程序在聲明中所做的事情。另外,表中的主鍵是表中的所有列是非常奇怪的,特別是當你已經有一個非空的列,它有一個唯一的約束('id'),可以作爲主鍵。 – spencer7593