首页 > 解决方案 > JPQL 请求的问题需要很长时间才能执行超过 600000 个注册

问题描述

我在 jpql 中有一个查询,通常会减少数据计数,问题是当表对他们超过 600000 条数据记录时。我使用 spring 数据,实体不包含任何关系(没有 OneToMany、OneToOne、ManyToOne .....)与 oracle 作为数据库..

我使用了 JpaRepository、crudRepository,我什至直接尝试使用 JDBC,返回需要 8 分钟到 30 分钟。我认为问题来自请求,所以我尝试了 findAll() 并且处理时间保持不变。我更改了 JVM -Xmx 和 -Xms 的设置以提供更多内存,但没有任何帮助。

这是我提出的要求:

公共接口 TestRepository 扩展 CrudRepository {

@Query(value = "select new Test(CONCAT(t.date1, t.stringTarget, t.numInfo), t.name, t.phone, t.numInfo, t.date1, t.cotations, t.stringTarget, p.code, p.design)"
        + " from Test t, PointVente p"
        + " WHERE t.ePdv = p.numero"
        + " AND t.date1 BETWEEN :dateBegin AND :dateEnd"
        + " AND (t.state <> 'ANCL' or t.state is null)"
        + " AND t.game in :game"
        + " AND t.type in :type"
        + " AND t.participe = 1"
        + " AND NOT EXISTS (select t2.numInfo, t2.date1"
        + " from Test t2"
        + " WHERE t2.date1 BETWEEN :dateBegin AND :dateEnd"
        + " AND (t2.state <> 'ANCL' or t2.state is null)"
        + " AND t2.game in :game"
        + " AND t2.type in :type"
        + " AND t2.participe = 1"
        + " AND t2.numInfo = t.numInfo"
        + " AND t2.date1 = t.date1"     
        + " AND (t2.phone is null or t2.phone NOT IN (select b.phone from BlacklistTest b))"
        + " group by CONCAT(t2.date1, t2.numInfo), t2.name, t2.phone, t2.numInfo, t2.date1, t2.ePdv"
        + " having sum(t2.cotations) <= :target)"
        + " AND t.cotations > :target"
        + " AND (t.phone is null or t.phone NOT IN (select b.phone from BlacklistTest b))")
List<TestResult> findTest(@Param("dateBegin") Date dateBegin, @Param("dateEnd") Date dateEnd, @Param("game") List<String> game, @Param("type") List<String> type, @Param("target") BigDecimal target);

}

是否可以减少响应时间?

我可以请你帮忙。

标签: javahibernatespring-bootjpa

解决方案


推荐阅读