Say you have Contact with a nullable many to one on Info, and you write the following HQL query :
SELECT c FROM Contact c WHERE c.name='blabla' OR c.info IS NOT NULL
The generated SQL looks like this :
SELECT c FROM Contact c LEFT JOIN Info i ON c.info = i.id WHERE c.name='blabla' OR c.id IS NOT NULL
Which is correct but uses a useless JOIN and confuses potsgresql optimizer.
The following would be better :
SELECT c FROM Contact c WHERE c.name='blabla' OR c.info IS NOT NULL
Postgresql gets confused and generates a bad plan.
|