Solved

mysql simple ORDER BY optimization

Posted on 2008-10-31
1
462 Views
Last Modified: 2012-05-05
I have a very simple SQL:

select * from members
ORDER BY online,photo DESC
LIMIT 0,12
This takes 4 seconds.

and this other sql :
select * from members
ORDER BY online DESC
LIMIT 0,12
takes less than 1 second

I had a look at
http://dev.mysql.com/doc/refman/5.0/en/order-by-optimization.html
It seems that you cannot optilmize the sql on 2 keys
Is there another way to optimize this SQL ?
0
Comment
Question by:yarek
1 Comment
 
LVL 16

Accepted Solution

by:
brad2575 earned 500 total points
ID: 22851124
well ordering by 1 item is much easier/faster then having to order by 2.

To optimize it I would add an index on the fields you are ordering by, but if it is a text field (DESC) it may not be a good field to add an index to.
0

Featured Post

Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction In this article, I will by showing a nice little trick for MySQL similar to that of my previous EE Article for SQLite (http://www.sqlite.org/), A SQLite Tidbit: Quick Numbers Table Generation (http://www.experts-exchange.com/A_3570.htm…
I use MySQL for many of my development projects in a Windows environment. To manage my databases (and perform queries) for years I used a tool called MySQL administrator.  This tool has since been replaced by MySQL Workbench. So I decided to m…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question