1

What is the best thing for my scenario

I have a tables with nearly 20,000,000 records, which basically stores what users have done in the site

  • id -> primary int 11 auto increment
  • user_id -> index int 11 not null
  • create_date -> ( no index yet ) date-time not null
  • it has other columns but seems irrelevant to name them here

I know I must put an index on create_date but do I put a single column index or a double column, which one first on the double index ( given the large number of records)?

by the way the query that I'm now using is like :

select max(id) -- in here I'm selecting actions that users have done, after this date, since date is today
from table t
where 
    t.create_date >= '2014-12-29 00:00:00'
group by t.user_id

1 Answer 1

1

Could you edit your question with an EXPLAIN PLAN of your SELECT? EXPLAIN Link. Meanwhile, you can try with this:

  • Make partitions using your date field create_date. Partitions
  • Build your index with the most restrictive criteria first. I think that in your case, it will be better create_date + user_id

    CREATE INDEX index_name ON table_name ( create_date , user_id );

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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