Tech or Treat! Write an article about your scariest tech disaster to win gadgets!Learn more

x
?
Solved

Slow simple MySQL query (date range)

Posted on 2013-06-14
3
Medium Priority
?
367 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 11

Assisted Solution

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

Accepted Solution

by:
Tomas Helgi Johannsson earned 1200 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 111

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

Fill in the form and get your FREE NFR key NOW!

Veeam® is happy to provide a FREE NFR server license to certified engineers, trainers, and bloggers.  It allows for the non‑production use of Veeam Agent for Microsoft Windows. This license is valid for five workstations and two servers.

Question has a verified solution.

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

Introduction Since I wrote the original article about Handling Date and Time in PHP and MySQL several years ago, it seemed like now was a good time to update it for object-oriented PHP.  This article does that, replacing as much as possible the pr…
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

648 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