Anton Dolganin

I'm an engineer focused on solving problems, not tied to any specific language. Architecture, development, DevOps — I choose the right tools for the job and build solutions that work in production and scale without pain.

This looks fine:

SELECT * FROM orders
WHERE customer_id NOT IN (SELECT id FROM banned_customers);

But in production, it can drag performance — or break logic.

Why? If the subquery returns even one NULL, NOT IN stops working properly. PostgreSQL can't optimize it well.

Better:

SELECT * FROM orders o
LEFT JOIN banned_customers b ON o.customer_id = b.id
WHERE b.id IS NULL;

Faster. Safer. Null-proof.

PostgreSQL: NOT IN can backfire hard