- 下面的查询需要很长时间才能执行大约 2 分钟,请帮助我如何提高此查询的性能。
- 所以我们的要求是在 2 到 3 秒内得到结果。
- 查询也使用索引。
- 但它正在执行更多扫描。
询问:
select max(`log_date`)
from `top_competitor_summary_entity`
where
own_domain_id = 4
and keyword_top1_count > 0
and (grouptag_id = 0 OR grouptag_id is null);
解释计划:
+----+-------------+-------------------------------+------+--------------------------------------+------------------------+---------+-------+---------+-------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+-------------------------------+------+--------------------------------------+------------------------+---------+-------+---------+-------------+
| 1 | SIMPLE | top_competitor_summary_entity | ref | own_domain_id,own_domain_id_log_date | own_domain_id_log_date | 4 | const | 2100128 | Using where |
+----+-------------+-------------------------------+------+--------------------------------------+------------------------+---------+-------+---------+-------------+
1 row in set (0.66 sec)
表结构:
mysql> show create table top_competitor_summary_entity\G
*************************** 1. row ***************************
Table: top_competitor_summary_entity
Create Table: CREATE TABLE `top_competitor_summary_entity` (
`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
`domain` varchar(255) NOT NULL COMMENT 'competitor domain name',
`own_domain_id` int(11) NOT NULL,
`keyword_top10_count` int(11) DEFAULT NULL,
`keyword_top3_count` int(11) DEFAULT NULL,
`keyword_top1_count` int(11) DEFAULT NULL,
`keyword_top10_search_volume` bigint(20) DEFAULT NULL,
`keyword_top3_search_volume` bigint(20) DEFAULT NULL,
`keyword_top1_search_volume` bigint(20) DEFAULT NULL,
`url_top10_count` int(11) DEFAULT NULL
COMMENT 'how many competitor url in Top 10',
`log_date` date DEFAULT NULL,
`grouptag_id` int(11) DEFAULT '0',
`keyword_top10_count_bing` int(11) DEFAULT '0',
`keyword_top10_count_yahoo` int(11) DEFAULT '0',
`keyword_top3_count_bing` int(11) DEFAULT '0',
`keyword_top3_count_yahoo` int(11) DEFAULT '0',
`keyword_top1_count_bing` int(11) DEFAULT '0',
`keyword_top1_count_yahoo` int(11) DEFAULT '0',
PRIMARY KEY (`id`),
KEY `own_domain_id` (`own_domain_id`),
KEY `domain_own_domain_id_log_date` (`domain`,`own_domain_id`,`log_date`),
KEY `own_domain_id_log_date` (`own_domain_id`,`log_date`)
) ENGINE=InnoDB AUTO_INCREMENT=680592051 DEFAULT CHARSET=utf8
1 row in set (0.09 sec)