<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
		>
<channel>
	<title>Comments on: Subquery with OR</title>
	<atom:link href="http://jonathanlewis.wordpress.com/2007/02/26/subquery-with-or/feed/" rel="self" type="application/rss+xml" />
	<link>http://jonathanlewis.wordpress.com/2007/02/26/subquery-with-or/</link>
	<description>Just another Oracle weblog</description>
	<lastBuildDate>Sat, 18 May 2013 11:04:10 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
	<item>
		<title>By: Manual Concatenation and LNVL &#171; OraStory</title>
		<link>http://jonathanlewis.wordpress.com/2007/02/26/subquery-with-or/#comment-48250</link>
		<dc:creator><![CDATA[Manual Concatenation and LNVL &#171; OraStory]]></dc:creator>
		<pubDate>Mon, 23 Jul 2012 12:34:01 +0000</pubDate>
		<guid isPermaLink="false">http://jonathanlewis.wordpress.com/2007/02/26/subquery-with-or/#comment-48250</guid>
		<description><![CDATA[[...] when considering rewriting a SQL OR condition to a UNION/UNION ALL, as pointed out to me by Jonathan Lewis referencing this post on this recent OTN forum [...]]]></description>
		<content:encoded><![CDATA[<p>[...] when considering rewriting a SQL OR condition to a UNION/UNION ALL, as pointed out to me by Jonathan Lewis referencing this post on this recent OTN forum [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jonathan Lewis</title>
		<link>http://jonathanlewis.wordpress.com/2007/02/26/subquery-with-or/#comment-42350</link>
		<dc:creator><![CDATA[Jonathan Lewis]]></dc:creator>
		<pubDate>Sun, 13 Nov 2011 14:37:29 +0000</pubDate>
		<guid isPermaLink="false">http://jonathanlewis.wordpress.com/2007/02/26/subquery-with-or/#comment-42350</guid>
		<description><![CDATA[Gary,

The only thing I can think of is an example I saw recently in 11.2 (I think) where the cardinality of a select statement was 1 when the query used a UNION ALL in an inline view joined to some other table, but a better (ca. 80M) cardinality when the UNION ALL was changed to a UNION.  There isn&#039;t any information in your example that would make it reasonable to suggest that your example is linked - but I suppose it&#039;s a possibility, and it&#039;s possible that CTAS results in a limited range of execution paths being examined that bypass the code that hits the cardinality error.]]></description>
		<content:encoded><![CDATA[<p>Gary,</p>
<p>The only thing I can think of is an example I saw recently in 11.2 (I think) where the cardinality of a select statement was 1 when the query used a UNION ALL in an inline view joined to some other table, but a better (ca. 80M) cardinality when the UNION ALL was changed to a UNION.  There isn&#8217;t any information in your example that would make it reasonable to suggest that your example is linked &#8211; but I suppose it&#8217;s a possibility, and it&#8217;s possible that CTAS results in a limited range of execution paths being examined that bypass the code that hits the cardinality error.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Gary</title>
		<link>http://jonathanlewis.wordpress.com/2007/02/26/subquery-with-or/#comment-42111</link>
		<dc:creator><![CDATA[Gary]]></dc:creator>
		<pubDate>Tue, 18 Oct 2011 20:15:14 +0000</pubDate>
		<guid isPermaLink="false">http://jonathanlewis.wordpress.com/2007/02/26/subquery-with-or/#comment-42111</guid>
		<description><![CDATA[Hi Jonathan

I have been investigating a performance issue regarding the use of OR. Changing the query to use UNION ALL improved performance(minutes to seconds) by changing the plans to use indexes instead of full scans which the OR version caused. Here&#039;s the bit I&#039;ve found strange, while trying to do various testing I wrap a create table as select around the slow query(with the &quot;OR&quot;) and the CBO decides to pick the fast explain plan i.e the one with the indexes. I&#039;ve assumed some form of dynamic sampling maybe in play but can&#039;t see anything in the 10046 trace that obviously suggests this or anything on the web to suggest DDL will change an explain plan. Have you seen this behavior before?]]></description>
		<content:encoded><![CDATA[<p>Hi Jonathan</p>
<p>I have been investigating a performance issue regarding the use of OR. Changing the query to use UNION ALL improved performance(minutes to seconds) by changing the plans to use indexes instead of full scans which the OR version caused. Here&#8217;s the bit I&#8217;ve found strange, while trying to do various testing I wrap a create table as select around the slow query(with the &#8220;OR&#8221;) and the CBO decides to pick the fast explain plan i.e the one with the indexes. I&#8217;ve assumed some form of dynamic sampling maybe in play but can&#8217;t see anything in the 10046 trace that obviously suggests this or anything on the web to suggest DDL will change an explain plan. Have you seen this behavior before?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jonathan Lewis</title>
		<link>http://jonathanlewis.wordpress.com/2007/02/26/subquery-with-or/#comment-37874</link>
		<dc:creator><![CDATA[Jonathan Lewis]]></dc:creator>
		<pubDate>Wed, 24 Nov 2010 12:30:29 +0000</pubDate>
		<guid isPermaLink="false">http://jonathanlewis.wordpress.com/2007/02/26/subquery-with-or/#comment-37874</guid>
		<description><![CDATA[Update:

I suggested the use of lnnvl() in &lt;a href=&quot;http://forums.oracle.com/forums/thread.jspa?threadID=2134421&amp;tstart=0&quot; rel=&quot;nofollow&quot;&gt;&lt;em&gt;&lt;strong&gt;a thread on OTN&lt;/strong&gt;&lt;/em&gt;&lt;/a&gt; recently - and the user found that they got Oracle error &lt;b&gt;&quot;ORA-013207: incorrect use of the [LNNVL] operator&quot;&lt;/b&gt;.  I hadn&#039;t realised that there were any limitations on the predicates you could apply the function to, and their predicate was:
[sourcecode language=&quot;&quot;]
    tr_status not in (&#039;C&#039;,&#039;R&#039;)
[/sourcecode]

You could work around this by expanding the lnnvl() predicate to:
[sourcecode language=&quot;&quot;]
    lnnvl(tr_status =&#039;C&#039;) and lnnvl(tr_status = &#039;R&#039;)
[/sourcecode]

but this is a little counter-intuitive and possibly difficult to work out - and my original argument for using the lnnvl() operator was that it made the code easier to understand. So in this case I&#039;d go for:

[sourcecode language=&quot;&quot;]
    not (nvl(tr_status,&#039;X&#039;) in (&#039;C&#039;,&#039;R&#039;))
[/sourcecode]]]></description>
		<content:encoded><![CDATA[<p>Update:</p>
<p>I suggested the use of lnnvl() in <a href="http://forums.oracle.com/forums/thread.jspa?threadID=2134421&amp;tstart=0" rel="nofollow"><em><strong>a thread on OTN</strong></em></a> recently &#8211; and the user found that they got Oracle error <b>&#8220;ORA-013207: incorrect use of the [LNNVL] operator&#8221;</b>.  I hadn&#8217;t realised that there were any limitations on the predicates you could apply the function to, and their predicate was:</p>
<p>    tr_status not in (&#8216;C&#8217;,'R&#8217;)</p>
<p>You could work around this by expanding the lnnvl() predicate to:</p>
<p>    lnnvl(tr_status =&#8217;C') and lnnvl(tr_status = &#8216;R&#8217;)</p>
<p>but this is a little counter-intuitive and possibly difficult to work out &#8211; and my original argument for using the lnnvl() operator was that it made the code easier to understand. So in this case I&#8217;d go for:</p>
<p>    not (nvl(tr_status,&#8217;X') in (&#8216;C&#8217;,'R&#8217;))</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Sokrates</title>
		<link>http://jonathanlewis.wordpress.com/2007/02/26/subquery-with-or/#comment-13794</link>
		<dc:creator><![CDATA[Sokrates]]></dc:creator>
		<pubDate>Thu, 28 Jun 2007 14:22:14 +0000</pubDate>
		<guid isPermaLink="false">http://jonathanlewis.wordpress.com/2007/02/26/subquery-with-or/#comment-13794</guid>
		<description><![CDATA[I would say, a workaround for the &quot;NOT LNNVL()&quot; Bug 4211527
is using &quot;lnnvl(lnnvl())&quot; instead of &quot;not lnnvl()&quot;

did some tests and it looks great for me.
for example

select null from dual
where lnnvl(lnnvl(exists(select null from dual where lnnvl(null=null))));

do I miss something ?
why don&#039;t they propose it as workaround ?]]></description>
		<content:encoded><![CDATA[<p>I would say, a workaround for the &#8220;NOT LNNVL()&#8221; Bug 4211527<br />
is using &#8220;lnnvl(lnnvl())&#8221; instead of &#8220;not lnnvl()&#8221;</p>
<p>did some tests and it looks great for me.<br />
for example</p>
<p>select null from dual<br />
where lnnvl(lnnvl(exists(select null from dual where lnnvl(null=null))));</p>
<p>do I miss something ?<br />
why don&#8217;t they propose it as workaround ?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jonathan Lewis</title>
		<link>http://jonathanlewis.wordpress.com/2007/02/26/subquery-with-or/#comment-5124</link>
		<dc:creator><![CDATA[Jonathan Lewis]]></dc:creator>
		<pubDate>Sun, 08 Apr 2007 15:55:12 +0000</pubDate>
		<guid isPermaLink="false">http://jonathanlewis.wordpress.com/2007/02/26/subquery-with-or/#comment-5124</guid>
		<description><![CDATA[Don,
Thanks for letting us know about this bug.]]></description>
		<content:encoded><![CDATA[<p>Don,<br />
Thanks for letting us know about this bug.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Don Seiler</title>
		<link>http://jonathanlewis.wordpress.com/2007/02/26/subquery-with-or/#comment-4813</link>
		<dc:creator><![CDATA[Don Seiler]]></dc:creator>
		<pubDate>Wed, 04 Apr 2007 19:33:26 +0000</pubDate>
		<guid isPermaLink="false">http://jonathanlewis.wordpress.com/2007/02/26/subquery-with-or/#comment-4813</guid>
		<description><![CDATA[Looks like the bug with &quot;NOT LNNVL()&quot; is Bug 4211527.  Originally filed with 10.1.0.3 over two years ago.  No workaround posted.  What a pain.  Back to the &quot;OR&quot; statements for me.]]></description>
		<content:encoded><![CDATA[<p>Looks like the bug with &#8220;NOT LNNVL()&#8221; is Bug 4211527.  Originally filed with 10.1.0.3 over two years ago.  No workaround posted.  What a pain.  Back to the &#8220;OR&#8221; statements for me.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Robert Shepard</title>
		<link>http://jonathanlewis.wordpress.com/2007/02/26/subquery-with-or/#comment-3770</link>
		<dc:creator><![CDATA[Robert Shepard]]></dc:creator>
		<pubDate>Mon, 05 Mar 2007 21:55:53 +0000</pubDate>
		<guid isPermaLink="false">http://jonathanlewis.wordpress.com/2007/02/26/subquery-with-or/#comment-3770</guid>
		<description><![CDATA[Interesting.  Looks like &quot;lnnvl&quot; can be nested.  I ran this on Oracle 9.2.0.7.0:

select &#039;Line 1&#039; as is_true
from dual
where lnnvl(1=null)
union
select &#039;Line 2&#039; as is_true
from dual
where lnnvl(1=0)
union
select &#039;Line 3&#039; as is_true
from dual
where lnnvl(1=1)
union
select &#039;Line 4&#039; as is_true
from dual
where lnnvl(lnnvl(1=null))
union
select &#039;Line 5&#039; as is_true
from dual
where lnnvl(lnnvl(1=0))
union
select &#039;Line 6&#039; as is_true
from dual
where lnnvl(lnnvl(1=1))]]></description>
		<content:encoded><![CDATA[<p>Interesting.  Looks like &#8220;lnnvl&#8221; can be nested.  I ran this on Oracle 9.2.0.7.0:</p>
<p>select &#8216;Line 1&#8242; as is_true<br />
from dual<br />
where lnnvl(1=null)<br />
union<br />
select &#8216;Line 2&#8242; as is_true<br />
from dual<br />
where lnnvl(1=0)<br />
union<br />
select &#8216;Line 3&#8242; as is_true<br />
from dual<br />
where lnnvl(1=1)<br />
union<br />
select &#8216;Line 4&#8242; as is_true<br />
from dual<br />
where lnnvl(lnnvl(1=null))<br />
union<br />
select &#8216;Line 5&#8242; as is_true<br />
from dual<br />
where lnnvl(lnnvl(1=0))<br />
union<br />
select &#8216;Line 6&#8242; as is_true<br />
from dual<br />
where lnnvl(lnnvl(1=1))</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: cos</title>
		<link>http://jonathanlewis.wordpress.com/2007/02/26/subquery-with-or/#comment-3757</link>
		<dc:creator><![CDATA[cos]]></dc:creator>
		<pubDate>Mon, 05 Mar 2007 15:08:00 +0000</pubDate>
		<guid isPermaLink="false">http://jonathanlewis.wordpress.com/2007/02/26/subquery-with-or/#comment-3757</guid>
		<description><![CDATA[you&#039;re correct Jonathan, yes, the purpose of the UNION ALL, &quot;AND&quot;-ing the date column one table at a time worked fine and was quite fast after &quot;then-walking-along PK&#039;s&quot;     ... I was just concerned about the amount of code that was to be written as well (complexity, management etc), but I guess, in these instances, you can&#039;t have your cake and eat it all as well...  sometimes, you have to write a lot more code to achieve performance.  Like some famous Oracle guru says :-) --  LOL  -- sometimes you have gently nudge, you have to &quot;coach&quot; Oracle into &quot;understanding&quot; better what you&#039;re trying to do ... worst part is, many times, developers, moreso end users, don&#039;t have a clue of what they&#039;re trying to accomplish to begin with!!! ... :-)    ok... enough with the ranting.]]></description>
		<content:encoded><![CDATA[<p>you&#8217;re correct Jonathan, yes, the purpose of the UNION ALL, &#8220;AND&#8221;-ing the date column one table at a time worked fine and was quite fast after &#8220;then-walking-along PK&#8217;s&#8221;     &#8230; I was just concerned about the amount of code that was to be written as well (complexity, management etc), but I guess, in these instances, you can&#8217;t have your cake and eat it all as well&#8230;  sometimes, you have to write a lot more code to achieve performance.  Like some famous Oracle guru says :-) &#8212;  LOL  &#8212; sometimes you have gently nudge, you have to &#8220;coach&#8221; Oracle into &#8220;understanding&#8221; better what you&#8217;re trying to do &#8230; worst part is, many times, developers, moreso end users, don&#8217;t have a clue of what they&#8217;re trying to accomplish to begin with!!! &#8230; :-)    ok&#8230; enough with the ranting.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jonathan Lewis</title>
		<link>http://jonathanlewis.wordpress.com/2007/02/26/subquery-with-or/#comment-3752</link>
		<dc:creator><![CDATA[Jonathan Lewis]]></dc:creator>
		<pubDate>Mon, 05 Mar 2007 13:14:34 +0000</pubDate>
		<guid isPermaLink="false">http://jonathanlewis.wordpress.com/2007/02/26/subquery-with-or/#comment-3752</guid>
		<description><![CDATA[Cos,  part of the assumption of the &lt;b&gt;union all&lt;/b&gt; approach is that you have have to do something inefficient to get the driving rows from one table, but the joins to the other seven will then be along the PK/FK indexes that represent the referential integrity. If those joins are still going to be inefficient then there isn&#039;t a lot you can do, other than some infrastructure changes.]]></description>
		<content:encoded><![CDATA[<p>Cos,  part of the assumption of the <b>union all</b> approach is that you have have to do something inefficient to get the driving rows from one table, but the joins to the other seven will then be along the PK/FK indexes that represent the referential integrity. If those joins are still going to be inefficient then there isn&#8217;t a lot you can do, other than some infrastructure changes.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
