<p>At what point does a MySQL database start to lose performance?</p>

<ul>
<li>Does physical database size matter?</li>
<li>Do number of records matter?</li>
<li>Is any performance degradation linear or exponential?</li>
</ul>

<p>I have what I believe to be a large database, with roughly 15M records which take up almost 2GB. Based on these numbers, is there any incentive for me to clean the data out, or am I safe to allow it to continue scaling for a few more years?</p>

[{'answer_id': 1338, 'author': 'Nick Berardi', 'author_id': 17, 'author_profile': 'https://Stackoverflow.com/users/17', 'pm_score': 9, 'selected': True, 'text': "<p>The physical database size doesn't matter.  The number of records don't matter.</p>\n\n<p>In my experience the biggest problem that you are going to run in to is not size, but the number of queries you can handle at a time.  Most likely you are going to have to move to a master/slave configuration so that the read queries can run against the slaves and the write queries run against the master.  However if you are not ready for this yet, you can always tweak your indexes for the queries you are running to speed up the response times.  Also there is a lot of tweaking you can do to the network stack and kernel in Linux that will help.</p>\n\n<p>I have had mine get up to 10GB, with only a moderate number of connections and it handled the requests just fine.</p>\n\n<p>I would focus first on your indexes, then have a server admin look at your OS, and if all that doesn't help it might be time to implement a master/slave configuration.</p>\n"}, {'answer_id': 1490, 'author': 'dlinsin', 'author_id': 198, 'author_profile': 'https://Stackoverflow.com/users/198', 'pm_score': 7, 'selected': False, 'text': '<p>In general this is a very subtle issue and not trivial whatsoever. I encourage you to read <a href="http://mysqlperformanceblog.com" rel="noreferrer">mysqlperformanceblog.com</a> and <a href="https://rads.stackoverflow.com/amzn/click/com/0596101716" rel="noreferrer" rel="nofollow noreferrer">High Performance MySQL</a>. I really think there is no general answer for this.</p>\n\n<p>I\'m working on a project which has a MySQL database with almost 1TB of data. The most important scalability factor is RAM. If the indexes of your tables fit into memory and your queries are highly optimized, you can serve a reasonable amount of requests with a average machine. </p>\n\n<p>The number of records do matter, depending of how your tables look like. It\'s a difference to have a lot of varchar fields or only a couple of ints or longs.</p>\n\n<p>The physical size of the database matters as well: think of backups, for instance. Depending on your engine, your physical db files on grow, but don\'t shrink, for instance with innodb. So deleting a lot of rows, doesn\'t help to shrink your physical files.</p>\n\n<p>There\'s a lot to this issues and as in a lot of cases the devil is in the details.</p>\n'}, {'answer_id': 1504, 'author': 'saint_groceon', 'author_id': 59, 'author_profile': 'https://Stackoverflow.com/users/59', 'pm_score': 3, 'selected': False, 'text': '<p>Also watch out for complex joins.  Transaction complexity can be a big factor in addition to transaction volume.</p>\n\n<p>Refactoring heavy queries sometimes offers a big performance boost.</p>\n'}, {'answer_id': 3079, 'author': 'jj33', 'author_id': 430, 'author_profile': 'https://Stackoverflow.com/users/430', 'pm_score': 4, 'selected': False, 'text': '<p>I once was called upon to look at a mysql that had "stopped working".  I discovered that the DB files were residing on a Network Appliance filer mounted with NFS2 and with a maximum file size of 2GB.  And sure enough, the table that had stopped accepting transactions was exactly 2GB on disk.  But with regards to the performance curve I\'m told that it was working like a champ right up until it didn\'t work at all!  This experience always serves for me as a nice reminder that there\'re always dimensions above and below the one you naturally suspect.</p>\n'}, {'answer_id': 3913, 'author': 'deadprogrammer', 'author_id': 556, 'author_profile': 'https://Stackoverflow.com/users/556', 'pm_score': 4, 'selected': False, 'text': '<p>It\'s kind of pointless to talk about "database performance", "query performance" is a better term here. And the answer is: it depends on the query, data that it operates on, indexes, hardware, etc. You can get an idea of how many rows are going to be scanned and what indexes are going to be used with EXPLAIN syntax. </p>\n\n<p>2GB does not really count as a "large" database - it\'s more of a medium size.</p>\n'}, {'answer_id': 8110, 'author': 'BlaM', 'author_id': 999, 'author_profile': 'https://Stackoverflow.com/users/999', 'pm_score': 5, 'selected': False, 'text': '<blockquote>\n  <p>I would focus first on your indexes, than have a server admin look at your OS, and if all that doesn\'t help it might be time for a master/slave configuration.</p>\n</blockquote>\n\n<p>That\'s true. Another thing that usually works is to just reduce the quantity of data that\'s repeatedly worked with. If you have "old data" and "new data" and 99% of your queries work with new data, just move all the old data to another table - and don\'t look at it ;)</p>\n\n<p>-> Have a look at <a href="http://dev.mysql.com/doc/refman/5.1/en/partitioning.html" rel="noreferrer">partitioning</a>.</p>\n'}, {'answer_id': 3413193, 'author': 'ian', 'author_id': 411743, 'author_profile': 'https://Stackoverflow.com/users/411743', 'pm_score': 5, 'selected': False, 'text': "<p>2GB and about 15M records is a very small database - I've run much bigger ones on a pentium III(!) and everything has still run pretty fast.. If yours is slow it is a database/application design problem, not a mysql one. </p>\n"}, {'answer_id': 9016823, 'author': '0x4a6f4672', 'author_id': 771581, 'author_profile': 'https://Stackoverflow.com/users/771581', 'pm_score': 6, 'selected': False, 'text': '<p>The database size <strong>does matter</strong>. If you have more than one table with more than a million records, then performance starts indeed to degrade. The number of records does of course affect the performance: <a href="http://www.mysqlperformanceblog.com/2006/06/09/why-mysql-could-be-slow-with-large-tables/">MySQL can be slow with large tables</a>. If you hit one million records you will get performance problems if the indices are not set right (for example no indices for fields in "WHERE statements" or "ON conditions" in joins). If you hit 10 million records, you will start to get performance problems even if you have all your indices right. Hardware upgrades - adding more memory and more processor power, especially memory - often help to reduce the most severe problems by increasing the performance again, at least to a certain degree.  For example <a href="http://37signals.com/svn/posts/1185-the-need-for-speed-making-basecamp-faster">37 signals went from 32 GB RAM to 128GB of RAM</a> for the Basecamp database server.</p>\n'}, {'answer_id': 13737357, 'author': 'alditis', 'author_id': 1116802, 'author_profile': 'https://Stackoverflow.com/users/1116802', 'pm_score': 3, 'selected': False, 'text': '<p>A point to consider is also the purpose of the system and the data in the day to day.</p>\n\n<p>For example, for a system with GPS monitoring of cars is not relevant query data from the positions of the car in previous months.</p>\n\n<p>Therefore the data can be passed to other historical tables for possible consultation and reduce the execution times of the day to day queries.</p>\n'}, {'answer_id': 18893356, 'author': 'Abhijit Buchake', 'author_id': 2645711, 'author_profile': 'https://Stackoverflow.com/users/2645711', 'pm_score': 3, 'selected': False, 'text': "<p>Performance can degrade in a matter of few thousand rows if database is not designed properly. </p>\n\n<p>If you have proper indexes, use proper engines (don't use MyISAM where multiple DMLs are expected), use partitioning, allocate correct memory depending on the use and of course have good server configuration, MySQL can handle data even in terabytes!</p>\n\n<p>There are always ways to improve the database performance.</p>\n"}, {'answer_id': 40865490, 'author': 'Anands23', 'author_id': 4643764, 'author_profile': 'https://Stackoverflow.com/users/4643764', 'pm_score': 3, 'selected': False, 'text': '<p><strong>It depends on your query and validation.</strong> </p>\n\n<p>For example, i worked with a table of 100 000 drugs which has a column generic name where it has more than 15 characters for each drug in that table .I put a query to compare the generic name of drugs between two tables.The query takes more minutes to run.The Same,if you compare the drugs using the drug index,using an id column (as said above), it takes only few seconds. </p>\n'}, {'answer_id': 44366926, 'author': 'Viktor Joras', 'author_id': 5645153, 'author_profile': 'https://Stackoverflow.com/users/5645153', 'pm_score': 1, 'selected': False, 'text': "<p>Database size DOES matter in terms of bytes and table's rows number. You will notice a huge performance difference between a light database and a blob filled one. Once my application got stuck because I put binary images inside fields instead of keeping images in files on the disk and putting only file names in database. Iterating a large number of rows on the other hand is not for free.</p>\n"}, {'answer_id': 44851042, 'author': 'Rich Remer', 'author_id': 3776288, 'author_profile': 'https://Stackoverflow.com/users/3776288', 'pm_score': 5, 'selected': False, 'text': "<p>I'm currently managing a MySQL database on Amazon's cloud infrastructure that has grown to 160 GB.  Query performance is fine.  What has become a nightmare is backups, restores, adding slaves, or anything else that deals with the whole dataset, or even DDL on large tables.  Getting a clean import of a dump file has become problematic.  In order to make the process stable enough to automate, various choices needed to be made to prioritize stability over performance.  If we ever had to recover from a disaster using a SQL backup, we'd be down for days.</p>\n<p>Horizontally scaling SQL is also pretty painful, and in most cases leads to using it in ways you probably did not intend when you chose to put your data in SQL in the first place.  Shards, read slaves, multi-master, et al, they are all really shitty solutions that add complexity to everything you ever do with the DB, and not one of them solves the problem; only mitigates it in some ways.  I would strongly suggest looking at moving some of your data out of MySQL (or really any SQL) when you start approaching a dataset of a size where these types of things become an issue.</p>\n<p>Update: a few years later, and our dataset has grown to about 800 GiB.  In addition, we have a single table which is 200+ GiB and a few others in the 50-100 GiB range.  Everything I said before holds.  It still performs just fine, but the problems of running full dataset operations have become worse.</p>\n"}, {'answer_id': 56303453, 'author': 'getNordic', 'author_id': 11147992, 'author_profile': 'https://Stackoverflow.com/users/11147992', 'pm_score': 0, 'selected': False, 'text': '<p>No it doesnt really matter. The MySQL speed is about 7 Million rows per second. So you can scale it quite a bit</p>\n'}, {'answer_id': 62373670, 'author': 'Adithya', 'author_id': 13744323, 'author_profile': 'https://Stackoverflow.com/users/13744323', 'pm_score': 0, 'selected': False, 'text': '<p>Query performance mainly depends on the number of records it needs to scan, indexes plays a high role in it and index data size is proportional to number of rows and number of indexes.</p>\n\n<p>Queries with indexed field conditions along with full value would be returned in 1ms generally, but starts_with, IN, Between, obviously contains conditions might take more time with more records to scan.  </p>\n\n<p>Also you will face lot of maintenance issues with DDL, like ALTER, DROP will be slow and difficult with more live traffic even for adding a index or new columns.</p>\n\n<p>Generally its advisable to cluster the Database into as many clusters as required (500GB would be a general benchmark, as said by others it depends on many factors and can vary based on use cases) that way it gives better isolation and gives independence to scale specific clusters (more suited in case of B2B)</p>\n'}]
['https://Stackoverflow.com/questions/1276', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/30/']