Skip to content

Files

Latest commit

 

History

History

HibernateSpringBootStreamAndMySQL

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 

  1. How To Stream Result Set Via Spring Data In MySQL

Note: For web-applications, pagination should be the way to go, not streaming. But, if you choose streaming then keep in mind the golden rule: keep th result set as small as posible. Also, keep in mind that the Execution Plan might not be as efficient as when using SQL-level pagination.

Description: This application is an example of streaming the result set via Spring Data and MySQL. This example can be adopted for databases that fetches the entire result set in a single roundtrip causing performance penalties.

Key points:

  • rely on forward-only result set (default in Spring Data)
  • rely on read-only statement (add @Transactional(readOnly=true))
  • set the fetch-size set (e.g. 30, or row-by-row; Integer.MIN_VALUE (recommended in MySQL))
  • for MySQL, set Statement fetch-size to Integer.MIN_VALUE, or add useCursorFetch=true to the JDBC URL and set Statement fetch-size to a positive integer (e.g., 30)

If you need a deep dive into the performance recipes exposed in this repository then I am sure that you will love my book "Spring Boot Persistence Best Practices"If you need a hand of tips and illustrations of 100+ Java persistence performance issues then "Java Persistence Performance Illustrated Guide" is for you.