Are Conditional subquery
Posted
by Tobias Schulte
on Stack Overflow
See other posts from Stack Overflow
or by Tobias Schulte
Published on 2010-05-20T14:48:25Z
Indexed on
2010/05/20
14:50 UTC
Read the original article
Hit count: 214
I have a table foo and a table bar, where each foo might have a bar (and a bar might belong to multiple foos).
Now I need to select all foos with a bar. My sql looks like this
SELECT * FROM foo f WHERE [...] AND ($param IS NULL OR
(SELECT ((COUNT(*))>0) FROM bar b WHERE f.bar = b.id))
with $param being replaced at runtime.
The question is: Will the subquery be executed even if param is null, or will the dbms optimize the subquery out?
© Stack Overflow or respective owner