开发者

how to speed up mysql query with two order by filters

开发者 https://www.devze.com 2023-02-17 19:00 出处:网络
select * from mytable order by first_col desc, sec_col asc limit 1; when using only one order by filter, the query finished rather quickly(a few seconds), but the above query took hours.would a two
select * from mytable order by first_col desc, sec_col asc limit 1;

when using only one order by filter, the query finished rather quickly(a few seconds), but the above query took hours. would a two开发者_运维百科 column index speed this up? is there any way to speed up the query?


No, for now there is no solution to optimize "ORDER BY ... ASC, ... DESC". Mysql cannot create indexes with sorting order different than ASC.

ps: yes, I know it is a sorting order parameter in create index but it still doesn't work and was added to satisfy some ansi sql requirements.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号