<?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: Session SQL</title>
	<atom:link href="http://jonathanlewis.wordpress.com/2012/02/09/session-sql/feed/" rel="self" type="application/rss+xml" />
	<link>http://jonathanlewis.wordpress.com/2012/02/09/session-sql/</link>
	<description>Just another Oracle weblog</description>
	<lastBuildDate>Wed, 22 May 2013 12:40:08 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
	<item>
		<title>By: Jonathan Lewis</title>
		<link>http://jonathanlewis.wordpress.com/2012/02/09/session-sql/#comment-45342</link>
		<dc:creator><![CDATA[Jonathan Lewis]]></dc:creator>
		<pubDate>Wed, 07 Mar 2012 11:02:06 +0000</pubDate>
		<guid isPermaLink="false">http://jonathanlewis.wordpress.com/?p=8393#comment-45342</guid>
		<description><![CDATA[Tom,

If you re-read the article you&#039;ll see the statement:
&lt;blockquote&gt;&lt;em&gt;
&quot;The most important one, to my mind, is the one about the execution path. When running any “got it off the Internet” SQL against the dynamic performance views, don’t forget to check the execution path and the performance threats before you use it on production&quot;
&lt;/em&gt;&lt;/blockquote&gt;
Running your query and pulling the plan from memory, this is what I got shortly after startup on a small 11.1 system I had at hand:
[sourcecode gutter=&quot;false&quot;]
SQL&gt; select * from table(dbms_xplan.display_cursor(null,null,&#039;allstats last&#039;));

PLAN_TABLE_OUTPUT
---------------------------------------------------------
SQL_ID  gcmw0ht7u5xm8, child number 0
-------------------------------------
select  /*+ gather_plan_statistics */  address &#124;&#124; &#039;:  &#039; &#124;&#124; sql_text
sql_text from  v$sqltext where  address in  (   select  oc.address
   from v$session        s,                 v$process        p,
        v$open_cursor    oc         where   p.addr     = s.paddr
 and     p.spid = 2840         and     s.saddr = oc.saddr )

Plan hash value: 1481537409

--------------------------------------------------------------------------------------------------------------------------
&#124; Id  &#124; Operation                   &#124; Name            &#124; Starts &#124; E-Rows &#124; A-Rows &#124;   A-Time   &#124;  OMem &#124;  1Mem &#124; Used-Mem &#124;
--------------------------------------------------------------------------------------------------------------------------
&#124;   0 &#124; SELECT STATEMENT            &#124;                 &#124;      1 &#124;        &#124;    115 &#124;00:00:00.01 &#124;       &#124;       &#124;          &#124;
&#124;*  1 &#124;  FILTER                     &#124;                 &#124;      1 &#124;        &#124;    115 &#124;00:00:00.01 &#124;       &#124;       &#124;          &#124;
&#124;*  2 &#124;   FIXED TABLE FULL          &#124; X$KGLNA         &#124;      1 &#124;      1 &#124;   6487 &#124;00:00:00.01 &#124;       &#124;       &#124;          &#124;
&#124;   3 &#124;   NESTED LOOPS              &#124;                 &#124;    931 &#124;      1 &#124;     31 &#124;00:00:00.01 &#124;       &#124;       &#124;          &#124;
&#124;   4 &#124;    MERGE JOIN CARTESIAN     &#124;                 &#124;    931 &#124;      1 &#124;   2541 &#124;00:00:00.01 &#124;       &#124;       &#124;          &#124;
&#124;   5 &#124;     NESTED LOOPS            &#124;                 &#124;    931 &#124;      1 &#124;   2541 &#124;00:00:00.01 &#124;       &#124;       &#124;          &#124;
&#124;   6 &#124;      MERGE JOIN CARTESIAN   &#124;                 &#124;    931 &#124;      1 &#124;   2541 &#124;00:00:00.01 &#124;       &#124;       &#124;          &#124;
&#124;*  7 &#124;       FIXED TABLE FULL      &#124; X$KGLLK         &#124;    931 &#124;      1 &#124;    121 &#124;00:00:00.01 &#124;       &#124;       &#124;          &#124;
&#124;   8 &#124;       BUFFER SORT           &#124;                 &#124;    121 &#124;    100 &#124;   2541 &#124;00:00:00.01 &#124;  2048 &#124;  2048 &#124; 2048  (0)&#124;
&#124;   9 &#124;        FIXED TABLE FULL     &#124; X$KSLWT         &#124;    102 &#124;    100 &#124;   2142 &#124;00:00:00.01 &#124;       &#124;       &#124;          &#124;
&#124;* 10 &#124;      FIXED TABLE FIXED INDEX&#124; X$KSLED (ind:2) &#124;   2541 &#124;      1 &#124;   2541 &#124;00:00:00.01 &#124;       &#124;       &#124;          &#124;
&#124;  11 &#124;     BUFFER SORT             &#124;                 &#124;   2541 &#124;      1 &#124;   2541 &#124;00:00:00.01 &#124;  2048 &#124;  2048 &#124; 2048  (0)&#124;
&#124;* 12 &#124;      FIXED TABLE FULL       &#124; X$KSUPR         &#124;    102 &#124;      1 &#124;    102 &#124;00:00:00.01 &#124;       &#124;       &#124;          &#124;
&#124;* 13 &#124;    FIXED TABLE FIXED INDEX  &#124; X$KSUSE (ind:1) &#124;   2541 &#124;      1 &#124;     31 &#124;00:00:00.01 &#124;       &#124;       &#124;          &#124;
--------------------------------------------------------------------------------------------------------------------------

Predicate Information (identified by operation id):
---------------------------------------------------
   1 - filter( IS NOT NULL)
   2 - filter((&quot;KGLOBOCT&quot;&lt;&gt;0 AND &quot;INST_ID&quot;=USERENV(&#039;INSTANCE&#039;)))
   7 - filter((&quot;KGLHDPAR&quot;=:B1 AND &quot;KGLHDNSP&quot;=0 AND &quot;KGLLKHDL&quot;&lt;&gt;:B2 AND &quot;INST_ID&quot;=USERENV(&#039;INSTANCE&#039;) AND
              &quot;KGLHDPAR&quot;&lt;&gt;&quot;KGLLKHDL&quot;))
  10 - filter(&quot;W&quot;.&quot;KSLWTEVT&quot;=&quot;E&quot;.&quot;INDX&quot;)
  12 - filter((TO_NUMBER(&quot;KSUPRPID&quot;)=2840 AND &quot;INST_ID&quot;=USERENV(&#039;INSTANCE&#039;) AND BITAND(&quot;KSSPAFLG&quot;,1)&lt;&gt;0))
  13 - filter((&quot;S&quot;.&quot;INST_ID&quot;=USERENV(&#039;INSTANCE&#039;) AND BITAND(&quot;S&quot;.&quot;KSSPAFLG&quot;,1)&lt;&gt;0 AND BITAND(&quot;S&quot;.&quot;KSUSEFLG&quot;,1)&lt;&gt;0
              AND &quot;ADDR&quot;=&quot;S&quot;.&quot;KSUSEPRO&quot; AND &quot;S&quot;.&quot;ADDR&quot;=&quot;KGLLKUSE&quot; AND &quot;S&quot;.&quot;INDX&quot;=&quot;W&quot;.&quot;KSLWTSID&quot;))

41 rows selected.

[/sourcecode]

Your query converts the IN subquery to an EXISTS subquery and operates it as a filter subquery that is called (&lt;em&gt;&lt;strong&gt;&lt;a href=&quot;http://jonathanlewis.wordpress.com/2006/11/06/filter-subqueries/&quot; rel=&quot;nofollow&quot;&gt;in theory&lt;/a&gt;&lt;/strong&gt;&lt;/em&gt;) for every row in x$kglna (v$sqltext). This is not a path you would want to see on a large, busy, production system.]]></description>
		<content:encoded><![CDATA[<p>Tom,</p>
<p>If you re-read the article you&#8217;ll see the statement:</p>
<blockquote><p><em><br />
&#8220;The most important one, to my mind, is the one about the execution path. When running any “got it off the Internet” SQL against the dynamic performance views, don’t forget to check the execution path and the performance threats before you use it on production&#8221;<br />
</em></p></blockquote>
<p>Running your query and pulling the plan from memory, this is what I got shortly after startup on a small 11.1 system I had at hand:</p>
<pre class="brush: plain; gutter: false; title: ; notranslate">
SQL&gt; select * from table(dbms_xplan.display_cursor(null,null,'allstats last'));

PLAN_TABLE_OUTPUT
---------------------------------------------------------
SQL_ID  gcmw0ht7u5xm8, child number 0
-------------------------------------
select  /*+ gather_plan_statistics */  address || ':  ' || sql_text
sql_text from  v$sqltext where  address in  (   select  oc.address
   from v$session        s,                 v$process        p,
        v$open_cursor    oc         where   p.addr     = s.paddr
 and     p.spid = 2840         and     s.saddr = oc.saddr )

Plan hash value: 1481537409

--------------------------------------------------------------------------------------------------------------------------
| Id  | Operation                   | Name            | Starts | E-Rows | A-Rows |   A-Time   |  OMem |  1Mem | Used-Mem |
--------------------------------------------------------------------------------------------------------------------------
|   0 | SELECT STATEMENT            |                 |      1 |        |    115 |00:00:00.01 |       |       |          |
|*  1 |  FILTER                     |                 |      1 |        |    115 |00:00:00.01 |       |       |          |
|*  2 |   FIXED TABLE FULL          | X$KGLNA         |      1 |      1 |   6487 |00:00:00.01 |       |       |          |
|   3 |   NESTED LOOPS              |                 |    931 |      1 |     31 |00:00:00.01 |       |       |          |
|   4 |    MERGE JOIN CARTESIAN     |                 |    931 |      1 |   2541 |00:00:00.01 |       |       |          |
|   5 |     NESTED LOOPS            |                 |    931 |      1 |   2541 |00:00:00.01 |       |       |          |
|   6 |      MERGE JOIN CARTESIAN   |                 |    931 |      1 |   2541 |00:00:00.01 |       |       |          |
|*  7 |       FIXED TABLE FULL      | X$KGLLK         |    931 |      1 |    121 |00:00:00.01 |       |       |          |
|   8 |       BUFFER SORT           |                 |    121 |    100 |   2541 |00:00:00.01 |  2048 |  2048 | 2048  (0)|
|   9 |        FIXED TABLE FULL     | X$KSLWT         |    102 |    100 |   2142 |00:00:00.01 |       |       |          |
|* 10 |      FIXED TABLE FIXED INDEX| X$KSLED (ind:2) |   2541 |      1 |   2541 |00:00:00.01 |       |       |          |
|  11 |     BUFFER SORT             |                 |   2541 |      1 |   2541 |00:00:00.01 |  2048 |  2048 | 2048  (0)|
|* 12 |      FIXED TABLE FULL       | X$KSUPR         |    102 |      1 |    102 |00:00:00.01 |       |       |          |
|* 13 |    FIXED TABLE FIXED INDEX  | X$KSUSE (ind:1) |   2541 |      1 |     31 |00:00:00.01 |       |       |          |
--------------------------------------------------------------------------------------------------------------------------

Predicate Information (identified by operation id):
---------------------------------------------------
   1 - filter( IS NOT NULL)
   2 - filter((&quot;KGLOBOCT&quot;&lt;&gt;0 AND &quot;INST_ID&quot;=USERENV('INSTANCE')))
   7 - filter((&quot;KGLHDPAR&quot;=:B1 AND &quot;KGLHDNSP&quot;=0 AND &quot;KGLLKHDL&quot;&lt;&gt;:B2 AND &quot;INST_ID&quot;=USERENV('INSTANCE') AND
              &quot;KGLHDPAR&quot;&lt;&gt;&quot;KGLLKHDL&quot;))
  10 - filter(&quot;W&quot;.&quot;KSLWTEVT&quot;=&quot;E&quot;.&quot;INDX&quot;)
  12 - filter((TO_NUMBER(&quot;KSUPRPID&quot;)=2840 AND &quot;INST_ID&quot;=USERENV('INSTANCE') AND BITAND(&quot;KSSPAFLG&quot;,1)&lt;&gt;0))
  13 - filter((&quot;S&quot;.&quot;INST_ID&quot;=USERENV('INSTANCE') AND BITAND(&quot;S&quot;.&quot;KSSPAFLG&quot;,1)&lt;&gt;0 AND BITAND(&quot;S&quot;.&quot;KSUSEFLG&quot;,1)&lt;&gt;0
              AND &quot;ADDR&quot;=&quot;S&quot;.&quot;KSUSEPRO&quot; AND &quot;S&quot;.&quot;ADDR&quot;=&quot;KGLLKUSE&quot; AND &quot;S&quot;.&quot;INDX&quot;=&quot;W&quot;.&quot;KSLWTSID&quot;))

41 rows selected.

</pre>
<p>Your query converts the IN subquery to an EXISTS subquery and operates it as a filter subquery that is called (<em><strong><a href="http://jonathanlewis.wordpress.com/2006/11/06/filter-subqueries/" rel="nofollow">in theory</a></strong></em>) for every row in x$kglna (v$sqltext). This is not a path you would want to see on a large, busy, production system.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Tom Robbins</title>
		<link>http://jonathanlewis.wordpress.com/2012/02/09/session-sql/#comment-45336</link>
		<dc:creator><![CDATA[Tom Robbins]]></dc:creator>
		<pubDate>Tue, 06 Mar 2012 22:05:42 +0000</pubDate>
		<guid isPermaLink="false">http://jonathanlewis.wordpress.com/?p=8393#comment-45336</guid>
		<description><![CDATA[If you also want to see the open cursors, including recursive sql, you can add a select on v$open_cursor.
This query uses unix PID to find the appropriate sql:
[sourcecode]
select   address &#124;&#124; &#039;:  &#039; &#124;&#124; sql_text sql_text
from v$sqltext
where address in
        (select  oc.address
        from    v$session        s,
                v$process        p,
                v$open_cursor    oc
        where   p.addr     = s.paddr
        and     p.spid = &amp;&amp;unix_pid
        and     s.saddr = oc.saddr)
[/sourcecode]
]]></description>
		<content:encoded><![CDATA[<p>If you also want to see the open cursors, including recursive sql, you can add a select on v$open_cursor.<br />
This query uses unix PID to find the appropriate sql:</p>
<pre class="brush: plain; title: ; notranslate">
select   address || ':  ' || sql_text sql_text
from v$sqltext
where address in
        (select  oc.address
        from    v$session        s,
                v$process        p,
                v$open_cursor    oc
        where   p.addr     = s.paddr
        and     p.spid = &amp;amp;&amp;amp;unix_pid
        and     s.saddr = oc.saddr)
</pre>
]]></content:encoded>
	</item>
	<item>
		<title>By: Weather &#171; Oracle Scratchpad</title>
		<link>http://jonathanlewis.wordpress.com/2012/02/09/session-sql/#comment-45118</link>
		<dc:creator><![CDATA[Weather &#171; Oracle Scratchpad]]></dc:creator>
		<pubDate>Tue, 21 Feb 2012 21:24:45 +0000</pubDate>
		<guid isPermaLink="false">http://jonathanlewis.wordpress.com/?p=8393#comment-45118</guid>
		<description><![CDATA[[...] thought it was pretty cold in Sarajevo a couple of weeks ago, and therefore fairly mild in Minneapolis and Denver when the temperature was [...]]]></description>
		<content:encoded><![CDATA[<p>[...] thought it was pretty cold in Sarajevo a couple of weeks ago, and therefore fairly mild in Minneapolis and Denver when the temperature was [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Session SQL &#8211; All Things Oracle</title>
		<link>http://jonathanlewis.wordpress.com/2012/02/09/session-sql/#comment-45075</link>
		<dc:creator><![CDATA[Session SQL &#8211; All Things Oracle]]></dc:creator>
		<pubDate>Fri, 17 Feb 2012 15:18:59 +0000</pubDate>
		<guid isPermaLink="false">http://jonathanlewis.wordpress.com/?p=8393#comment-45075</guid>
		<description><![CDATA[[...] can find the answer out on my blog; Oracle Scratchpad.         Jonathan [...]]]></description>
		<content:encoded><![CDATA[<p>[...] can find the answer out on my blog; Oracle Scratchpad.         Jonathan [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jonathan Lewis</title>
		<link>http://jonathanlewis.wordpress.com/2012/02/09/session-sql/#comment-45044</link>
		<dc:creator><![CDATA[Jonathan Lewis]]></dc:creator>
		<pubDate>Wed, 15 Feb 2012 02:33:46 +0000</pubDate>
		<guid isPermaLink="false">http://jonathanlewis.wordpress.com/?p=8393#comment-45044</guid>
		<description><![CDATA[Valentin,

True on both counts.
It&#039;s also important to remember to include the join on &quot;instance number&quot; when using the gv$ - I&#039;ve seen people forget that occasionally.]]></description>
		<content:encoded><![CDATA[<p>Valentin,</p>
<p>True on both counts.<br />
It&#8217;s also important to remember to include the join on &#8220;instance number&#8221; when using the gv$ &#8211; I&#8217;ve seen people forget that occasionally.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Valentin Nikotin</title>
		<link>http://jonathanlewis.wordpress.com/2012/02/09/session-sql/#comment-45021</link>
		<dc:creator><![CDATA[Valentin Nikotin]]></dc:creator>
		<pubDate>Mon, 13 Feb 2012 20:29:37 +0000</pubDate>
		<guid isPermaLink="false">http://jonathanlewis.wordpress.com/?p=8393#comment-45021</guid>
		<description><![CDATA[Though it&#039;s very expensive to use gv$, and it&#039;ll be better to query v$ having connected to the proper node.]]></description>
		<content:encoded><![CDATA[<p>Though it&#8217;s very expensive to use gv$, and it&#8217;ll be better to query v$ having connected to the proper node.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Valentin Nikotin</title>
		<link>http://jonathanlewis.wordpress.com/2012/02/09/session-sql/#comment-45019</link>
		<dc:creator><![CDATA[Valentin Nikotin]]></dc:creator>
		<pubDate>Mon, 13 Feb 2012 15:54:03 +0000</pubDate>
		<guid isPermaLink="false">http://jonathanlewis.wordpress.com/?p=8393#comment-45019</guid>
		<description><![CDATA[It makes sense to remeber of the using gv$ versions of views on the RAC environment.]]></description>
		<content:encoded><![CDATA[<p>It makes sense to remeber of the using gv$ versions of views on the RAC environment.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Valentin Nikotin</title>
		<link>http://jonathanlewis.wordpress.com/2012/02/09/session-sql/#comment-44993</link>
		<dc:creator><![CDATA[Valentin Nikotin]]></dc:creator>
		<pubDate>Fri, 10 Feb 2012 15:29:01 +0000</pubDate>
		<guid isPermaLink="false">http://jonathanlewis.wordpress.com/?p=8393#comment-44993</guid>
		<description><![CDATA[Here are two more observations about the using predicate with &quot;OR&quot; :

1. You can not determine what it was actually - SQL_ID or PREV_SQL_ID;
2. The query will have worse plan with NL + FIXED TABLE FULL instead of FIXED TABLE FIXED INDEX;]]></description>
		<content:encoded><![CDATA[<p>Here are two more observations about the using predicate with &#8220;OR&#8221; :</p>
<p>1. You can not determine what it was actually &#8211; SQL_ID or PREV_SQL_ID;<br />
2. The query will have worse plan with NL + FIXED TABLE FULL instead of FIXED TABLE FIXED INDEX;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Log Buffer #258, A Carnival of the Vanities for DBAs &#124; The Pythian Blog</title>
		<link>http://jonathanlewis.wordpress.com/2012/02/09/session-sql/#comment-44991</link>
		<dc:creator><![CDATA[Log Buffer #258, A Carnival of the Vanities for DBAs &#124; The Pythian Blog]]></dc:creator>
		<pubDate>Fri, 10 Feb 2012 09:56:03 +0000</pubDate>
		<guid isPermaLink="false">http://jonathanlewis.wordpress.com/?p=8393#comment-44991</guid>
		<description><![CDATA[[...] From time to time a request for a query to “show the current SQL” for each session appears on the internet. Jonathan answers. [...]]]></description>
		<content:encoded><![CDATA[<p>[...] From time to time a request for a query to “show the current SQL” for each session appears on the internet. Jonathan answers. [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Narendra</title>
		<link>http://jonathanlewis.wordpress.com/2012/02/09/session-sql/#comment-44989</link>
		<dc:creator><![CDATA[Narendra]]></dc:creator>
		<pubDate>Fri, 10 Feb 2012 09:25:34 +0000</pubDate>
		<guid isPermaLink="false">http://jonathanlewis.wordpress.com/?p=8393#comment-44989</guid>
		<description><![CDATA[&lt;i&gt;I’ll leave it (temporarily) as an exercise to the reader to explain why this is probably a bad strategy&lt;/i&gt;
Is it because the query is accessing memory structures (and not tables) which are not guaranteed to be read-consistent? So a join (between v$session and v$sql) will not necessarily give correct results. I remember Tanel poder using this to his advantage when he wrote his cool session snapper toolkits.]]></description>
		<content:encoded><![CDATA[<p><i>I’ll leave it (temporarily) as an exercise to the reader to explain why this is probably a bad strategy</i><br />
Is it because the query is accessing memory structures (and not tables) which are not guaranteed to be read-consistent? So a join (between v$session and v$sql) will not necessarily give correct results. I remember Tanel poder using this to his advantage when he wrote his cool session snapper toolkits.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
