mirror of
https://gitee.com/mybatis-flex/mybatis-flex.git
synced 2025-12-07 17:18:24 +08:00
fixed: 无法优化 COUNT 查询的问题,关闭:https://gitee.com/mybatis-flex/mybatis-flex/issues/IAYAHL。
This commit is contained in:
parent
98b3c7b92e
commit
37e76da4d9
@ -69,17 +69,20 @@ public class MapperUtil {
|
||||
.select(count().as("total"))
|
||||
.from(queryWrapper).as("t");
|
||||
}
|
||||
|
||||
public static QueryWrapper rawCountQueryWrapper(QueryWrapper queryWrapper, List<QueryColumn> customCountColumns) {
|
||||
return customCountColumns != null ? QueryWrapper.create()
|
||||
.select(customCountColumns)
|
||||
.from(queryWrapper).as("t") : rawCountQueryWrapper(queryWrapper);
|
||||
}
|
||||
|
||||
/**
|
||||
* 优化 COUNT 查询语句。
|
||||
*/
|
||||
public static QueryWrapper optimizeCountQueryWrapper(QueryWrapper queryWrapper) {
|
||||
return optimizeCountQueryWrapper(queryWrapper, Collections.singletonList(count().as("total")));
|
||||
}
|
||||
|
||||
/**
|
||||
* 优化 COUNT 查询语句。
|
||||
*/
|
||||
@ -108,7 +111,7 @@ public class MapperUtil {
|
||||
// 如果有 distinct、group by、having 等语句则不优化
|
||||
// 这种一旦优化了就会造成 count 语句查询出来的值不对
|
||||
if (hasDistinct(selectColumns) || hasGroupBy(groupByColumns) || havingCondition != null) {
|
||||
return clone;
|
||||
return rawCountQueryWrapper(clone);
|
||||
}
|
||||
// 判断能不能清除 join 语句
|
||||
if (canClearJoins(clone)) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user