简体   繁体   English

如何使休眠查询更快

[英]How to make hibernate query faster

I am currently working on a task to improve performance of an action and the slowest part of code is this hibernate query: 我目前正在执行一项任务,以提高操作的性能,而最慢的代码部分是此休眠查询:

.createQuery( "SELECT distinct p FROM CSParcel p " +
                              " WHERE p.bag.destination.loop.line.changeover.barcode = :barcode AND p.created > :limit " +
                              " AND (p.bag.destination.loop.courierLoop.id = :courierId OR p.bag.destination.loop.line.courier.id = :courierId)" +
                              " AND p.latestAction.actionType <> :doruceni" + " AND p.id NOT IN " +
                              "(SELECT pa.parcel.id " + "   FROM CSParcelAction pa " +
                              " WHERE pa.actionType = :predani AND pa.courier.id = :courierId AND pa.timestamp > :limit" +
                              ")", CSParcel.class )
                .setParameter( "barcode", changeoverBarcode.toUpperCase() )
                .setParameter( "limit", Time.setTime( 0, 0, 0, cal.getTime() ) )
                .setParameter( "courierId", courierId )
                .setParameter( "predani", CSParcelActionType.CHANGEOVER )
                .setParameter( "doruceni", CSParcelActionType.DELIVERY )
                .getResultList();

are there any ways to make it run faster? 有什么方法可以使其运行更快?

Thank you for every suggestion. 谢谢你的每一个建议。

You can monitor with some tools and you will see how queries behave, normally adding some indices where is needed is enough, if you databases alredy have indices you can do some kind of maintenance to tables you use. 您可以使用一些工具进行监视,然后您将看到查询的行为,通常在需要的地方添加一些索引就足够了,如果您的数据库有索引,则可以对使用的表进行某种维护。 Here is some information 这是一些信息

enter link description here 在此处输入链接说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM