MySQL数据库在什么时候开始失去性能?

物理数据库大小重要吗? 记录的数量重要吗? 性能下降是线性的还是指数级的?

我有一个我相信是一个大的数据库,大约有1500万条记录,占用了近2GB。基于这些数字,我是否有任何动机清理数据,或者我是否可以允许它继续扩展几年?


当前回答

查询性能主要取决于它需要扫描的记录数,索引在其中起着很高的作用,索引数据大小与行数和索引数成正比。

带有索引字段条件和完整值的查询通常会在1毫秒内返回,但是starts_with, in, Between,显然包含条件可能需要更多的时间和更多的记录来扫描。

此外,您还将面临DDL的许多维护问题,如ALTER, DROP将缓慢且难以处理更多的实时流量,即使是添加索引或新列。

一般来说,建议将数据库集群到所需的尽可能多的集群中(500GB将是一个通用的基准,正如其他人所说,它取决于许多因素,并且可以根据用例而变化),这样可以提供更好的隔离性,并提供扩展特定集群的独立性(更适合B2B情况)

其他回答

The database size does matter. 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: MySQL can be slow with large tables. 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 37 signals went from 32 GB RAM to 128GB of RAM for the Basecamp database server.

物理数据库大小无关紧要。记录的数量并不重要。

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.

我的内存达到了10GB,只有中等数量的连接,它处理请求还不错。

我将首先关注您的索引,然后让服务器管理员查看您的操作系统,如果所有这些都没有帮助,那么可能是时候实现主/从配置了。

如果数据库设计不当,性能可能会在几千行中下降。

如果你有合适的索引,使用合适的引擎(不要使用MyISAM,因为需要多个dml),使用分区,根据使用情况分配正确的内存,当然还有良好的服务器配置,MySQL可以处理tb级的数据!

总有办法提高数据库性能。

这取决于您的查询和验证。

例如,我处理过一个包含10万种药物的表格,表格中每个药物都有一个超过15个字符的列通用名。我输入了一个查询来比较两个表格之间药物的通用名。查询需要更多的时间来运行。同样,如果使用药物索引,使用id列(如上所述)比较药物,只需要几秒钟。

查询性能主要取决于它需要扫描的记录数,索引在其中起着很高的作用,索引数据大小与行数和索引数成正比。

带有索引字段条件和完整值的查询通常会在1毫秒内返回,但是starts_with, in, Between,显然包含条件可能需要更多的时间和更多的记录来扫描。

此外,您还将面临DDL的许多维护问题,如ALTER, DROP将缓慢且难以处理更多的实时流量,即使是添加索引或新列。

一般来说,建议将数据库集群到所需的尽可能多的集群中(500GB将是一个通用的基准,正如其他人所说,它取决于许多因素,并且可以根据用例而变化),这样可以提供更好的隔离性,并提供扩展特定集群的独立性(更适合B2B情况)