获取总数时很慢该怎么处理 返回

数据库中只有1万多条数据,使用 ToPageListAsync 获取总数时很慢,我将语句单独抽出来获取数量也是差不多,总是要加载很久,请教下该怎么去处理
索引我也去加了,查询列表没问题,五个表联查总字段大概有两三百。
```
await _db.Queryable<To_Collection>()
.LeftJoin<To_CollectionSource>((a, b) => a.CollectionNumber == b.CollectionNumber)
.LeftJoin<To_CollectionProtect>((a, b, c) => a.CollectionNumber == c.CollectionNumber)
.LeftJoin<WF_ProcessInstance>((a, b, c, d) => a.CollectionNumber == d.OrderNumber)
.Where(a => a.IsDelete == false)
....中间有很多WhereIF
.Select((a, b, c, d) => SqlFunc.AggregateCount(a.CollectionNumber))
.FirstAsync()
```
这是专门获取数量的语句,生成后的语句会再去 order by,如果不使用 SqlFunc.AggregateCount,会生成 Count(*),也是同样的慢
为什么我复制一份库到另外一台服务器去执行的时候就很快呢?服务器配置也挺高的。。
热忱回答(1)
-
fate sta VIP0
2021/12/24await _db.Queryable<To_Collection>()
.LeftJoin<To_CollectionSource>((a, b) => a.CollectionNumber == b.CollectionNumber)
.LeftJoin<To_CollectionProtect>((a, b, c) => a.CollectionNumber == c.CollectionNumber)
.LeftJoin<WF_ProcessInstance>((a, b, c, d) => a.CollectionNumber == d.OrderNumber)
.Where(a => a.IsDelete == false)
....中间有很多WhereIF
.Select((a, b, c, d) => SqlFunc.AggregateCount(a.CollectionNumber))
.SingleAsync()
这样试试,你上面的代码生成了 limit
0 回复