General question from the HQL/JPA-QL perspective --
If you write a JPA-QL query such as the following with multi-boolean where clause (note, this is an example for simplicity to show boolean query, not to be used to 'solve' the problem with hibernate search):
SELECT o from MyObject o WHERE (o.firstname = 'jon' OR o.firstname='john') AND (o.lastname = 'smith' OR o.lastname='smithe')
With the above query, the few DBMS's I've tried do NOT use indexes correctly related to the number of OR's in the WHERE clause.
However, if re-written such as SQL:
Select * from MyObject WHERE o.firstname = 'jon' AND o.lastname='smith'
UNION
Select * from MyObject WHERE o.firstname = 'john' AND o.lastname='smithe'
UNION
Select * from MyObject WHERE o.firstname = 'jon' AND o.lastname='smith'
UNION
Select * from MyObject WHERE o.firstname = 'john' AND o.lastname='smithe'
The underlying DBMS now uses indexes appropriately. I know this is an unusual use-case, but looking for feedback on the forums about feasibility/drawbacks to putting a HINT to create the assoicated SQL from the HQL/JPA-QL query to be 'unionized'. Do not want to create a ticket without initial discussion.
thanks,
-D
|