I’ve encountered strange behavior of Oracle DBMS.
With the SQL quoted below result set is empty. If I delete either of “this_.order_date >=” condition – it returns expected 2 rows.
SELECT DISTINCT this_.id AS y0_,
this_.order_date AS y1_
FROM flight_trip_orders this_,
int_work_order_info iwoi1_,
state_history_records cs2_
WHERE this_.work_info_id =iwoi1_.id
AND iwoi1_.state_history_records_id=cs2_.id
AND this_.order_date <=to_timestamp('12/16/2011', 'mm/dd/yyyy')
AND this_.order_date >=to_timestamp('12/13/2011', 'mm/dd/yyyy')
AND this_.order_date >=to_timestamp('12/15/2011', 'mm/dd/yyyy')
AND rownum <=2;
How this could happen? Results of the query are different on two different Oracle instances, but both are version 11.2.0.2.0
Please do not suggest optimizing query and removing conditions – the query is generated and I have no power to change it.
EDIT:
Adding hint “ALL_ROWS” helps with the issue. The problem is that I can not add this hint in actual application, as explained above.
If your description of the problem is accurate, it sounds like it could be an optimizer bug. Perhaps the redundant conditions are being handled badly and causing an incorrect filter to be used. The first thing I would do is look at the execution plan for the full query and the query without the “12/13/2011” condition, and look for differences, particularly in the predicates being applied.