MySQL query optimization

Posted on 2011-03-10
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
              batch_timestamp >= '20110310'
             and batch_timestamp < DATE_ADD('20110310', INTERVAL 1 DAY)
       group by client_code, view, batch_timestamp
       order by batch_timestamp ;
Question by:rudy201
  • 2
LVL 77

Expert Comment

ID: 35097233
could you post the show create table mytable

batch_timestamp, client_code shold have an index.

Accepted Solution

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

Expert Comment

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

Author Closing Comment

ID: 35175589

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
C# Application Local DB Connection String 23 113
Duplicating MySQL Table columns 5 32
SQL Server - Check Constraint or NOT NULL? 11 69
Steps to produce a data strategy 5 43
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.
Shadow IT is coming out of the shadows as more businesses are choosing cloud-based applications. It is now a multi-cloud world for most organizations. Simultaneously, most businesses have yet to consolidate with one cloud provider or define an offic…
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…

895 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

18 Experts available now in Live!

Get 1:1 Help Now