I need to query data from a second table, but only if a rare set of conditions in the primary table is met:
SELECT ..., IF(a AND b AND c AND (SELECT 1 FROM tableb ...)) FROM tablea ...
a, b, and c conditions are almost always false, so my thinking is the subquery will never execute for most rows in the result set and thus be way faster than a join. But that would only true if the IF() statement short circuits.
Does it?
Thanks for any help you guys can provide.
OR
in the second selectsql SELECT IF(1 = 1 OR (@var:=10), @var, 123); #Expected output: 5
if you want to prove that MySQL is properly short-circuiting for both AND and OR – Wassail