数据库分页可以带来哪些性能提升?
假设我有一个表 X,其中包含 100 条记录,并且运行 select * from X
需要 100 秒。
我预计查询 select top 10 * from X
需要多长时间?
我预计这种关系或多或少是线性的,所以 10 秒。这是正确的,还是这种关系在某种程度上是非线性的?
Say I have a table X with 100 records in it and that running a select * from X
takes 100 seconds.
How long should I expect the query select top 10 * from X
to take?
I'd expect that the relationship is more or less linear so 10 seconds. Is this correct, or is the relationship non-linear in some way?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的性能成本体现在两个不同的方面:
通常,查询会很快,但返回结果会很慢,因为它受 I/O 限制。如果是这种情况,那么您将通过返回更少的结果看到近似线性的加速。
但是,如果查询本身很复杂,情况就不同了。如果不仅仅是
select * from X
,而是select * from X where [complicated-expression]
,那么数据库实现之间的结果可能会有很大差异。在这种情况下,您的性能可能会受到查询复杂性的影响,在这种情况下,您不会通过仅返回较少的结果看到那么多好处。Your performance cost is in two different areas:
Often, a query will be fast, but returning results will be slow, since it's I/O-bound. If this is the case, then you will see an approximately linear speedup by returning fewer results.
However, if the query itself is complicated, things are different. If it's not just
select * from X
, butselect * from X where [complicated-expression]
, then results may vary widely between database implementations. In that case, your performance might be dominated by query complexity, in which case you won't see as much benefit by merely returning fewer results.