Django,MSSQL Server查询和分页

发布于 2025-02-05 19:33:01 字数 537 浏览 1 评论 0原文

这是我的MSSQL Server表的一个示例

,现在可以在我的应用程序前页面中使用

emp_id  name  status 
EMP001  A     STATUS-A
EMP001  A     STATUS-B
EMP002  B     STATUS-C
EMP001  A     STATUS-D
EMP002  B     STATUS-D
EMP003  C     STATUS-C

,其中有一个表,其中每个员工都在表中列出了一次,并且扩展每个员工将显示他们的所有可用状态。我曾尝试使用pyodbc

来获取:

EMPID   NAME 
EMP001  A
---STATUS-A  #After expanding the EMP001 row it shows all the status of EMP001
---STATUS-B
---STATUS-D
EMP002  B
EMP003  C  

因此,我们如何使用分页,考虑到大约有200k的记录和大约100万个不同的员工

This is a sample of my MSSQL server table

Employeetable

emp_id  name  status 
EMP001  A     STATUS-A
EMP001  A     STATUS-B
EMP002  B     STATUS-C
EMP001  A     STATUS-D
EMP002  B     STATUS-D
EMP003  C     STATUS-C

Now in my app front end page there is a table in which each employee is listed once in the table and expanding each employee will show their every available status. I had tried to fetch using pyodbc

For Example:

EMPID   NAME 
EMP001  A
---STATUS-A  #After expanding the EMP001 row it shows all the status of EMP001
---STATUS-B
---STATUS-D
EMP002  B
EMP003  C  

So how can we use pagination in this consider there are about 200K records and about 100K distinct employees

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

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

发布评论

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

评论(1

感性不性感 2025-02-12 19:33:02

有两种方法可以做到这一点:

1。流行加载

  1. 使用阵列大小参数,这意味着您不会从数据库中获取所有数据,但是批次调用,该记忆的记忆更少,但从DB中读取了更多的读取,这可以使您的应用程序使您的应用程序工作较慢,另一方面,如果更多用户仅使用第一页或第二页,这将更有效

There are two approaches to do it:

1.lazy loading

  1. Use arraysize parameter in the cursor that mean you will not fetch all data from database , but batch calling, this one takes less memory but more reads from DB, which can make your app work slower, from the other hand if more users only use first or second page this will be more effective
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文