Solved

MySQL query optimization

Posted on 2011-03-10
4
310 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 76

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Creating and Managing Databases with phpMyAdmin in cPanel.
Never store passwords in plain text or just their hash: it seems a no-brainier, but there are still plenty of people doing that. I present the why and how on this subject, offering my own real life solution that you can implement right away, bringin…
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…

758 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

27 Experts available now in Live!

Get 1:1 Help Now