A year ago I wrote about the pitfalls of NULL values in NOT IN subqueries. This time I wanted to keep promises I made back then, dig a little deeper and also look at NOT EXISTS as another type of subquery used to filter out records based on negative matches. Is there any semantic difference and which is faster? Unfortunately, there are many myths and misconceptions around the usage of (NOT) IN and (NOT) EXISTS subqueries.
Continue readingTag Archives: subquery
Null Values? NOT IN my Subquery! #JoelKallmanDay
I had to learn from this mistake more than once in my SQL career, until it became a kind of reflex: always think about the NULL values when you are writing a NOT IN subquery. Well, you should ALWAYS keep the NULL values in mind as a SQL developer, but in this case the consequences can be really nasty! And it drives me crazy how many times I’ve seen this error in my consulting life, even in production code. So, what is the point here?
Continue readingUsing Subqueries and Views with PTF or SQL macros
In the last post about SQL macros in 19c I tried to use a subquery as an input for the function. And when I had some DATE calculations in a query, I got ORA-62558: Unsupported data types (DATE)
The result looked somewhat confusing at first, but if you think about it, it is logical and maybe not a bug at all. You should just be very explicit while using subqueries and views(!) in this scenario. And because this behavior is not documented, it is worth sharing, I think.
Null Accepting Semi-Joins in 12c
One of the new query optimizations in 12c are the null-accepting semi-joins. They make subquery unnesting and a semi-join possible in a situation which led to FILTER operation in older versions. Continue reading
Subquery Unnesting – if it doesn’t work
Actually, the CBO usually does a good job optimizing “NOT IN” subqueries. Unless something goes wrong. Recently it took a long time on a 10.2.0.5 database to search for the reason. At last looking in the CBO trace files (event 10053) has given the right hint.
Continue reading