Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
170 views
in Technique[技术] by (71.8m points)

java - Will the SELECT Query be able to retrieve 200K records in Spring Batch

PROBLEM:

We have a below query to be triggered in a database that may have 200K records in TABLE.

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

Below is the Repository class that we are using to trigger the query

@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);

}

I cant test the code as I do not have access to the TABLE which contains 200K records. So please consider the expected number of records to be retrieved is 200K. will the query be able to retrieve that many records to the List?

Please advice.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

will the query be able to retrieve that many records to the List?

If you give your application enough memory, then yes, I don't see why It couldn't.

However, I would recommend using a paging item reader in order to load records in chunks. The whole idea of chunk-oriented processing is to read data in chunks and not load the entire data set in one go (in a List or any other data structure in memory).


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...