Please how can I optimize this query?
FROM OrderEntity WHERE id IN (SELECT DISTINCT orderId FROM ProductEntity
WHERE code = :myCode OR extCode = :myCode)
This query is too slow for the tables which has around million rows
Order 1 ... * Product
Thank you for help
EDIT
In pure sql I would use this query which is fast, but I don't know how to form it in HQL:
SELECT * FROM order o, (SELECT DISTINCT order_id FROM product WHERE code = 'ABC'
OR ext_code = 'ABC') p WHERE o.id = p.order_id