分页和大型 SQL Server 表

发布于 2024-10-08 02:37:02 字数 214 浏览 0 评论 0原文

我有一个数据库,有两个数据库表,有超过3000万条记录,当连接它们并使用row_number()进行分页查询时,需要很长时间并且还需要大量资源! 我如何特征这些表:

  • 使用索引视图保存每个用户的分页结果(视图不支持参数),如果我对每个用户使用一个视图,这将是数据的重复,
  • 将表划分为更小的表

是否有完美的解决方案?

I've a database two database tables with more than 30 million records, When joining them and use the row_number() for paging the query takes a long time and also a lot of resources!
How can I trait these tables:

  • Using indexed views to save the paging result for each user(views does not support parameters) and if I use a view per user this will be a duplication of the data
  • divide tables into smaller tables

Is there any perfect solution?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

梦萦几度 2024-10-15 02:37:02

如果您使用OPTION FAST(n),它将优化查询以提供该数量的记录。我之前曾在拥有超过 2000 万条记录的表上成功使用过此功能,将执行时间从分钟缩短到毫秒

但是,如果您将其用于第 10,000 页(恰好是第 1,000,000 条记录),则它将不起作用。如果您的用户想要执行类似的操作,您必须创建一个有序快照并从中执行查询。

If you use OPTION FAST(n), it will optimise the query to provide that number of records. I have used this with success before on tables having +20 million records, bringing down the execution time from minutes to milliseconds.

However, if you use this for 10,000th page which happen to be 1,000,000th record, it will not work. If your users want to do something like this, you would have to create an ordered snapshot and perform the queries from that.

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