简体   繁体   English

Django,MSSQL 服务器查询和分页

[英]Django,MSSQL server query and pagination

This is a sample of my MSSQL server table这是我的 MSSQL 服务器表的示例

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我曾尝试使用 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那么考虑到大约有 20 万条记录和大约 10 万不同的员工,我们如何在此使用分页

There are two approaches to do it:有两种方法可以做到这一点:

1.lazy loading 1.懒加载

  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在游标中使用 arraysize 参数,这意味着您不会从数据库中获取所有数据,而是批量调用,这会占用更少的内存,但会从数据库中读取更多的数据,这会使您的应用程序运行速度变慢,另一方面,如果更多用户只使用第一个或第二页,这将更有效

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM