sql - Optimize Hibernate HQL SELECT with IN clause -


please how can optimize query?

from orderentity id in (select distinct orderid productentity    code = :mycode or extcode = :mycode) 

this query slow tables has around million rows

order 1 ... * product

thank help

edit

in pure sql use query fast, don't know how form in hql:

select * order o, (select distinct order_id product code = 'abc'     or ext_code = 'abc') p o.id = p.order_id 

i guess productentity can mapped association orderentity (foreign key order_id) .

if true, try map , test query (inner join may faster) :

select o  productentity p  inner join p.orderentity o  p.code = :mycode or p.extcode = :mycode 

Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -