Hi team,
We are using spring boot version 3.1.5 (hibernate 6.2.13.Final). Encountered slow performance when access some of the last page (> 100) (page < 100 is fast in 1s), in our data, the last page is 205 and 800, both are slow around 1 minute. Moreover when i execute the query directly in db, it’s fast for last page, so i would say the query is ok.
this is the query
@Query(value = "select cgfd "
+ "from MockEntity cgfd "
+ "where "
+ "cgfd.managerCode = :managerCode "
+ "and cgfd.clientGroupNumber like %:clientGroupNo% "
+ "and (:currentPricingGuidance = null or cgfd.currentPricingGuidance = :currentPricingGuidance) "
+ "and (:wfStatusList = null or cgfd.status in :wfStatusList) "
+ "and (:outOfScope = null or cgfd.outOfScope = :outOfScope)")
Page<MockEntity > queryData(@Param("managerCode") String managerCode,
@Param("clientGroupNo") String clientGroupNo,
@Param("currentPricingGuidance") Integer currentPricingGuidance,
@Param("wfStatusList") List<String> wfStatusList,
@Param("outOfScope") Boolean outOfScope,
Pageable pageable);
this is how we query
Page<MockEntity> list = repository.queryData(
search.getManagerCode(),
search.getClientGroupNo(),
search.getCurrentPricingGuidance(),
wfStatusList,
isOutOfscope,
PageRequest.of(search.getPage(), commonProperties.getPageSize(), sort)
);
note: already changed some of the name above but the structure is the same.
MockEntity: this is the view actually.
pageSize is 20.
last page (search.getPage()): 204.
total: around 4k rows.
sql server
managerCode: nvarchar (eg: RM001), not null
clientGroupNumber: nvarchar (e.g: “”, empty string)
currentPricingGuidance : int (e.g: null)
status: nvarchar (e.g: null)
outOfScope: bit (e.g: null)
if the data MockEntity is around 200 rows in total, no issue.
if i use @EntityManager to build the exact query, no issue.
the query is fast when i remove condition: "and (:wfStatusList = null or cgfd.status in :wfStatusList) "
so i think might something wrong with in condition.
can you check if that’s issue, can you try to reproduce that? (maybe this is spring jpa issue?)
thanks.