相关疑难解决方法(0)

优化我的mysql查询以使用索引进行排序

我有一个基于3列的复合索引,其中两列在我的查询中受约束,第三列是按顺序子句,但mysql不使用索引进行排序.

explain select * from videos where public_private='public' and approved='yes' order by number_of_views desc;

+----+-------------+--------+------+--------------------------------+------+---------+------+---------+-----------------------------+
| id | select_type | table  | type | possible_keys                  | key  | key_len | ref  | rows    | Extra     |
+----+-------------+--------+------+--------------------------------+------+---------+------+---------+-----------------------------+
|  1 | SIMPLE      | videos | ALL  | approved,approved_3,approved_2 | NULL | NULL    | NULL | 1476818 | Using where; Using filesort |
+----+-------------+--------+------+--------------------------------+------+---------+------+---------+-----------------------------+

表结构如下:

CREATE TABLE `videos` (
  `indexer` int(9) NOT NULL auto_increment,
  `user_id` int(9) default NULL,
  `public_private` varchar(24) default NULL, …
Run Code Online (Sandbox Code Playgroud)

mysql indexing optimization query-optimization

7
推荐指数
1
解决办法
1万
查看次数