Take the 2-minute tour ×
Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. It's 100% free, no registration required.

This question is an exact duplicate of:

I just need advice on how I am going to optimize my database.

| Date | Time | Area | Block | Data1 | Data2 | Data3 | DataN |

I have that format of tables on my database. Each tables has 30-days of records with hundred thousands of records each data. Uploading of data to database is every morning. The data of yesterday will be uploaded.

The most common queries to run is grouped by Date or Date and Area or Date and Area and Block. Now, in order to make queries faster, I found out using indexes. I used indexes before. But that was when I am using a primary key. In this table, I didn't use primary key because it is totally unnecessary.

Now, I am really confused on how I am going to optimize this. Based on this reference on Column Considerations part, clustered index is not a good choice on Columns that undergo frequent changes. I am really confused.

Please help me if I need to use clustered index here or just non clustered or both.

share|improve this question

marked as duplicate by Jon Seigel, RolandoMySQLDBA, ypercube, Paul White, JNK Apr 7 at 15:35

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

    
I just provided an answer to this on your stack overflow version of this question. If you prefer, I can drop the answer in over here. –  user158017 Apr 5 at 4:40
    
Clustered indexes are useful for columns / keys which are always inserted in increasing order ( serial, timestamp, .. ) and never updated. –  Olivier S Apr 5 at 17:05
    
You may want to consider sliding window partitioning –  stacylaray Apr 6 at 5:07

1 Answer 1

1/ If after upload you do not update the data, only delete the rows older than 30 days.

2/ And if you can sort your file for the upload by Date, Area, Block

=> Then a clustered index on Date,Area,Block will greatly benefit your aggregations on Date, Date + Area, Date+ Area+Block .

It will also help any request with a where condition on Date, Date + Area, Date + Area + Block , whatever the selected columns for the request.

share|improve this answer
    
I delete data everyday (16th day data), and upload everyday (yesterday data)... –  Kris Edison Apr 9 at 7:50
    
As long as the insertion is ordered, there is no problem. –  Olivier S Apr 9 at 7:55

Not the answer you're looking for? Browse other questions tagged or ask your own question.