JPQL的NEW请求,这会花费太多时间

问题描述 投票:0回答:1

我使用Java和休眠模式。我尝试在JPQL中实现该请求,但与在相同条件下用纯SQL发出的近似相似的等效请求相比,运行它确实花费了太多时间(我什至不得不在5分钟的延迟后停止执行)

select NEW package.CustomObject(co.num, item, dim, mat, pro) from Object1 co LEFT JOIN co.items item LEFT JOIN item.dim dim LEFT JOIN item.mat mat LEFT JOIN item.pro pro
           where co.ins between '2018-12-26 01:00:00' and '2019-06-26 01:00:00' 
               or co.mod between '2018-12-26 01:00:00' and '2019-06-26 01:00:00'.

CustomObject是以下

public class CustomObject {

    private String num;

    private OtherCustomObject other;

    public CustomObject(String num, ItemObject item, DimObject dim, MatObject mat, ProObject pro) {
        this.num = num;
        this.other = new OtherCustomObject(item, dim, mat, pro);
    }

}

public class OtherCustomObject {

    private String property1;
    private String property2;
    private String property3;
    private DimObject  dim;
    private MatObject  mat;
    private ProObject  pro;

    public OtherCustomObject(ItemObject item, DimObject dim, MatObject mat, ProObject pro) {
        this.property1 = item.getProperty1();
        this.property2 = item.getProperty2();
        this.property3 = item.getProperty3();
        this.dim = dim;
        this.mat = mat;
        this.pro = pro; 
    }
}

这是在纯SQL中提出的近似相似的等效请求

select  co.num
from    table1    co  left join ItemTable item on item.ou = co.ou left join DimTable dim on dim.item_id = item.id left join MatTable mat on mat.item_id = item.id left join ProTable pro on pro.item_id = item.id 
where   co.ins   between '2018-12-26 01:00:00' and '2019-06-26 01:00:00'
    or  co.mod   between '2018-12-26 01:00:00' and '2019-06-26 01:00:00';

此请求几乎是即时的。那么我的JPQL请求出了什么问题?

sql jpa jpql
1个回答
0
投票
原因是要收集的数据太多。当我运行以下请求时

select co.num from Object1 co LEFT JOIN co.items item LEFT JOIN item.dim dim LEFT JOIN item.mat mat LEFT JOIN item.pro pro where co.ins between '2018-12-26 01:00:00' and '2019-06-26 01:00:00' or co.mod between '2018-12-26 01:00:00' and '2019-06-26 01:00:00'.

我有105 000个结果。因此服务器缺少内存来渲染其他对象并创建CustomObject
© www.soinside.com 2019 - 2024. All rights reserved.