Solved

mysql simple ORDER BY optimization

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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

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…
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

762 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

20 Experts available now in Live!

Get 1:1 Help Now