Solved

mysql simple ORDER BY optimization

Posted on 2008-10-31
1
460 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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Loading csv or delimited data files to MySQL database is a very common task frequently questioned about and almost every time LOAD DATA INFILE comes to the rescue. Here we will try to understand some of the very common scenarios for loading data …
Foreword This is an old article.  Instead of using the MySQL extension that was used in the original code examples, please choose one of the currently supported database extensions instead.  More information is available here: MySQLi / PDO (http://…
Concerto provides fully managed cloud services and the expertise to provide an easy and reliable route to the cloud. Our best-in-class solutions help you address the toughest IT challenges, find new efficiencies and deliver the best application expe…
Delivering innovative fully-managed cloud services for mission-critical applications requires expertise in multiple areas plus vision and commitment. Meet a few of the people behind the quality services of Concerto.

932 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now