Solved

Slow simple MySQL query (date range)

Posted on 2013-06-14
3
311 Views
Last Modified: 2013-06-17
This is a very simple table with 6 columns.  Currently the table has more than 4 million records.  This is the query:


SELECT * FROM chamber_ghst
WHERE chamberid='Ambient' and
actiondate BETWEEN '2013/06/12 12:06:00' and '2013/06/13 12:06:00'
ORDER BY actiondate ASC



This query results in 288 records.  It takes about 16 seconds.  I just don't see why or understand how I can optimize this.
0
Comment
Question by:Zipbang
3 Comments
 
LVL 11

Assisted Solution

by:David Kroll
David Kroll earned 200 total points
ID: 39248867
Are there indexes on chamberid and actiondate?
0
 
LVL 25

Accepted Solution

by:
Tomas Helgi Johannsson earned 300 total points
ID: 39249292
You should add an index on chamberid and actiondate like this

Create index chixactd on chamber_ghst ( chamber asc, actiondate desc) using btree;

This index will speed up your query.

Regards,
    Tomas Helgi
0
 
LVL 109

Expert Comment

by:Ray Paseur
ID: 39251709
NEVER EVER USE SELECT *  ALWAYS USE LIMIT

But that said, there are some really good articles here at EE about MySQL performance.  Example here:
http://www.experts-exchange.com/Database/MySQL/A_1250-3-Ways-to-Speed-Up-MySQL.html
0

Featured Post

Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

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…
Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

813 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

17 Experts available now in Live!

Get 1:1 Help Now