Update AbstractSQLExecutor.java

This commit is contained in:
TommyLemon 2022-10-17 21:28:27 +08:00 committed by GitHub
parent 47fbbdabc0
commit 74a7717dd7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -695,25 +695,25 @@ public abstract class AbstractSQLExecutor implements SQLExecutor {
jc.setMain(true).setPreparedValueList(new ArrayList<>());
// 放一块逻辑更清晰也避免解析 * 等不支持或性能开销
// String q = jc.getQuote();
// if (allChildCount > 0 && jc.getCount() <= 0) {
// List<String> column = jc.getColumn();
// if (column == null || column.isEmpty()) {
// column = Arrays.asList("*;row_number()OVER(PARTITION BY " + q + key + q + " ORDER BY " + q + key + q + " ASC):_row_num_");
// }
// else {
// column.add("row_number()OVER(PARTITION BY " + q + key + q + " ORDER BY " + q + key + q + " ASC):_row_num_");
// }
// jc.setColumn(column);
// }
// String q = jc.getQuote();
// if (allChildCount > 0 && jc.getCount() <= 0) {
// List<String> column = jc.getColumn();
// if (column == null || column.isEmpty()) {
// column = Arrays.asList("*;row_number()OVER(PARTITION BY " + q + key + q + " ORDER BY " + q + key + q + " ASC):_row_num_");
// }
// else {
// column.add("row_number()OVER(PARTITION BY " + q + key + q + " ORDER BY " + q + key + q + " ASC):_row_num_");
// }
// jc.setColumn(column);
// }
int childCount = cc.getCount();
int allChildCount = childCount*config.getCount(); // 所有分组子项数量总和
boolean isOne2Many = childCount != 1 || join.isOne2Many();
// 一对多会漏副表数据 TODO 似乎一对一走以下优化 row_number() <= childCount 逻辑也没问题
// if (isOne2Many == false && allChildCount > 0 && jc.getCount() < allChildCount) {
// jc.setCount(allChildCount);
// }
// if (isOne2Many == false && allChildCount > 0 && jc.getCount() < allChildCount) {
// jc.setCount(allChildCount);
// }
boolean prepared = jc.isPrepared();
String sql = jc.getSQL(false);
@ -725,24 +725,24 @@ public abstract class AbstractSQLExecutor implements SQLExecutor {
String sql2 = null;
if (childCount > 0 && isOne2Many && (jc.isMySQL() == false || jc.getDBVersionNums()[0] >= 8)) {
// row_number 字段并不会导致 count 等聚合函数统计出错结果偏大SQL JOIN 才会之前没发现是因为缓存失效 bug
// boolean noAggrFun = true;
// List<String> column = jc.getColumn();
// if (column != null) {
// for (String c : column) {
// int start = c == null ? -1 : c.indexOf("(");
// int end = start <= 0 ? -1 : c.lastIndexOf(")");
// if (start > 0 && end > start) {
// String fun = c.substring(0, start);
// if (AbstractSQLConfig.SQL_AGGREGATE_FUNCTION_MAP.containsKey(fun)) {
// noAggrFun = false;
// break;
// }
// }
// }
// }
//
// if (noAggrFun) { // row_number 字段会导致 count 等聚合函数统计出错结果偏大
// row_number 字段并不会导致 count 等聚合函数统计出错结果偏大SQL JOIN 才会之前没发现是因为缓存失效 bug
// boolean noAggrFun = true;
// List<String> column = jc.getColumn();
// if (column != null) {
// for (String c : column) {
// int start = c == null ? -1 : c.indexOf("(");
// int end = start <= 0 ? -1 : c.lastIndexOf(")");
// if (start > 0 && end > start) {
// String fun = c.substring(0, start);
// if (AbstractSQLConfig.SQL_AGGREGATE_FUNCTION_MAP.containsKey(fun)) {
// noAggrFun = false;
// break;
// }
// }
// }
// }
//
// if (noAggrFun) { // row_number 字段会导致 count 等聚合函数统计出错结果偏大
String q = jc.getQuote();
sql2 = prepared ? jc.getSQL(true) : sql;
@ -756,7 +756,7 @@ public abstract class AbstractSQLExecutor implements SQLExecutor {
+ suffix;
sql = prepared ? (prefix + sql.replaceFirst(" FROM ", rnStr) + suffix) : sql2;
// }
// }
}
boolean isExplain = jc.isExplain();