<p>We have an InnoDB database that is about 70 GB and we expect it to grow to several hundred GB in the next 2 to 3 years. About 60 % of the data belong to a single table. Currently the database is working quite well as we have a server with 64 GB of RAM, so almost the whole database fits into memory, but we’re concerned about the future when the amount of data will be considerably larger. Right now we’re considering some way of splitting up the tables (especially the one that accounts for the biggest part of the data) and I’m now wondering, what would be the best way to do it.</p>

<p>The options I’m currently aware of are</p>

<ul>
<li>Using MySQL Partitioning that comes with version 5.1 </li>
<li>Using some kind of third party library that encapsulates the partitioning of the data (like hibernate shards)</li>
<li>Implementing it ourselves inside our application</li>
</ul>

<p>Our application is built on J2EE and EJB 2.1 (hopefully we’re switching to EJB 3 some day).</p>

<p>What would you suggest?</p>

<p>EDIT (2011-02-11):<br>
Just an update: Currently the size of the database is 380 GB, the data size of our "big" table is 220 GB and the size of its index is 36 GB. So while the whole table does not fit in memory any more, the index does.<br>
The system is still performing fine (still on the same hardware) and we're still thinking about partitioning the data.</p>

<p>EDIT (2014-06-04):
One more update: The size of the whole database is 1.5 TB, the size of our "big" table is 1.1 TB. We upgraded our server to a 4 processor machine (Intel Xeon E7450) with 128 GB RAM.
The system is still performing fine.
What we're planning to do next is putting our big table on a separate database server (we've already done the necessary changes in our software) while simultaneously upgrading to new hardware with 256 GB RAM.</p>

<p>This setup is supposed to last for two years. Then we will either have to finally start implementing a sharding solution or just buy servers with 1 TB of RAM which should keep us going for some time. </p>

<p>EDIT (2016-01-18):</p>

<p>We have since put our big table in it's own database on a separate server. Currently the size ot this database is about 1.9 TB, the size of the other database (with all tables except for the "big" one) is 1.1 TB.</p>

<p>Current Hardware setup:</p>

<ul>
<li>HP ProLiant DL 580</li>
<li>4 x Intel(R) Xeon(R) CPU E7- 4830</li>
<li>256 GB RAM</li>
</ul>

<p>Performance is fine with this setup.</p>

