@@ -705,6 +705,14 @@ protected void executeAppJoin(SQLConfig config, List<JSONObject> resultList, Map
705705// column.add("row_number()OVER(PARTITION BY " + q + key + q + " ORDER BY " + q + key + q + " ASC):_row_num_");
706706// }
707707// jc.setColumn(column);
708+ // }
709+
710+ int childCount = cc .getCount ();
711+ int allChildCount = childCount *config .getCount (); // 所有分组子项数量总和
712+ boolean isOne2Many = childCount != 1 || join .isOne2Many ();
713+ // 一对多会漏副表数据 TODO 似乎一对一走以下优化 row_number() <= childCount 逻辑也没问题
714+ // if (isOne2Many == false && allChildCount > 0 && jc.getCount() < allChildCount) {
715+ // jc.setCount(allChildCount);
708716// }
709717
710718boolean prepared = jc .isPrepared ();
@@ -715,17 +723,14 @@ protected void executeAppJoin(SQLConfig config, List<JSONObject> resultList, Map
715723throw new NullPointerException (TAG + ".executeAppJoin StringUtil.isEmpty(sql, true) >> return null;" );
716724}
717725
718- int childCount = cc .getCount ();
719- int allChildCount = childCount *config .getCount (); // 所有分组子项数量总和
720-
721726 String sql2 = null ;
722- if (childCount > 0 && ( childCount != 1 || join . isOne2Many ()) && (jc .isMySQL () == false || jc .getDBVersionNums ()[0 ] >= 8 )) {
727+ if (childCount > 0 && isOne2Many && (jc .isMySQL () == false || jc .getDBVersionNums ()[0 ] >= 8 )) {
723728 String q = jc .getQuote ();
724729 sql2 = prepared ? jc .getSQL (true ) : sql ;
725730
726731 String prefix = "SELECT * FROM(" ;
727732 String rnStr = ", row_number() OVER (PARTITION BY " + q + key + q + ((AbstractSQLConfig ) jc ).getOrderString (true ) + ") _row_num_ FROM " ;
728- String suffix = ") _t WHERE ( (_row_num_ <= " + childCount + ") ) LIMIT " + allChildCount ;
733+ String suffix = ") _t WHERE ( (_row_num_ <= " + childCount + ") )" + ( allChildCount > 0 ? " LIMIT " + allChildCount : "" ) ;
729734
730735 sql2 = prefix
731736 // 放一块逻辑更清晰,也避免解析 * 等不支持或性能开销 + sql
@@ -786,7 +791,7 @@ protected void executeAppJoin(SQLConfig config, List<JSONObject> resultList, Map
786791
787792//每个 result 都要用新的 SQL 来存 childResultMap = onPutTable(config, rs, rsmd, childResultMap, index, result);
788793
789- Log .d (TAG , "\n executeAppJoin while (rs.next()) { resultList.put( " + index + ", result); "
794+ Log .d (TAG , "\n executeAppJoin while (rs.next()) { resultList.put(" + index + ", result); "
790795+ "\n >>>>>>>>>>>>>>>>>>>>>>>>>>> \n \n " );
791796
792797 //TODO 兼容复杂关联
0 commit comments