Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are some optimization techniques for MySQL table with 300+ million records?

I am looking at storing some JMX data from JVMs on many servers for about 90 days. This data would be statistics like heap size and thread count. This will mean that one of the tables will have around 388 million records.

From this data I am building some graphs so you can compare the stats retrieved from the Mbeans. This means I will be grabbing some data at an interval using timestamps.

So the real question is, Is there anyway to optimize the table or query so you can perform these queries in a reasonable amount of time?

Thanks,

Josh

like image 319
Josh Harris Avatar asked Jan 14 '09 18:01

Josh Harris


People also ask

Can MySQL handle 100 million records?

Can MySQL handle 100 million records? Yeah, it can handle billions of records. If you properly index tables, they fit in memory and your queries are written properly then it shouldn't be an issue.

Can MySQL store millions of records?

Sure, and a whole lot more. I've personally worked with single tables in MySQL that had ten billion records. They were, needless-to-say, very carefully partitioned and had very simple access patterns, but they performed just fine as long as application developers tuned their query patterns Very Carefully.


2 Answers

There are several things you can do:

  1. Build your indexes to match the queries you are running. Run EXPLAIN to see the types of queries that are run and make sure that they all use an index where possible.

  2. Partition your table. Paritioning is a technique for splitting a large table into several smaller ones by a specific (aggregate) key. MySQL supports this internally from ver. 5.1.

  3. If necessary, build summary tables that cache the costlier parts of your queries. Then run your queries against the summary tables. Similarly, temporary in-memory tables can be used to store a simplified view of your table as a pre-processing stage.

like image 69
Eran Galperin Avatar answered Sep 30 '22 23:09

Eran Galperin


3 suggestions:

  1. index
  2. index
  3. index

p.s. for timestamps you may run into performance issues -- depending on how MySQL handles DATETIME and TIMESTAMP internally, it may be better to store timestamps as integers. (# secs since 1970 or whatever)

like image 28
Jason S Avatar answered Sep 30 '22 22:09

Jason S