Java JPQL请求的问题需要很长时间才能执行,注册数超过600000

Java JPQL请求的问题需要很长时间才能执行,注册数超过600000,java,hibernate,spring-boot,jpa,Java,Hibernate,Spring Boot,Jpa,我在jpql中有一个查询,通常使用较少的数据计数进行查询,问题是当向它们发送的表超过600000条数据记录时。 我使用spring数据,实体不包含任何关系,不包含OneToMany、OneToOne、ManyToOne……以oracle作为数据库 我使用了JpaRepository,crudepository,我甚至直接尝试了JDBC,返回时间从8分钟到30分钟不等。 我认为问题来自于请求,所以我尝试了findAll,处理时间保持不变。 我更改了JVM-Xmx和-Xms的设置以提供更多内存,但没

我在jpql中有一个查询,通常使用较少的数据计数进行查询,问题是当向它们发送的表超过600000条数据记录时。 我使用spring数据,实体不包含任何关系,不包含OneToMany、OneToOne、ManyToOne……以oracle作为数据库

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

以下是我的请求:

公共接口测试存储库扩展了Crudepository{

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

是否有可能缩短响应时间


我想你的问题太笼统了。您做了什么来优化SQL查询的性能?你创建索引了吗?您说过您使用Oracle DB,也许您可以在查询中使用一些Oracle提示?600k不多。请尝试将存储库方法的返回类型从列表更改为流。。。这可能会阻止大量对象创建600.000个实例——相反,当您在流上迭代时,将根据需要创建对象。plz还可以看看这个:[[这听起来像是一个数据库管理问题,访问计划没有好的索引。您需要学习分析SQL语句并创建必要的索引,以便数据库SQL优化器能够更快地找到数据。这本身不是一个编程问题,而是一个DBA问题,因此可能需要询问如何提高数据库性能。I d我不认为这是Oracle的问题,因为当我通过toad运行请求时,返回速度非常快1毫秒,但通过spring数据、hibernate或jdbc,返回时间非常长。我忘了提到我使用ehcache生成缓存DAO端,不能使用流。项目在java 7中,并且表索引良好