perf(sql):Optimize SQL performance by replacing SQL_CALC_FOUND_ROWS with COUNT(*)

This commit is contained in:
lizi3
2025-08-18 15:35:51 +08:00
committed by Loïc Mathieu
parent 6def8ef831
commit 8c3cd2856a
7 changed files with 12 additions and 15 deletions

View File

@@ -61,12 +61,9 @@ public class MysqlRepository<T> extends AbstractJdbcRepository<T> {
@Override
public <R extends Record, E> ArrayListTotal<E> fetchPage(DSLContext context, SelectConditionStep<R> select, Pageable pageable, RecordMapper<R, E> mapper) {
Integer rows = context.fetchCount(select);
Result<R> records = this.pageable(select, pageable).fetch();
return dslContextWrapper.transactionResult(configuration -> {
Integer rows = context.fetchOne("SELECT FOUND_ROWS()").into(Integer.class);
return new ArrayListTotal<>(records.map(mapper), rows);
});
return new ArrayListTotal<>(records.map(mapper), rows);
}
@Override