Below is a SQL statement inside a stored procedure (truncated for brevity):
SELECT *
FROM item a
WHERE a.orderId NOT IN (SELECT orderId FROM table_excluded_item);
This statement takes 30 seconds or so! But if I remove the inner SELECT query, it drops to 1s. table_excluded_item
is not huge, but I suspect the inner query is being executed more than it needs to be.
Is there a more efficient way of doing this?