Solved

MySQL query optimization

Posted on 2011-03-10
4
316 Views
Last Modified: 2012-05-11
I want to add an index to improve performance of this  query.
From your experience, which index do you think I would benefit the most?  MyTable has several million rows.  There are maybe about 100 unique client_code, view, batch_timestamp combinations.

Please include your thoughts.

select   client_code
              , view
              , batch_timestamp
              , sum(if(file_reference = null,  1, 0)) as pending
              , count(*) as total
       from mytable
       where
              batch_timestamp >= '20110310'
             and batch_timestamp < DATE_ADD('20110310', INTERVAL 1 DAY)
       group by client_code, view, batch_timestamp
       order by batch_timestamp ;
0
Comment
Question by:rudy201
  • 2
4 Comments
 
LVL 78

Expert Comment

by:arnold
ID: 35097233
could you post the show create table mytable

batch_timestamp, client_code shold have an index.
0
 
LVL 5

Accepted Solution

by:
mayankagarwal earned 500 total points
ID: 35097399
create a Nonclustered Index on  client_code, view, batch_timestamp.
0
 
LVL 5

Expert Comment

by:mayankagarwal
ID: 35097432
create nonclustered index idx_mytable_idx1 on mytable(client_code, view, batch_timestamp)
0
 

Author Closing Comment

by:rudy201
ID: 35175589
Thanks
0

Featured Post

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

Question has a verified solution.

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

Suggested Solutions

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…
As technology users and professionals, we’re always learning. Our universal interest in advancing our knowledge of the trade is unmatched by most industries. It’s a curiosity that makes sense, given the climate of change. Within that, there lies a…
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

730 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