我确信执行时间与 MySQL 查询中的行数成正比。我的问题是,比例是多少?随着数据库变大,查询的执行时间会显着增加还是只增加一点点?
有关该主题的任何信息将不胜感激
最佳答案
不,不是真的。
select * from table
将花费更长的时间(如果您有很多行,对于只有四行的表,它所花费的时间不会是有两行的表的两倍,这将是以“固定成本”为主)
无论表大小如何,select * from table limit 10
都将花费相同的时间。
select count(*) from table
在 MySQL 上是即时的,无论表大小如何。
select * from table where Primary_key = ?
将以对数方式缩放(因为使用了 B 树索引)。
select count(*) from table where non_indexed_column = ?
将花费相应更长的时间,但 select count(*) from table where indexed_column = ?
则不会.
如果行数加倍,select * from table_a join table_b
将花费四倍的时间。 使用 (column_a = indexed_column_b) select * from table_a join table_b
应线性缩放。
如果行数加倍,select * from table_a order by unindexed_column
将花费两倍以上的时间。 select * from table_a order by indexed_column
可以按比例缩放,但 select * from table_a where some = ?按indexed_column排序
可能不会。
一旦表不再适合内存,所有操作都会花费更多时间。或者,如果您在内存用于其他表时运行查询。这可能是真正的障碍,执行时间会突然飙升。
此外,您还考虑了“查询中的行”(选定的行)和“表中的行”。这两者都有影响。表中已删除行的“存在”也会产生影响。
关于mysql - 执行时间与行数成正比吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12418860/