fixed: 无法优化 COUNT 查询的问题,关闭:https://gitee.com/mybatis-flex/mybatis-flex/issues/IAYAHL

This commit is contained in:
王帅 2024-10-28 16:27:41 +08:00
parent 98b3c7b92e
commit 37e76da4d9

View File

@ -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 {
// 如果有 distinctgroup byhaving 等语句则不优化
// 这种一旦优化了就会造成 count 语句查询出来的值不对
if (hasDistinct(selectColumns) || hasGroupBy(groupByColumns) || havingCondition != null) {
return clone;
return rawCountQueryWrapper(clone);
}
// 判断能不能清除 join 语句
if (canClearJoins(clone)) {