<?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: Conditional SQL</title>
	<atom:link href="http://jonathanlewis.wordpress.com/2007/01/09/conditional-sql/feed/" rel="self" type="application/rss+xml" />
	<link>http://jonathanlewis.wordpress.com/2007/01/09/conditional-sql/</link>
	<description>Just another Oracle weblog</description>
	<lastBuildDate>Fri, 24 May 2013 13:27:07 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
	<item>
		<title>By: ANSI Outer &#171; Oracle Scratchpad</title>
		<link>http://jonathanlewis.wordpress.com/2007/01/09/conditional-sql/#comment-39362</link>
		<dc:creator><![CDATA[ANSI Outer &#171; Oracle Scratchpad]]></dc:creator>
		<pubDate>Mon, 31 Jan 2011 19:04:09 +0000</pubDate>
		<guid isPermaLink="false">http://jonathanlewis.wordpress.com/2007/01/09/conditional-sql/#comment-39362</guid>
		<description><![CDATA[[...] (the VIEW operator), and this calls the FILTER operation. The filter operation is an example of a &quot;conditional&quot; filter - i.e. if the test in line 5 is true then line 6 is called - and in this case the test is [...]]]></description>
		<content:encoded><![CDATA[<p>[...] (the VIEW operator), and this calls the FILTER operation. The filter operation is an example of a &quot;conditional&quot; filter &#8211; i.e. if the test in line 5 is true then line 6 is called &#8211; and in this case the test is [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Connect By &#171; Oracle Scratchpad</title>
		<link>http://jonathanlewis.wordpress.com/2007/01/09/conditional-sql/#comment-33722</link>
		<dc:creator><![CDATA[Connect By &#171; Oracle Scratchpad]]></dc:creator>
		<pubDate>Tue, 30 Jun 2009 09:22:18 +0000</pubDate>
		<guid isPermaLink="false">http://jonathanlewis.wordpress.com/2007/01/09/conditional-sql/#comment-33722</guid>
		<description><![CDATA[[...] Oracle choose to execute different parts of an execution plan &#8211; giving another reason for the &#8220;conditional plan&#8221; strategy I&#8217;ve described in the [...]]]></description>
		<content:encoded><![CDATA[<p>[...] Oracle choose to execute different parts of an execution plan &#8211; giving another reason for the &#8220;conditional plan&#8221; strategy I&#8217;ve described in the [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Odd Filter &#171; Oracle Scratchpad</title>
		<link>http://jonathanlewis.wordpress.com/2007/01/09/conditional-sql/#comment-33054</link>
		<dc:creator><![CDATA[Odd Filter &#171; Oracle Scratchpad]]></dc:creator>
		<pubDate>Tue, 19 May 2009 18:40:01 +0000</pubDate>
		<guid isPermaLink="false">http://jonathanlewis.wordpress.com/2007/01/09/conditional-sql/#comment-33054</guid>
		<description><![CDATA[[...] type filter&#8221; is a reference to the type of filter I&#8217;ve mentioned in a note on Conditional SQL; but this isn&#8217;t relevant in this [...]]]></description>
		<content:encoded><![CDATA[<p>[...] type filter&#8221; is a reference to the type of filter I&#8217;ve mentioned in a note on Conditional SQL; but this isn&#8217;t relevant in this [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jonathan Lewis</title>
		<link>http://jonathanlewis.wordpress.com/2007/01/09/conditional-sql/#comment-3976</link>
		<dc:creator><![CDATA[Jonathan Lewis]]></dc:creator>
		<pubDate>Thu, 15 Mar 2007 21:30:54 +0000</pubDate>
		<guid isPermaLink="false">http://jonathanlewis.wordpress.com/2007/01/09/conditional-sql/#comment-3976</guid>
		<description><![CDATA[Boris, I don&#039;t think there&#039;s a generic solution that&#039;s clean and tidy. There&#039;s a general principle, perhaps, to move you in the right direction. You can always add a &#039;virtual column&#039; to any suitable existing indexes - or create an index on just a virtual column - to deal with the null dates, for example:

&lt;code&gt;
create index t1_fbi on t1(nvl(end_date,to_date(&#039;31-dec-4000&#039;,&#039;dd-mon-yyyy&#039;)))
&lt;/code&gt;

The drawback to this &lt;em&gt;&#039;year 4000&#039;&lt;/em&gt; hack, though, is that it distorts the optimizer&#039;s view of your data, so you will need to generate a histogram on the &#039;virtual column&#039; so that the optimizer knows that the year 4000 data is a very odd outlier. There is a &lt;em&gt;&lt;strong&gt;method_opt&lt;/strong&gt;&lt;/em&gt; of &quot;for all hidden columns&quot; that you can use with the &lt;em&gt;&lt;strong&gt;dbms_stats&lt;/strong&gt;&lt;/em&gt; procedures to do this.]]></description>
		<content:encoded><![CDATA[<p>Boris, I don&#8217;t think there&#8217;s a generic solution that&#8217;s clean and tidy. There&#8217;s a general principle, perhaps, to move you in the right direction. You can always add a &#8216;virtual column&#8217; to any suitable existing indexes &#8211; or create an index on just a virtual column &#8211; to deal with the null dates, for example:</p>
<p><code><br />
create index t1_fbi on t1(nvl(end_date,to_date('31-dec-4000','dd-mon-yyyy')))<br />
</code></p>
<p>The drawback to this <em>&#8216;year 4000&#8242;</em> hack, though, is that it distorts the optimizer&#8217;s view of your data, so you will need to generate a histogram on the &#8216;virtual column&#8217; so that the optimizer knows that the year 4000 data is a very odd outlier. There is a <em><strong>method_opt</strong></em> of &#8220;for all hidden columns&#8221; that you can use with the <em><strong>dbms_stats</strong></em> procedures to do this.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Boris Dali</title>
		<link>http://jonathanlewis.wordpress.com/2007/01/09/conditional-sql/#comment-3973</link>
		<dc:creator><![CDATA[Boris Dali]]></dc:creator>
		<pubDate>Thu, 15 Mar 2007 20:10:01 +0000</pubDate>
		<guid isPermaLink="false">http://jonathanlewis.wordpress.com/2007/01/09/conditional-sql/#comment-3973</guid>
		<description><![CDATA[... there is a variation of this case though that we couldn&#039;t figure out back than and this article reminded me of that old problem. It was on a project with a highly normalized database model where the main theme was to eliminate redundancy. Everywhere. It probably went a bit too far, as in many tables that would normally have a status column, it wasn&#039;t. Status became a derived column instead. For many queries one of the business rules in effect would be that &quot;... and only the ACTIVE items are to be displayed&quot;. The definition of active was &quot;any items with the end_date as null or set in the future&quot;. An example of item could be a new regulation with the expiration date not known at the time of the insert. As a result, about half of the queries on that system looked like:

where ... and ( end_date is null or end_date &gt; sysdate)

Since these clause had to be repeated many times, developers quickly figured out a typing shortcut:

&lt;b&gt; where ... and nvl(end_date, sysdate+1/1400)&gt;sysdate &lt;/b&gt;

The problem was that at the beginning most of the items were open and consequently index access path based on the above predicate wouldn&#039;t make much sense in many cases as it would need almost every single row from a given table. As the system grew however, many items became &quot;expired&quot; and the above predicate became fairly selective (no archiving of any sort was used for that system).

Is there a good generic enough solution for this problem? Something along the lines of conditional plan you demonstrated in this article perhaps? Function based indexes just came around back than (beginning of 8i) and we haven&#039;t tried them out. Would they work in this case?]]></description>
		<content:encoded><![CDATA[<p>&#8230; there is a variation of this case though that we couldn&#8217;t figure out back than and this article reminded me of that old problem. It was on a project with a highly normalized database model where the main theme was to eliminate redundancy. Everywhere. It probably went a bit too far, as in many tables that would normally have a status column, it wasn&#8217;t. Status became a derived column instead. For many queries one of the business rules in effect would be that &#8220;&#8230; and only the ACTIVE items are to be displayed&#8221;. The definition of active was &#8220;any items with the end_date as null or set in the future&#8221;. An example of item could be a new regulation with the expiration date not known at the time of the insert. As a result, about half of the queries on that system looked like:</p>
<p>where &#8230; and ( end_date is null or end_date &gt; sysdate)</p>
<p>Since these clause had to be repeated many times, developers quickly figured out a typing shortcut:</p>
<p><b> where &#8230; and nvl(end_date, sysdate+1/1400)&gt;sysdate </b></p>
<p>The problem was that at the beginning most of the items were open and consequently index access path based on the above predicate wouldn&#8217;t make much sense in many cases as it would need almost every single row from a given table. As the system grew however, many items became &#8220;expired&#8221; and the above predicate became fairly selective (no archiving of any sort was used for that system).</p>
<p>Is there a good generic enough solution for this problem? Something along the lines of conditional plan you demonstrated in this article perhaps? Function based indexes just came around back than (beginning of 8i) and we haven&#8217;t tried them out. Would they work in this case?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Boris Dali</title>
		<link>http://jonathanlewis.wordpress.com/2007/01/09/conditional-sql/#comment-3951</link>
		<dc:creator><![CDATA[Boris Dali]]></dc:creator>
		<pubDate>Mon, 12 Mar 2007 19:58:30 +0000</pubDate>
		<guid isPermaLink="false">http://jonathanlewis.wordpress.com/2007/01/09/conditional-sql/#comment-3951</guid>
		<description><![CDATA[Jonathan,

Just wanted to mention that while reading this article I remembered that I saw a similar piece couple of years ago back in the 8i/9i days, which was the reason to use NVL quite extensively in our code:

http://www.oracle.com/technology/oramag/oracle/03-jul/o43asktom.html

(scroll down to the &quot;How to Write this Query&quot;)

Thanks,
Boris Dali.]]></description>
		<content:encoded><![CDATA[<p>Jonathan,</p>
<p>Just wanted to mention that while reading this article I remembered that I saw a similar piece couple of years ago back in the 8i/9i days, which was the reason to use NVL quite extensively in our code:</p>
<p><a href="http://www.oracle.com/technology/oramag/oracle/03-jul/o43asktom.html" rel="nofollow">http://www.oracle.com/technology/oramag/oracle/03-jul/o43asktom.html</a></p>
<p>(scroll down to the &#8220;How to Write this Query&#8221;)</p>
<p>Thanks,<br />
Boris Dali.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Conditional SQL (2) &#171; Oracle Scratchpad</title>
		<link>http://jonathanlewis.wordpress.com/2007/01/09/conditional-sql/#comment-3334</link>
		<dc:creator><![CDATA[Conditional SQL (2) &#171; Oracle Scratchpad]]></dc:creator>
		<pubDate>Wed, 14 Feb 2007 08:48:31 +0000</pubDate>
		<guid isPermaLink="false">http://jonathanlewis.wordpress.com/2007/01/09/conditional-sql/#comment-3334</guid>
		<description><![CDATA[[...] plans, CBO &#8212; Jonathan Lewis @ 8:48 am UTC Feb 14,2007   Some time ago I wrote a note on conditional SQL, commenting on code with predicates [...]]]></description>
		<content:encoded><![CDATA[<p>[...] plans, CBO &#8212; Jonathan Lewis @ 8:48 am UTC Feb 14,2007   Some time ago I wrote a note on conditional SQL, commenting on code with predicates [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jonathan Lewis</title>
		<link>http://jonathanlewis.wordpress.com/2007/01/09/conditional-sql/#comment-1586</link>
		<dc:creator><![CDATA[Jonathan Lewis]]></dc:creator>
		<pubDate>Sat, 13 Jan 2007 22:03:18 +0000</pubDate>
		<guid isPermaLink="false">http://jonathanlewis.wordpress.com/2007/01/09/conditional-sql/#comment-1586</guid>
		<description><![CDATA[KB - given that you don&#039;t have an index on your n1 column, take a look at note 8 above from John Flack.]]></description>
		<content:encoded><![CDATA[<p>KB &#8211; given that you don&#8217;t have an index on your n1 column, take a look at note 8 above from John Flack.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Kavya</title>
		<link>http://jonathanlewis.wordpress.com/2007/01/09/conditional-sql/#comment-1580</link>
		<dc:creator><![CDATA[Kavya]]></dc:creator>
		<pubDate>Sat, 13 Jan 2007 20:41:13 +0000</pubDate>
		<guid isPermaLink="false">http://jonathanlewis.wordpress.com/2007/01/09/conditional-sql/#comment-1580</guid>
		<description><![CDATA[Hi,

I am intrested in knowing the solution on this.

I am thinking of using something like this to get around this issue.

select 	*
from 	t1
where	nvl(t1.n1,&#039;$&#039;) = nvl(:n1,nvl(t1.n1,&#039;$&#039;))
;

PS: n1 is not indexed and is not date datatype column.

Appreciate your feedback on this.

Thanks
KB]]></description>
		<content:encoded><![CDATA[<p>Hi,</p>
<p>I am intrested in knowing the solution on this.</p>
<p>I am thinking of using something like this to get around this issue.</p>
<p>select 	*<br />
from 	t1<br />
where	nvl(t1.n1,&#8217;$') = nvl(:n1,nvl(t1.n1,&#8217;$'))<br />
;</p>
<p>PS: n1 is not indexed and is not date datatype column.</p>
<p>Appreciate your feedback on this.</p>
<p>Thanks<br />
KB</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: CT</title>
		<link>http://jonathanlewis.wordpress.com/2007/01/09/conditional-sql/#comment-1514</link>
		<dc:creator><![CDATA[CT]]></dc:creator>
		<pubDate>Fri, 12 Jan 2007 18:28:22 +0000</pubDate>
		<guid isPermaLink="false">http://jonathanlewis.wordpress.com/2007/01/09/conditional-sql/#comment-1514</guid>
		<description><![CDATA[Hello Lewis 
Thank you very much for the respoanse, I will follow through dbms_xplan.
I wanted to post this cartesian merge join but by mistake I posted here.I apologise for that.

Next time I will make sure ,I will post the code.
Thank you
CT]]></description>
		<content:encoded><![CDATA[<p>Hello Lewis<br />
Thank you very much for the respoanse, I will follow through dbms_xplan.<br />
I wanted to post this cartesian merge join but by mistake I posted here.I apologise for that.</p>
<p>Next time I will make sure ,I will post the code.<br />
Thank you<br />
CT</p>
]]></content:encoded>
	</item>
</channel>
</rss>
