我有一个具有以下模式的表:
CREATE TABLE `wordtrend` (
`oid` bigint(20) NOT NULL AUTO_INCREMENT,
`monitorId` bigint(20) DEFAULT NULL,
`nGram` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
`nGramWord` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
`negatives` bigint(20) DEFAULT NULL,
`neutrals` bigint(20) DEFAULT NULL,
`positives` bigint(20) DEFAULT NULL,
`total` bigint(20) DEFAULT NULL,
`trendCut` datetime DEFAULT NULL,
PRIMARY KEY (`oid`)
) ENGINE=MyISAM
AUTO_INCREMENT=358539
DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci
是否可以创建索引以高效地运行以下查询?
SELECT nGram
, nGramWord
, SUM(total) AS sTotal
, SUM(positives)
, SUM(negatives)
, SUM(neutrals)
FROM WordTrend
WHERE monitorId = 21751021
AND trendCut >= '2011-01-01 00:00:00'
GROUP BY nGram
, nGramWord
ORDER BY sTotal DESC
我们已经尝试了以下操作:
KEY `RollupIndex` (`monitorId`,`trendCut`)
KEY `RollupIndex2` (`monitorId`,`nGram`,`trendCut`)
但是在额外的一列中,我们得到了"Using where;Using temporary;Using filesort“。提前谢谢。
发布于 2011-08-26 22:12:56
发布于 2011-08-26 22:31:25
您可以使用ORDER- 'ORDER BY sTotal DESC',因此在sTotal
字段上建立索引可能会有所帮助。
发布于 2011-08-27 03:10:05
尝试不同的组合键(nGram
、nGramWord
、total
)。
https://stackoverflow.com/questions/7205905
复制相似问题