我有一个方法是分页获取用户,方法如下:
PageHelper.startPage(pageNumber, pageSize);
List<UserPageResponse> userPageResponseList = userMapper.findBy(some condition);
return new PageInfo<>(userPageResponseList);
userMapper.findBy对应的 SQL 语句如下:
SELECT u.id,
u.name,
total_consumption_times, # 复杂的 count
total_consumption_amount, # 复杂的 sum
u.last_consumption_time
FROM user u
where ...
order by u.create_time desc;
我期望它产生的 count 语句是:
SELECT count(0)
FROM (SELECT 0
FROM user u
where ...) table_count;
但实际它产生的 count 语句如下,导致执行时间很长。
SELECT count(0)
FROM (SELECT u.id,
u.name,
total_consumption_times, # 复杂的 count
total_consumption_amount, # 复杂的 sum
u.last_consumption_time
FROM user u
where ...) table_count;
怎么解决这个问题?🤕
一个相关的 issue:1.3.1 版本 count 问题 · Issue #121 · pagehelper/pagehelper-spring-boot