数据库分页可以带来哪些性能提升?

发布于 2024-09-04 23:22:32 字数 188 浏览 8 评论 0原文

假设我有一个表 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

你与昨日 2024-09-11 23:22:32

您的性能成本体现在两个不同的方面:

  • 执行查询需要多长时间
  • 返回结果需要多长时间

通常,查询会很快,但返回结果会很慢,因为它受 I/O 限制。如果是这种情况,那么您将通过返回更少的结果看到近似线性的加速。

但是,如果查询本身很复杂,情况就不同了。如果不仅仅是 select * from X,而是 select * from X where [complicated-expression],那么数据库实现之间的结果可能会有很大差异。在这种情况下,您的性​​能可能会受到查询复杂性的影响,在这种情况下,您不会通过仅返回较少的结果看到那么多好处。

Your performance cost is in two different areas:

  • How long it takes to perform the query
  • How long it takes to return the results

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, but select * 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文