问题:
我们有一个要在 TABLE 中可能有 200K 记录的数据库中触发的查询。
SELECT a.* from TABLE a inner join ( SELECT f.COLUMN1, f.COLUMN2, f.COLUMN3, MAX(f.DATECOLUMN4) as LATEST_DATE FROM TABLE f WHERE f.DATECOLUMN5 >= '2020-01-01 00:00:00' AND f.DATECOLUMN5 < '2020-06-04 23:00:00' AND f.COLUMN6 = true GROUP BY f.COLUMN1, f.COLUMN2 , f.COLUMN3) b ON a.COLUMN1 = b.COLUMN1 and a.COLUMN2 = b.COLUMN2 and a.COLUMN3 = b.COLUMN3 and a.DATECOLUMN4 = b.LATEST_DATE WHERE a.DATECOLUMN5 >= '0001-01-01 00:00:00' and a.DATECOLUMN5 < '2020-06-04 23:00:00' and a.COLUMN6 = true
下面是我们用来触发查询的 Repository 类
@Repository
public interface Repository1 extends JpaRepository<Entity1, Long> {
//@formatter:off
@Query(value = "select a.* from TABLE a " +
" inner join ( " +
" select f.COLUMN1, f.COLUMN2, f.COLUMN3, max(f.DATECOLUMN4) as LATEST_DATE " +
" from TABLE f " +
" where f.DATECOLUMN5 >= ?1 and f.DATECOLUMN5 < ?2 and f.COLUMN6 = true " +
" group by f.COLUMN1, f.COLUMN2, f.COLUMN3 " +
" ) a " +
" on a.COLUMN1 = a.COLUMN1 and a.COLUMN2 = a.COLUMN2 and a.COLUMN3 = a.FDP_REQUEST_TYPE_NAME and a.DATECOLUMN4 = a.LATEST_DATE "
+ " where a.DATECOLUMN5 >= ?1 and a.DATECOLUMN5 < ?2 and a.COLUMN6 = true ",
nativeQuery = true)
//@formatter:on
List<Entity1> findRecordsBetweenDATECOLUMN5(LocalDateTime startTime, LocalDateTime endTime);
}
我无法测试代码,因为我无权访问包含 200K 记录的 TABLE。所以请考虑要检索的预期记录数是 200K。查询是否能够将这么多记录检索到列表中?
请指教。