MS-SQL 2008 R2 (Dell, 2 CPU)
This query takes two minutes to run, which is too slow.
SELECT *
FROM t_events WITH (NOLOCK)
WHERE order_no = 2783190
and event_no <= ( SELECT MIN(event_no)
FROM t_events WITH (NOLOCK)
WHERE order_no = 2783190 and complaint_id = 80898
)
However, If I run:
SELECT MIN(event_no) FROM t_events WITH (NOLOCK)
WHERE order_no = 2783190 and complaint_id = 80898
it returns the result, 18880040, in less than a second.
If I run:
SELECT * FROM t_events WITH (NOLOCK)
WHERE order_no = 2783190
and event_no <= 18880040
it returns about 17 lines in 1 sec.
However, together the query takes 2 minutes to return the same 17 lines.
Why is this happening?