[{'answer_id': 45902, 'author': 'Joel Coehoorn', 'author_id': 3043, 'author_profile': 'https://Stackoverflow.com/users/3043', 'pm_score': 0, 'selected': False, 'text': "<p>First of all, it doesn't matter as much splitting out tables unless you also move some of the tables to a separate physical volume.  </p>\n\n<p>Secondly, it's not necessarily the table with the largest physical size that you want to move.  You may have a much smaller table that gets more activity, while your big table remains fairly constant or only appends data.</p>\n\n<p>Whatever you do, don't implement it yourselves.  Let the database system handle it.</p>\n"}, {'answer_id': 45930, 'author': 'VanOrman', 'author_id': 4550, 'author_profile': 'https://Stackoverflow.com/users/4550', 'pm_score': 1, 'selected': False, 'text': '<p>A while back at a Microsoft ArcReady event, I saw a presentation on scaling patterns that might be useful to you.  You can <a href="http://www.slideshare.net/clintedmonson/scalable-and-usable-web-applications/" rel="nofollow noreferrer">view the slides</a> for it online.</p>\n'}, {'answer_id': 45936, 'author': 'seanyboy', 'author_id': 1726, 'author_profile': 'https://Stackoverflow.com/users/1726', 'pm_score': 0, 'selected': False, 'text': '<p>What does the big table do. </p>\n\n<p>If you\'re going to split it, you\'ve got a few options:<br>\n - Split it using the database system (don\'t know much about that)<br>\n - Split it by row.<br>\n - split it by column.   </p>\n\n<p>Splitting it by row would only be possible if your data can be separated easily into chunks. e.g. Something like <a href="http://www.basecamphq.com/" rel="nofollow noreferrer">Basecamp</a> has multiple accounts which are completely separate. You could keep 50% of the accounts in one table and 50% in a different table on a different machine. </p>\n\n<p>Splitting by Column is good for situations where the row size contains large text fields or BLOBS. If you\'ve got a table with (for example) a user image and a huge block of text, you could farm the image into a completely different table. (on a different machine)</p>\n\n<p>You break normalisation here, but I don\'t think it would cause too many problems. </p>\n'}, {'answer_id': 45987, 'author': 'Gary Richardson', 'author_id': 2506, 'author_profile': 'https://Stackoverflow.com/users/2506', 'pm_score': 4, 'selected': True, 'text': "<p>If you think you're going to be IO/memory bound, I don't think partitioning is going to be helpful. As usual, benchmarking first will help you figure out the best direction. If you don't have spare servers with 64GB of memory kicking around, you can always ask your vendor for a 'demo unit'.</p>\n\n<p>I would lean towards sharding if you don't expect 1 query aggregate reporting. I'm assuming you'd shard the whole database and not just your big table: it's best to keep entire entities together. Well, if your model splits nicely, anyway.</p>\n"}, {'answer_id': 117614, 'author': 'Seun Osewa', 'author_id': 6475, 'author_profile': 'https://Stackoverflow.com/users/6475', 'pm_score': 0, 'selected': False, 'text': "<p>You would probably want to split that large table eventually.  You'll probably want to put it on a separate hard disk, before thinking of a second server.  Doing it with MySQL is the most convenient option.  If it is capable, then go for it.  </p>\n\n<p>BUT</p>\n\n<p>Everything depends on how your database is being used, really. Statistics.</p>\n"}, {'answer_id': 133505, 'author': 'giltotherescue', 'author_id': 8215, 'author_profile': 'https://Stackoverflow.com/users/8215', 'pm_score': 5, 'selected': False, 'text': "<p>You will definitely start to run into issues on that 42 GB table once it no longer fits in memory. In fact, as soon as it does not fit in memory anymore, performance will degrade extremely quickly. One way to test is to put that table on another machine with less RAM and see how poor it performs.</p>\n\n<blockquote>\n  <p>First of all, it doesn't matter as much splitting out tables unless you also move some of the tables to a separate physical volume.</p>\n</blockquote>\n\n<p>This is incorrect. Partioning (either through the feature in MySQL 5.1, or the same thing using MERGE tables) can provide significant performance benefits even if the tables are on the same drive. </p>\n\n<p>As an example, let's say that you are running SELECT queries on your big table using a date range. If the table is whole, the query will be forced to scan through the entire table (and at that size, even using indexes can be slow). The advantage of partitioning is that your queries will only run on the partitions where it is absolutely necessary. If each partition is 1 GB in size and your query only needs to access 5 partitions in order to fulfill itself, the combined 5 GB table is a lot easier for MySQL to deal with than a monster 42 GB version.</p>\n\n<p>One thing you need to ask yourself is how you are querying the data. If there is a chance that your queries will only need to access certain chunks of data (i.e. a date range or ID range), partitioning of some kind will prove beneficial.</p>\n\n<p>I've heard that there is still some buggyness with MySQL 5.1 partitioning, particularly related to MySQL choosing the correct key. MERGE tables can provide the same functionality, although they require slightly more overhead.</p>\n\n<p>Hope that helps...good luck!</p>\n"}, {'answer_id': 4240598, 'author': 'Greg', 'author_id': 515422, 'author_profile': 'https://Stackoverflow.com/users/515422', 'pm_score': 3, 'selected': False, 'text': '<p>This is a great example of what can MySql partitioning do in a real-life example of huge data flows:</p>\n\n<p><a href="http://web.archive.org/web/20101125025320/http://www.tritux.com/blog/2010/11/19/partitioning-mysql-database-with-high-load-solutions/11/1" rel="nofollow noreferrer">http://web.archive.org/web/20101125025320/http://www.tritux.com/blog/2010/11/19/partitioning-mysql-database-with-high-load-solutions/11/1</a></p>\n\n<p>Hoping it will be helpful for your case.</p>\n'}, {'answer_id': 7724599, 'author': 'Toby', 'author_id': 989295, 'author_profile': 'https://Stackoverflow.com/users/989295', 'pm_score': 1, 'selected': False, 'text': "<p>I would go for MariaDB InnoDB + Partitions (either by key or by date, depending on your queries).</p>\n\n<p>I did this and now I don't have any Database problems anymore.</p>\n\n<p>MySQL can be replaced with MariaDB in seconds...all the database files stay the same.</p>\n"}]
['https://Stackoverflow.com/questions/45879', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/4497/']