<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	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:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Tanel Poder's blog: Core IT for Geeks and Pros &#187; Administration</title>
	<atom:link href="http://blog.tanelpoder.com/category/administration/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.tanelpoder.com</link>
	<description>Oracle troubleshooting, internals and performance tuning</description>
	<lastBuildDate>Sat, 31 Jul 2010 05:44:10 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Dropping and creating tables in read only tablespaces?!</title>
		<link>http://blog.tanelpoder.com/2010/07/11/dropping-and-creating-tables-in-read-only-tablespaces-what/</link>
		<comments>http://blog.tanelpoder.com/2010/07/11/dropping-and-creating-tables-in-read-only-tablespaces-what/#comments</comments>
		<pubDate>Sun, 11 Jul 2010 17:09:12 +0000</pubDate>
		<dc:creator>Tanel Poder</dc:creator>
				<category><![CDATA[Administration]]></category>
		<category><![CDATA[Internals]]></category>
		<category><![CDATA[Oracle]]></category>
		<category><![CDATA[Oracle 11gR2]]></category>

		<guid isPermaLink="false">http://blog.tanelpoder.com/?p=719</guid>
		<description><![CDATA[You probably already know that it&#8217;s possible to drop tables in Oracle read only tablespaces&#8230; (You did know that already, right? ;-) Here&#8217;s a little example: SQL&#62; create tablespace ronly datafile '/u03/oradata/LIN112/ronly.01.dbf' size 10m; Tablespace created. SQL&#62; create table test tablespace ronly as select * from all_users; Table created. SQL&#62; alter tablespace ronly READ ONLY; [...]]]></description>
			<content:encoded><![CDATA[<p>You probably already know that it&#8217;s possible to drop tables in Oracle read only tablespaces&#8230; (You did know that already, right? ;-) Here&#8217;s a little example:</p>
<pre>SQL&gt; create tablespace ronly datafile '/u03/oradata/LIN112/ronly.01.dbf' size 10m;

Tablespace created.

SQL&gt; create table test tablespace ronly as select * from all_users;

Table created.

SQL&gt; alter tablespace ronly READ ONLY;

Tablespace altered.

SQL&gt; drop table test;

Table dropped.</pre>
<p>I just dropped a table from a read only tablespace! Well, perhaps it&#8217;s because that instead of dropping the table was put into recyclebin instead (which is a data dictionary update)? Let&#8217;s check which segments remain in the RONLY tablespace:</p>
<pre>SQL&gt; select owner,segment_name,segment_type from dba_segments where tablespace_name = 'RONLY';

OWNER   SEGMENT_NAME                    SEGMENT_TYPE
------- ------------------------------- ------------------
TANEL   BIN$ix7rAUXZfB3gQKjAgS4LXg==$0  TABLE</pre>
<p>Indeed, it seems that the table segment wasn&#8217;t actually dropped. Well, let&#8217;s purge the recycle bin to try to actually drop the table segment:</p>
<pre>SQL&gt; purge recyclebin;

Recyclebin purged.

SQL&gt; select owner,segment_name,segment_type from dba_segments where tablespace_name = 'RONLY';

OWNER    SEGMENT_NAME                   SEGMENT_TYPE
-------- ------------------------------ ------------------
TANEL    9.130                          TEMPORARY</pre>
<p>Wow, Oracle has converted the table segment into a temporary segment instead (see segment_type)! Bur our tablespace is read only, how can it do that?! The answer is that neither the regular DROP nor DROP PURGE need to write anything into the tablespace where the segment resides! The initial DROP operation just updated data dictionary, like renaming the table to BIN$&#8230; in OBJ$ and so on. The second DROP PURGE operation just ran a bunch of deletes against data dictionary to indicate that the table object is gone. But why is the TEMPORARY segment left behind? This has to do with locally managed tablespaces. Before LMT days, when you dropped a segment, then the segment space was released and acquired back to tablespace through inserts/updates to UET$/FET$ (used/free extents) base tables, which resided in system tablespace like all other data dictionary base tables. But with LMTs, the free space information is kept in bitmaps in the tablespace files themselves! Thus, if you drop a table in a read only LMT tablespace, the table will be gone, but the space will not be physically released (as you can&#8217;t update the LMT bitmaps in read only tablespace files). However, Oracle doesn&#8217;t want to lose that space should someone make the tablespace read write later on, so the table segment is updated to be a TEMPORARY segment instead of completely deleting it from data dictionary. That&#8217;s how the SMON can clean it up later on should that tablespace become read-write again. The 9.130 in SEGMENT_NAME column means relative file# 9 and starting block# 130, that&#8217;s a segment&#8217;s unique identifier in a tablespace. Let&#8217;s move on. This example is executed on Oracle 11.2, while logged on to a non-SYS/SYSTEM user:</p>
<pre>SQL&gt; select status from dba_tablespaces where tablespace_name = 'RONLY';

STATUS
---------
READ ONLY</pre>
<p>The tablespace is still in read only status. Let&#8217;s try to CREATE a table into that tablespace:</p>
<pre>SQL&gt; create table test(a int) tablespace ronly;

Table created.</pre>
<p>What? I can also CREATE a table into a read only tablespace?! Well, this is the behavior you get starting from 11gR2 onwards, it&#8217;s called deferred segment creation, Oracle doesn&#8217;t need to create any segments for a table until you actually insert rows into it! So, Oracle creates all needed metadata about the new table in data dictionary, but doesn&#8217;t actually allocate any space from the tablespace. This applies to other segment types like index and table/index partitions as well. There&#8217;s new syntax which controls the deferred segment creation:</p>
<pre>SQL&gt; drop table test purge;

Table dropped.

SQL&gt; create table test (a int) segment creation IMMEDIATE tablespace ronly;
create table test (a int) segment creation IMMEDIATE tablespace ronly
*
ERROR at line 1:
ORA-01647: tablespace 'RONLY' is read-only, cannot allocate space in it</pre>
<p>In the above case I disabled the deferred segment creation and got an error immediately as Oracle tried to allocate space from the read only tablespace. Let&#8217;s try the other way:</p>
<pre>SQL&gt; create table test (a int) segment creation DEFERRED tablespace ronly;

Table created.</pre>
<p>Now, with deferred segment creation enabled, Oracle didn&#8217;t try to allocate space from the read only tablespace. Let&#8217;s look into the segments in that tablespace again:</p>
<pre>SQL&gt; select owner,segment_name,segment_type from dba_segments where tablespace_name = 'RONLY';

OWNER        SEGMENT_NAME    SEGMENT_TYPE
------------ --------------- ---------------
TANEL        9.130           TEMPORARY</pre>
<p>We still have that old segment from an earlier DROP TABLE operation waiting to be cleaned up (when the tablespace goes into read-write mode again), but no segment for our latest test table created. Let&#8217;s make the tablespace read write and check again:</p>
<pre>SQL&gt; alter tablespace ronly read write;

Tablespace altered.

SQL&gt; select owner,segment_name,segment_type from dba_segments where tablespace_name = 'RONLY';

no rows selected</pre>
<p>Apparently SMON has kicked in already and cleaned up the table segment which had been marked temporary earlier when I dropped the table in a read only tablespace.</p>
<p>Note that tables in SYS and SYSTEM schema can not use deferred segment creation:</p>
<pre>SQL&gt; create table sys.test (a int) segment creation deferred;
create table sys.test (a int) segment creation deferred
*
ERROR at line 1:
ORA-14223: Deferred segment creation is not supported for this table

SQL&gt; create table system.test (a int) segment creation deferred;
create table system.test (a int) segment creation deferred
*
ERROR at line 1:
ORA-14223: Deferred segment creation is not supported for this table

SQL&gt; create table tanel.test (a int) segment creation deferred;

Table created.</pre>
<p>There&#8217;s also a parameter, deferred_segment_creation which controls the default behavior:</p>
<pre>SQL&gt; show parameter deferred

NAME_COL_PLUS_SHOW_PARAM     TYPE        VALUE
---------------------------- ----------- --------
deferred_segment_creation    boolean     TRUE

SQL&gt;</pre>
<div class="facebook_like_button"><iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fblog.tanelpoder.com%2F2010%2F07%2F11%2Fdropping-and-creating-tables-in-read-only-tablespaces-what%2F&amp;layout=standard&amp;show-faces=true&amp;width=450&amp;action=like&amp;font=arial&amp;colorscheme=light" scrolling="no" frameborder="0" allowTransparency="true" style="padding: 0px 0px; border:none; overflow:hidden; width:450px; height:70px;"></iframe></div> <img src="http://blog.tanelpoder.com/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?view=1&post_id=719" width="1" height="1" style="display: none;" /><p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save"><img src="http://blog.tanelpoder.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://blog.tanelpoder.com/2010/07/11/dropping-and-creating-tables-in-read-only-tablespaces-what/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>Flexible Sqlplus command line history with RLWRAP</title>
		<link>http://blog.tanelpoder.com/2010/05/07/flexible-sqlplus-command-line-history-with-rlwrap/</link>
		<comments>http://blog.tanelpoder.com/2010/05/07/flexible-sqlplus-command-line-history-with-rlwrap/#comments</comments>
		<pubDate>Fri, 07 May 2010 22:49:26 +0000</pubDate>
		<dc:creator>Tanel Poder</dc:creator>
				<category><![CDATA[Administration]]></category>
		<category><![CDATA[Cool stuff]]></category>
		<category><![CDATA[Oracle]]></category>
		<category><![CDATA[Productivity]]></category>
		<category><![CDATA[Tools]]></category>

		<guid isPermaLink="false">http://blog.tanelpoder.com/?p=690</guid>
		<description><![CDATA[At Hotsos Symposium Training Day I used rlwrap with sqlplus &#8211; which gives nice command line editing and history capabilities for tools like sqlplus. Additionally I pre-generated commonly used Oracle keywords, data dictionary view and package names into rlwrap wordfile, so I got nice tab-completion too. Sqlplus sucks much less with rlwrap ;-) It&#8217;s relatively [...]]]></description>
			<content:encoded><![CDATA[<p>At Hotsos Symposium Training Day I used rlwrap with sqlplus &#8211; which gives nice command line editing and history capabilities for tools like sqlplus. Additionally I pre-generated commonly used Oracle keywords, data dictionary view and package names into rlwrap wordfile, so I got nice tab-completion too. Sqlplus sucks much less with rlwrap ;-)</p>
<p>It&#8217;s relatively easy to install rlwrap on Unix (there are rlwrap RPMs out there, Solaris freeware packages and I installed it on Mac via macports.org). Just google around&#8230;</p>
<p>You can have rlwrap on Windows too &#8211; As rlwrap has been coded for Unix flavors, then on Windows you need to run it on a Unix library environment emulator &#8211; like Cygwin.</p>
<p>Dave Herring and Michael Paddock have both written an article about how to get rlwrap &amp; sqlplus running on Windows, check out the articles here. It&#8217;s worth reading both as they have different additions&#8230;</p>
<p>So, if you want command line history, search and tab completion for sqlplus on Unix flavors or Windows, check these articles out!</p>
<p><a href="http://blog.tanelpoder.com/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL2RhdmVoZXJyaW5nc2RiYWJsb2cuYmxvZ3Nwb3QuY29tLzIwMTAvMDMvc3FscGx1cy1jb21tYW5kLWhpc3Rvcnktd2l0aC1jeWd3aW4uaHRtbA==">http://daveherringsdbablog.blogspot.com/2010/03/sqlplus-command-history-with-cygwin.html</a></p>
<p><a href="http://blog.tanelpoder.com/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL2Jsb2cuZW5raXRlYy5jb20vMjAxMC8wNC8yOS91c2luZy1zcWxwbHVzLXdpdGgtcmx3cmFwLW9uLW1zLXdpbmRvd3Mv">http://blog.enkitec.com/2010/04/29/using-sqlplus-with-rlwrap-on-ms-windows/</a></p>
<div class="facebook_like_button"><iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fblog.tanelpoder.com%2F2010%2F05%2F07%2Fflexible-sqlplus-command-line-history-with-rlwrap%2F&amp;layout=standard&amp;show-faces=true&amp;width=450&amp;action=like&amp;font=arial&amp;colorscheme=light" scrolling="no" frameborder="0" allowTransparency="true" style="padding: 0px 0px; border:none; overflow:hidden; width:450px; height:70px;"></iframe></div> <img src="http://blog.tanelpoder.com/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?view=1&post_id=690" width="1" height="1" style="display: none;" /><p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save"><img src="http://blog.tanelpoder.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://blog.tanelpoder.com/2010/05/07/flexible-sqlplus-command-line-history-with-rlwrap/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Quiz: Explaining index creation</title>
		<link>http://blog.tanelpoder.com/2010/04/23/quiz-explaining-index-creation/</link>
		<comments>http://blog.tanelpoder.com/2010/04/23/quiz-explaining-index-creation/#comments</comments>
		<pubDate>Fri, 23 Apr 2010 14:49:02 +0000</pubDate>
		<dc:creator>Tanel Poder</dc:creator>
				<category><![CDATA[Administration]]></category>
		<category><![CDATA[Cool stuff]]></category>
		<category><![CDATA[Internals]]></category>
		<category><![CDATA[Oracle]]></category>
		<category><![CDATA[Troubleshooting]]></category>

		<guid isPermaLink="false">http://blog.tanelpoder.com/?p=680</guid>
		<description><![CDATA[Did you know that it&#8217;s possible to use EXPLAIN PLAN FOR CREATE INDEX ON table(col1,col2,col3) syntax for explaining what exactly would be done when an index is created? That&#8217;s useful for example for seeing the Oracle&#8217;s estimated index size without having to actually create the index. You can also use EXPLAIN PLAN FOR ALTER INDEX [...]]]></description>
			<content:encoded><![CDATA[<p>Did you know that it&#8217;s possible to use EXPLAIN PLAN FOR <strong>CREATE INDEX </strong>ON table(col1,col2,col3) syntax for explaining what exactly would be done when an index is created?</p>
<p>That&#8217;s useful for example for seeing the Oracle&#8217;s estimated index size without having to actually create the index.</p>
<p>You can also use EXPLAIN PLAN FOR <strong>ALTER INDEX</strong> i <strong>REBUILD</strong> to see whether this operation would use a FULL TABLE SCAN or a FAST FULL INDEX SCAN (offline index rebuilds of valid indexes can use this method).</p>
<p>Anyway, you can experiment with this yourself, but here&#8217;s a little quiz (with a little gotcha :)</p>
<p>What kind of index creation statement would create such an execution plan?</p>
<pre>SQL&gt; explain plan for create index hack_index on hack_table ....the rest is a secret for now....
Explained.
<span style="font-family: Georgia, 'Times New Roman', 'Bitstream Charter', Times, serif; font-size: small;"><span style="line-height: 19px; white-space: normal;"><span style="font-family: Consolas, Monaco, 'Courier New', Courier, monospace; font-size: small;"><span style="line-height: 18px; white-space: pre;">
<pre>PLAN_TABLE_OUTPUT
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Plan hash value: 457720527
-------------------------------------------------------------------------------------------------
| Id  | Operation                | Name                 | Rows  | Bytes | Cost (%CPU)| Time     |
-------------------------------------------------------------------------------------------------
|   0 | CREATE INDEX STATEMENT   |                      | 88868 |       |   657   (1)| 00:00:12 |
|   1 |  INDEX BUILD NON UNIQUE  | HACK_INDEX           |       |       |            |          |
|   2 |   SORT AGGREGATE         |                      |     1 |       |            |          |
|   3 |    VIEW                  | HACK_VIEW            | 74062 |       |   318   (1)| 00:00:06 |
|*  4 |     HASH JOIN            |                      | 74062 |  1012K|   210   (1)| 00:00:04 |
|   5 |      TABLE ACCESS FULL   | TEST_USERS           |    46 |   368 |     4   (0)| 00:00:01 |
|   6 |      INDEX FAST FULL SCAN| IDX2_INDEXED_OBJECTS | 74062 |   433K|   206   (1)| 00:00:04 |
|   7 |   SORT CREATE INDEX      |                      | 88868 |       |            |          |
|   8 |    TABLE ACCESS FULL     | HACK_TABLE           | 88868 |       |   544   (1)| 00:00:10 |
-------------------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
4 - access("U"."USERNAME"="O"."OWNER")
Note
-----
- estimated index size: 3145K bytes</pre>
<p></span></span></span></span></pre>
<div class="facebook_like_button"><iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fblog.tanelpoder.com%2F2010%2F04%2F23%2Fquiz-explaining-index-creation%2F&amp;layout=standard&amp;show-faces=true&amp;width=450&amp;action=like&amp;font=arial&amp;colorscheme=light" scrolling="no" frameborder="0" allowTransparency="true" style="padding: 0px 0px; border:none; overflow:hidden; width:450px; height:70px;"></iframe></div> <img src="http://blog.tanelpoder.com/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?view=1&post_id=680" width="1" height="1" style="display: none;" /><p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save"><img src="http://blog.tanelpoder.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://blog.tanelpoder.com/2010/04/23/quiz-explaining-index-creation/feed/</wfw:commentRss>
		<slash:comments>13</slash:comments>
		</item>
		<item>
		<title>Non-trivial performance problems</title>
		<link>http://blog.tanelpoder.com/2010/04/03/non-trivial-performance-problems/</link>
		<comments>http://blog.tanelpoder.com/2010/04/03/non-trivial-performance-problems/#comments</comments>
		<pubDate>Sat, 03 Apr 2010 10:07:26 +0000</pubDate>
		<dc:creator>Tanel Poder</dc:creator>
				<category><![CDATA[Administration]]></category>
		<category><![CDATA[Oracle]]></category>
		<category><![CDATA[Performance]]></category>
		<category><![CDATA[Troubleshooting]]></category>
		<category><![CDATA[Tuning]]></category>
		<category><![CDATA[SQL]]></category>

		<guid isPermaLink="false">http://blog.tanelpoder.com/?p=665</guid>
		<description><![CDATA[Gwen Shapira has written an article about a good example of a non-trivial performance problem. I&#8217;m not talking about anything advanced here (such as bugs or problems arising at OS/Oracle touchpoint) but that sometimes the root cause of a problem (or at least the reason why you notice this problem now) is not something deeply [...]]]></description>
			<content:encoded><![CDATA[<p>Gwen Shapira has written an article about a good example of a <a href="http://blog.tanelpoder.com/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3Byb2RsaWZlLndvcmRwcmVzcy5jb20vMjAxMC8wNC8wMi9kYXlsaWdodC1zYXZpbmctdGltZS1jYXVzZXMtcGVyZm9ybWFuY2UtaXNzdWVzLw==">non-trivial performance problem</a>.</p>
<p>I&#8217;m not talking about anything advanced here (such as bugs or problems arising at OS/Oracle touchpoint) but that sometimes the root cause of a problem (or at least the reason why you notice this problem now) is not something deeply technical or related to some specific SQL optimizer feature or a configuration issue. Instead of focusing on the first symptom you see immediately, it pays off to take a step back and see how the problem task/application/SQL is actually used by the users or client applications.</p>
<p>In other words, talk to the users, ask how exactly they experience the problem and then drill down from there.</p>
<div class="facebook_like_button"><iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fblog.tanelpoder.com%2F2010%2F04%2F03%2Fnon-trivial-performance-problems%2F&amp;layout=standard&amp;show-faces=true&amp;width=450&amp;action=like&amp;font=arial&amp;colorscheme=light" scrolling="no" frameborder="0" allowTransparency="true" style="padding: 0px 0px; border:none; overflow:hidden; width:450px; height:70px;"></iframe></div> <img src="http://blog.tanelpoder.com/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?view=1&post_id=665" width="1" height="1" style="display: none;" /><p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save"><img src="http://blog.tanelpoder.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://blog.tanelpoder.com/2010/04/03/non-trivial-performance-problems/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>New versions of LatchProf and LatchProfX for latch contention troubleshooting and tuning</title>
		<link>http://blog.tanelpoder.com/2010/02/15/new-versions-of-latchprof-and-latchprofx-for-latch-contention-troubleshooting-and-tuning/</link>
		<comments>http://blog.tanelpoder.com/2010/02/15/new-versions-of-latchprof-and-latchprofx-for-latch-contention-troubleshooting-and-tuning/#comments</comments>
		<pubDate>Tue, 16 Feb 2010 03:01:51 +0000</pubDate>
		<dc:creator>Tanel Poder</dc:creator>
				<category><![CDATA[Administration]]></category>
		<category><![CDATA[Cool stuff]]></category>
		<category><![CDATA[Oracle]]></category>
		<category><![CDATA[Performance]]></category>
		<category><![CDATA[Troubleshooting]]></category>

		<guid isPermaLink="false">http://blog.tanelpoder.com/?p=620</guid>
		<description><![CDATA[The LatchProf and LatchProfX scripts allow you to be more systematic with latch contention troubleshooting and tuning. No more guesswork is needed as these scripts give you exact session IDs and in this version also SQLIDs of the troublemaking applications. You can download the new versions here: LatchProf (reads V$ views) LatchProfX (reads X$ tables, [...]]]></description>
			<content:encoded><![CDATA[<p>The LatchProf and LatchProfX scripts allow you to be more systematic with latch contention troubleshooting and tuning. No more guesswork is needed as these scripts give you exact session IDs and in this version also SQLIDs of the troublemaking applications.</p>
<p>You can download the new versions here:</p>
<ul>
<li><a href="http://blog.tanelpoder.com/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3d3dy50YW5lbHBvZGVyLmNvbS9maWxlcy9zY3JpcHRzL2xhdGNocHJvZi5zcWw=" target=\"_blank\">LatchProf</a> (reads V$ views)</li>
<li><a href="http://blog.tanelpoder.com/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3d3dy50YW5lbHBvZGVyLmNvbS9maWxlcy9zY3JpcHRzL2xhdGNocHJvZnguc3Fs" target=\"_blank\">LatchProfX</a> (reads X$ tables, but gives better info, run as SYS)</li>
</ul>
<p>Example output (with SQLID info) is below:</p>
<pre class="brush: plain;">SQL&gt; @latchprof name,sid,sqlid % % 100000

-- LatchProf 1.21 by Tanel Poder ( http://www.tanelpoder.com )

NAME                                       SID SQLID               Held       Gets  Held %     Held ms Avg hold ms
----------------------------------- ---------- ------------- ---------- ---------- ------- ----------- -----------
cache buffers chains                       133 3jbwa65aqmkvm        349        348     .35      14.169        .041
simulator lru latch                        133 3jbwa65aqmkvm         51         51     .05       2.071        .041
row cache objects                          133 3jbwa65aqmkvm          5          5     .01        .203        .041
cache buffers chains                        24                        5          5     .01        .203        .041
cache buffers chains                       149 3jbwa65aqmkvm          3          3     .00        .122        .041
resmgr group change latch                   33 147a57cxq3w5y          2          2     .00        .081        .041
cache buffers chains                         9 5raw2bzx227wp          2          1     .00        .081        .081
In memory undo latch                       149 f3y38zthh270n          2          1     .00        .081        .081
active checkpoint queue latch                5                        2          1     .00        .081        .081
cache buffers chains                       149 75621g9y3xmvd          2          2     .00        .081        .041
cache buffers chains                         9 gvgdv2v90wfa7          2          2     .00        .081        .041
cache buffers chains                        33 75621g9y3xmvd          2          2     .00        .081        .041
checkpoint queue latch                       5                        1          1     .00        .041        .041
ksuosstats global area                       8                        1          1     .00        .041        .041
cache buffers lru chain                    133 3jbwa65aqmkvm          1          1     .00        .041        .041
multiblock read objects                    155 75ju2gn3s8009          1          1     .00        .041        .041
resmgr group change latch                    9 0w2qpuc6u2zsp          1          1     .00        .041        .041
resmgr group change latch                   33 apgb2g9q2zjh1          1          1     .00        .041        .041
resmgr group change latch                  133 apgb2g9q2zjh1          1          1     .00        .041        .041
space background task latch                 17                        1          1     .00        .041        .041
cache buffers chains                       149 5raw2bzx227wp          1          1     .00        .041        .041
cache buffers chains                        33 5raw2bzx227wp          1          1     .00        .041        .041
cache buffers chains                        33 05s4vdwsf5802          1          1     .00        .041        .041
cache buffers chains                        31 0yas01u2p9ch4          1          1     .00        .041        .041
cache buffers chains                         9 41zu158rqf4kf          1          1     .00        .041        .041
In memory undo latch                        33 0bzhqhhj9mpaa          1          1     .00        .041        .041
In memory undo latch                        31 gvgdv2v90wfa7          1          1     .00        .041        .041
In memory undo latch                         9 gvgdv2v90wfa7          1          1     .00        .041        .041
simulator lru latch                        149 3jbwa65aqmkvm          1          1     .00        .041        .041
row cache objects                          133 5yq51dtyc6qf2          1          1     .00        .041        .041
SQL memory manager workarea list la        133 3jbwa65aqmkvm          1          1     .00        .041        .041
enqueues                                   141                        1          1     .00        .041        .041
row cache objects                          132                        1          1     .00        .041        .041

33 rows selected.
</pre>
<p>LatchProf scripts allow you to easily identify which session and SQLID (or sqlhash in 9i) cause the latch(es) to be held the most.</p>
<p>Let&#8217;s check what&#8217;s the most &#8220;latch-holding&#8221; SQL reported by LatchProf:</p>
<pre class="brush: sql;">SQL&gt; @sqlid 3jbwa65aqmkvm

HASH_VALUE  CH# SQL_TEXT
---------- ---- ------------------------------------------------------------------------------------------------------------------------------------------------------
1432996723    0 SELECT O.ORDER_ID, LINE_ITEM_ID, PRODUCT_ID, UNIT_PRICE, QUANTITY, ORDER_MODE, ORDER_STATUS, ORDER_TOTAL, SALES_REP_ID, PROMOTION_ID, C.CUSTOMER_ID,
 CUST_FIRST_NAME, CUST_LAST_NAME, CREDIT_LIMIT, CUST_EMAIL, ORDER_DATE FROM ORDERS O , ORDER_ITEMS OI, CUSTOMERS C WHERE O.ORDER_ID = OI.ORDER_ID AND
 O.CUSTOMER_ID = C.CUSTOMER_ID AND O.ORDER_STATUS &lt;= 4
</pre>
<p>If you want to read more about the capabilities of LatchProf and LatchProfX, go here:</p>
<ul>
<li><a href="http://blog.tanelpoder.com/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL2Jsb2cudGFuZWxwb2Rlci5jb20vMjAwOC8wNy8wOS9hZHZhbmNlZC1vcmFjbGUtdHJvdWJsZXNob290aW5nLWd1aWRlLXBhcnQtNy1zYW1wbGluZy1sYXRjaC1ob2xkZXItc3RhdGlzdGljcy11c2luZy1sYXRjaHByb2Yv">http://blog.tanelpoder.com/2008/07/09/advanced-oracle-troubleshooting-guide-part-7-sampling-latch-holder-statistics-using-latchprof/</a></li>
<li><a href="http://blog.tanelpoder.com/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL2Jsb2cudGFuZWxwb2Rlci5jb20vMjAwOC8wNy8yMy9hZHZhbmNlZC1vcmFjbGUtdHJvdWJsZXNob290aW5nLWd1aWRlLXBhcnQtOC1ldmVuLW1vcmUtZGV0YWlsZWQtbGF0Y2gtdHJvdWJsZXNob290aW5nLXVzaW5nLWxhdGNocHJvZngv">http://blog.tanelpoder.com/2008/07/23/advanced-oracle-troubleshooting-guide-part-8-even-more-detailed-latch-troubleshooting-using-latchprofx/</a></li>
</ul>
<p>Note that the latest version (v1.21) also fixes a problem with Oracle 11.2 where the script execution plan order was wrong, causing the sampling to not happen in correct order. I added a NO_TRANSFORM_DISTINCT_AGG hint to disable a new transformation happening in 11.2 to make the scripts behave correctly&#8230;</p>
<div class="facebook_like_button"><iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fblog.tanelpoder.com%2F2010%2F02%2F15%2Fnew-versions-of-latchprof-and-latchprofx-for-latch-contention-troubleshooting-and-tuning%2F&amp;layout=standard&amp;show-faces=true&amp;width=450&amp;action=like&amp;font=arial&amp;colorscheme=light" scrolling="no" frameborder="0" allowTransparency="true" style="padding: 0px 0px; border:none; overflow:hidden; width:450px; height:70px;"></iframe></div> <img src="http://blog.tanelpoder.com/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?view=1&post_id=620" width="1" height="1" style="display: none;" /><p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save"><img src="http://blog.tanelpoder.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://blog.tanelpoder.com/2010/02/15/new-versions-of-latchprof-and-latchprofx-for-latch-contention-troubleshooting-and-tuning/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Oracle Troubleshooting: How to read Oracle ERRORSTACK output?!</title>
		<link>http://blog.tanelpoder.com/2010/02/14/oracle-troubleshooting-how-to-read-oracle-errorstack-output/</link>
		<comments>http://blog.tanelpoder.com/2010/02/14/oracle-troubleshooting-how-to-read-oracle-errorstack-output/#comments</comments>
		<pubDate>Sun, 14 Feb 2010 18:41:46 +0000</pubDate>
		<dc:creator>Tanel Poder</dc:creator>
				<category><![CDATA[Administration]]></category>
		<category><![CDATA[Cool stuff]]></category>
		<category><![CDATA[Internals]]></category>
		<category><![CDATA[Oracle]]></category>
		<category><![CDATA[Troubleshooting]]></category>
		<category><![CDATA[Tuning]]></category>

		<guid isPermaLink="false">http://blog.tanelpoder.com/?p=617</guid>
		<description><![CDATA[I have written the first article to the troubleshooting section of my new website tech.E2SN.com: It&#8217;s about a very valuable Oracle troubleshooting tool -&#62; ERRORSTACK trace. I cover 4 frequently asked questions there: Reading the current executing SQL statement text from errorstack trace Reading the current executing PL/SQL package and PL/SQL source code line number [...]]]></description>
			<content:encoded><![CDATA[<p>I have written the first article to the troubleshooting section of my new website tech.E2SN.com:</p>
<p>It&#8217;s about a very valuable Oracle troubleshooting tool -&gt; ERRORSTACK trace.</p>
<p>I cover 4 frequently asked questions there:</p>
<ol>
<li>Reading the current executing SQL statement text from errorstack trace</li>
<li>Reading the current executing PL/SQL package and PL/SQL source code line number from errorstack trace</li>
<li>Reading the current bind variable values from errostack trace</li>
<li>Identifying how much private (UGA) memory a cursor is using</li>
</ol>
<p>You can read it here:</p>
<ul>
<li><a href="http://blog.tanelpoder.com/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3RlY2guZTJzbi5jb20vb3JhY2xlL3Ryb3VibGVzaG9vdGluZy9ob3ctdG8tcmVhZC1lcnJvcnN0YWNrLW91dHB1dA==" target=\"_blank\">http://tech.e2sn.com/oracle/troubleshooting/how-to-read-errorstack-output</a></li>
</ul>
<p>By the way, if you like my new website, feel free to link to it !!! ;-)</p>
<ul>
<li><a href="http://blog.tanelpoder.com/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3RlY2guZTJzbi5jb20=" target=\"_blank\">http://tech.e2sn.com</a></li>
</ul>
<div class="facebook_like_button"><iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fblog.tanelpoder.com%2F2010%2F02%2F14%2Foracle-troubleshooting-how-to-read-oracle-errorstack-output%2F&amp;layout=standard&amp;show-faces=true&amp;width=450&amp;action=like&amp;font=arial&amp;colorscheme=light" scrolling="no" frameborder="0" allowTransparency="true" style="padding: 0px 0px; border:none; overflow:hidden; width:450px; height:70px;"></iframe></div> <img src="http://blog.tanelpoder.com/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?view=1&post_id=617" width="1" height="1" style="display: none;" /><p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save"><img src="http://blog.tanelpoder.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://blog.tanelpoder.com/2010/02/14/oracle-troubleshooting-how-to-read-oracle-errorstack-output/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Recursive sessions&#8230;</title>
		<link>http://blog.tanelpoder.com/2010/01/21/recursive-sessions-2/</link>
		<comments>http://blog.tanelpoder.com/2010/01/21/recursive-sessions-2/#comments</comments>
		<pubDate>Fri, 22 Jan 2010 04:43:29 +0000</pubDate>
		<dc:creator>Tanel Poder</dc:creator>
				<category><![CDATA[Administration]]></category>
		<category><![CDATA[Oracle]]></category>
		<category><![CDATA[Troubleshooting]]></category>

		<guid isPermaLink="false">http://blog.tanelpoder.com/?p=577</guid>
		<description><![CDATA[I have published a new article to tech.e2sn.com about recursive sessions and ORA-00018: maximum number of sessions exceeded error message: http://tech.e2sn.com/oracle/oracle-internals-and-architecture/recursive-sessions-and-ora-00018-maximum-number-of-sessions-exceeded Note that I&#8217;m working on setting up RSS feed for tech.e2sn too, coming soon :)]]></description>
			<content:encoded><![CDATA[<p>I have published a new article to tech.e2sn.com about recursive sessions and <strong>ORA-00018: maximum number of sessions exceeded</strong> error message:</p>
<p><a href="http://blog.tanelpoder.com/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3RlY2guZTJzbi5jb20vb3JhY2xlL29yYWNsZS1pbnRlcm5hbHMtYW5kLWFyY2hpdGVjdHVyZS9yZWN1cnNpdmUtc2Vzc2lvbnMtYW5kLW9yYS0wMDAxOC1tYXhpbXVtLW51bWJlci1vZi1zZXNzaW9ucy1leGNlZWRlZA==" target=\"_blank\">http://tech.e2sn.com/oracle/oracle-internals-and-architecture/recursive-sessions-and-ora-00018-maximum-number-of-sessions-exceeded</a></p>
<p>Note that I&#8217;m working on setting up RSS feed for tech.e2sn too, coming soon :)</p>
<div class="facebook_like_button"><iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fblog.tanelpoder.com%2F2010%2F01%2F21%2Frecursive-sessions-2%2F&amp;layout=standard&amp;show-faces=true&amp;width=450&amp;action=like&amp;font=arial&amp;colorscheme=light" scrolling="no" frameborder="0" allowTransparency="true" style="padding: 0px 0px; border:none; overflow:hidden; width:450px; height:70px;"></iframe></div> <img src="http://blog.tanelpoder.com/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?view=1&post_id=577" width="1" height="1" style="display: none;" /><p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save"><img src="http://blog.tanelpoder.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://blog.tanelpoder.com/2010/01/21/recursive-sessions-2/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>My new website tech.e2sn.com and a new application</title>
		<link>http://blog.tanelpoder.com/2010/01/18/my-new-website-tech-e2sn-com-and-a-new-application/</link>
		<comments>http://blog.tanelpoder.com/2010/01/18/my-new-website-tech-e2sn-com-and-a-new-application/#comments</comments>
		<pubDate>Mon, 18 Jan 2010 18:45:40 +0000</pubDate>
		<dc:creator>Tanel Poder</dc:creator>
				<category><![CDATA[Administration]]></category>
		<category><![CDATA[Cool stuff]]></category>
		<category><![CDATA[Internals]]></category>
		<category><![CDATA[Oracle]]></category>
		<category><![CDATA[Performance]]></category>
		<category><![CDATA[Productivity]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[Tools]]></category>

		<guid isPermaLink="false">http://blog.tanelpoder.com/?p=574</guid>
		<description><![CDATA[In early January I wrote that I&#8217;m gonna start organizing the more serious and practical Oracle content into my new website and I&#8217;ll leave my blog for Oracle hacks, my (IT) observations and philosophy, general thoughts and just fun. It&#8217;s time to publish the newsite now with an application demo rototype which gives some clue [...]]]></description>
			<content:encoded><![CDATA[<p>In early January I wrote that I&#8217;m gonna start organizing the more serious and practical Oracle content into my new website and I&#8217;ll leave my blog for Oracle hacks, my (IT) observations and philosophy, general thoughts and just fun.</p>
<p>It&#8217;s time to publish the newsite now with an application <em>demo rototype</em> which gives some clue of what kind of features will there be in the secret project I&#8217;ve been working on for several months with my friend and business partner.</p>
<p>The website is located here:</p>
<h3><a href="http://blog.tanelpoder.com/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3RlY2guZTJzbi5jb20=" target=\"_blank\">http://tech.e2sn.com</a></h3>
<p>E2SN <em>does</em> have a meaning, but I&#8217;ll leave it a secret for now ( you are free to guess ;-)</p>
<p>So, there&#8217;s not much technical content at the site yet, but there&#8217;s a cool online app which you should check if you deal with SQL tuning and execution plan analysis much.</p>
<p>It&#8217;s called PlanViz, Oracle Execution Plan Visualization app, you can check it out here:</p>
<h3></h3>
<h3><a href="http://blog.tanelpoder.com/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3RlY2guZTJzbi5jb20vYXBwcy9wbGFudml6Lw==" target=\"_blank\">http://tech.e2sn.com/apps/planviz</a></h3>
<p>Oh, I&#8217;ve also created something called a &#8220;Living Book&#8221; into my website, where I will write about Oracle, performance, troubleshooting, etc. There is also a place where people can request what I should write about there!</p>
<p>And that&#8217;s all for today!</p>
<div class="facebook_like_button"><iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fblog.tanelpoder.com%2F2010%2F01%2F18%2Fmy-new-website-tech-e2sn-com-and-a-new-application%2F&amp;layout=standard&amp;show-faces=true&amp;width=450&amp;action=like&amp;font=arial&amp;colorscheme=light" scrolling="no" frameborder="0" allowTransparency="true" style="padding: 0px 0px; border:none; overflow:hidden; width:450px; height:70px;"></iframe></div> <img src="http://blog.tanelpoder.com/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?view=1&post_id=574" width="1" height="1" style="display: none;" /><p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save"><img src="http://blog.tanelpoder.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://blog.tanelpoder.com/2010/01/18/my-new-website-tech-e2sn-com-and-a-new-application/feed/</wfw:commentRss>
		<slash:comments>14</slash:comments>
		</item>
		<item>
		<title>Sometimes things are easy (Part 1): How to fix wrapped execution plan text?</title>
		<link>http://blog.tanelpoder.com/2010/01/18/sometimes-things-are-easy-part-1-how-to-fix-wrapped-execution-plan-text/</link>
		<comments>http://blog.tanelpoder.com/2010/01/18/sometimes-things-are-easy-part-1-how-to-fix-wrapped-execution-plan-text/#comments</comments>
		<pubDate>Mon, 18 Jan 2010 16:26:33 +0000</pubDate>
		<dc:creator>Tanel Poder</dc:creator>
				<category><![CDATA[Administration]]></category>
		<category><![CDATA[Oracle]]></category>
		<category><![CDATA[Productivity]]></category>
		<category><![CDATA[Tools]]></category>
		<category><![CDATA[Unix/Linux]]></category>

		<guid isPermaLink="false">http://blog.tanelpoder.com/?p=568</guid>
		<description><![CDATA[What you see below is a common problem. Someone sends you (or posts to a forum) a wide execution plan, which is unreadable because of wrapped lines. For example, this one below: -------------------------------------------------------------------------------- ------------------- &#124; Id  &#124; Operation                   &#124; Name                    &#124; E-Rows &#124;  OMem &#124; 1Mem &#124; Used-Mem &#124; -------------------------------------------------------------------------------- ------------------- &#124;   0 &#124; SELECT [...]]]></description>
			<content:encoded><![CDATA[<p>What you see below is a common problem. Someone sends you (or posts to a forum) a wide execution plan, which is unreadable because of wrapped lines. For example, this one below:</p>
<pre>--------------------------------------------------------------------------------
-------------------

| Id  | Operation                   | Name                    | E-Rows |  OMem |
 1Mem | Used-Mem |

--------------------------------------------------------------------------------
-------------------

|   0 | SELECT STATEMENT            |                         |        |       |
 |          |

|   1 |  SORT AGGREGATE             |                         |      1 |       |
 |          |

|*  2 |   HASH JOIN                 |                         |     13 |  1102K|
 1102K|  355K (0)|

|*  3 |    HASH JOIN                |                         |     13 |   988K|
 988K|  367K (0)|

|*  4 |     HASH JOIN               |                         |     13 |   921K|
 921K|  621K (0)|

|*  5 |      HASH JOIN OUTER        |                         |     13 |   836K|
 836K| 1224K (0)|

|*  6 |       HASH JOIN             |                         |     13 |   821K|
 821K|  501K (0)|

|*  7 |        HASH JOIN            |                         |     13 |  1102K|
 1102K|  501K (0)|

|   8 |         MERGE JOIN CARTESIAN|                         |      1 |       |
 |          |

|*  9 |          TABLE ACCESS FULL  | PROFILE$                |      1 |       |
 |          |

|  10 |          BUFFER SORT        |                         |      1 | 73728 |
 73728 |          |

|* 11 |           TABLE ACCESS FULL | PROFILE$                |      1 |       |
 |          |

|* 12 |         TABLE ACCESS FULL   | USER$                   |     36 |       |
 |          |

|  13 |        TABLE ACCESS FULL    | PROFNAME$               |      1 |       |
 |          |

|* 14 |       TABLE ACCESS FULL     | RESOURCE_GROUP_MAPPING$ |      1 |       |
 |          |

|  15 |      TABLE ACCESS FULL      | TS$                     |      7 |       |
 |          |

|  16 |     TABLE ACCESS FULL       | TS$                     |      7 |       |
 |          |

|  17 |    TABLE ACCESS FULL        | USER_ASTATUS_MAP        |      9 |       |
 |          |

--------------------------------------------------------------------------------
-------------------
</pre>
<p>So now you either try to manually edit and fix the execution plan text so you could read it or ask the developer to send the execution plan again. Both approaches take time.</p>
<p>Well, sometimes things are easy &#8211; in this particular case I saved the above into a file called /tmp/x and ran the following command:</p>
<pre>$ cat /tmp/x | <strong>awk '{ printf "%s", $0 ; if (NR % 3 == 0) print } END { print }'</strong>
---------------------------------------------------------------------------------------------------
| Id  | Operation                   | Name                    | E-Rows |  OMem | 1Mem | Used-Mem |
---------------------------------------------------------------------------------------------------
|   0 | SELECT STATEMENT            |                         |        |       | |          |
|   1 |  SORT AGGREGATE             |                         |      1 |       | |          |
|*  2 |   HASH JOIN                 |                         |     13 |  1102K| 1102K|  355K (0)|
|*  3 |    HASH JOIN                |                         |     13 |   988K| 988K|  367K (0)|
|*  4 |     HASH JOIN               |                         |     13 |   921K| 921K|  621K (0)|
|*  5 |      HASH JOIN OUTER        |                         |     13 |   836K| 836K| 1224K (0)|
|*  6 |       HASH JOIN             |                         |     13 |   821K| 821K|  501K (0)|
|*  7 |        HASH JOIN            |                         |     13 |  1102K| 1102K|  501K (0)|
|   8 |         MERGE JOIN CARTESIAN|                         |      1 |       | |          |
|*  9 |          TABLE ACCESS FULL  | PROFILE$                |      1 |       | |          |
|  10 |          BUFFER SORT        |                         |      1 | 73728 | 73728 |          |
|* 11 |           TABLE ACCESS FULL | PROFILE$                |      1 |       | |          |
|* 12 |         TABLE ACCESS FULL   | USER$                   |     36 |       | |          |
|  13 |        TABLE ACCESS FULL    | PROFNAME$               |      1 |       | |          |
|* 14 |       TABLE ACCESS FULL     | RESOURCE_GROUP_MAPPING$ |      1 |       | |          |
|  15 |      TABLE ACCESS FULL      | TS$                     |      7 |       | |          |
|  16 |     TABLE ACCESS FULL       | TS$                     |      7 |       | |          |
|  17 |    TABLE ACCESS FULL        | USER_ASTATUS_MAP        |      9 |       | |          |
---------------------------------------------------------------------------------------------------</pre>
<p>All I did here was that I stripped out line feeds from all lines except every 3rd line (which is the real end of the original line).</p>
<p>Note that if your linesize is very wide (and trimspool/trimout settings are ON) then this script would need some adjustment&#8230;</p>
<p>I&#8217;m sure this trivial approach doesn&#8217;t work in all situations, but with this article I wanted to illustrate that sometimes things which seem hard can be made much easier with a little scripting knowledge. If you are thinking which technology you should learn next &#8211; then better check out a Perl, Python or some shell+AWK book :)</p>
<p>By the way, if you want real flexibility displaying your execution plans (from library cache), then check this out:</p>
<p><a href="http://blog.tanelpoder.com/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL2Jsb2cudGFuZWxwb2Rlci5jb20vMjAwOS8wNS8yNi9zY3JpcHRzLWZvci1zaG93aW5nLWV4ZWN1dGlvbi1wbGFucy12aWEtcGxhaW4tc3FsLWFuZC1hbHNvLWluLW9yYWNsZS05aS8=">http://blog.tanelpoder.com/2009/05/26/scripts-for-showing-execution-plans-via-plain-sql-and-also-in-oracle-9i/</a></p>
<div class="facebook_like_button"><iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fblog.tanelpoder.com%2F2010%2F01%2F18%2Fsometimes-things-are-easy-part-1-how-to-fix-wrapped-execution-plan-text%2F&amp;layout=standard&amp;show-faces=true&amp;width=450&amp;action=like&amp;font=arial&amp;colorscheme=light" scrolling="no" frameborder="0" allowTransparency="true" style="padding: 0px 0px; border:none; overflow:hidden; width:450px; height:70px;"></iframe></div> <img src="http://blog.tanelpoder.com/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?view=1&post_id=568" width="1" height="1" style="display: none;" /><p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save"><img src="http://blog.tanelpoder.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://blog.tanelpoder.com/2010/01/18/sometimes-things-are-easy-part-1-how-to-fix-wrapped-execution-plan-text/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Explain Plan For command may show you the wrong execution plan &#8211; Part 1</title>
		<link>http://blog.tanelpoder.com/2009/11/17/explain-plan-for-command-may-show-you-the-wrong-execution-plan-part-1/</link>
		<comments>http://blog.tanelpoder.com/2009/11/17/explain-plan-for-command-may-show-you-the-wrong-execution-plan-part-1/#comments</comments>
		<pubDate>Wed, 18 Nov 2009 02:33:24 +0000</pubDate>
		<dc:creator>Tanel Poder</dc:creator>
				<category><![CDATA[Administration]]></category>
		<category><![CDATA[Oracle]]></category>
		<category><![CDATA[Performance]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[Troubleshooting]]></category>

		<guid isPermaLink="false">http://blog.tanelpoder.com/?p=494</guid>
		<description><![CDATA[In Oracle-L mailing list a question was asked about under which conditions can the explain plan report a wrong execution plan (not the one which was actually used when a problem happened). I replied this, but thought to show an example test case of this problem too: 1) The optimizer statistics the EXPLAIN PLAN ends [...]]]></description>
			<content:encoded><![CDATA[<p>In Oracle-L mailing list <a href="http://blog.tanelpoder.com/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3d3dy5mcmVlbGlzdHMub3JnL3Bvc3Qvb3JhY2xlLWwvZXhwbGFpbi1wbGFuLWFuZC10aGUtcmVhbC1leGVjdXRpb24tcGxhbg==" target=\"_blank\">a question</a> was asked about under which conditions can the explain plan report a wrong execution plan (not the one which was actually used when a problem happened).</p>
<p>I replied this, but thought to show an example test case of this problem too:</p>
<blockquote><p><em>1) The optimizer statistics the EXPLAIN PLAN ends up using are different<br />
from the statistics the other session ended up using</em></p>
<p><em>2) Explain plan does not use bind variable peeking thus will not optimize<br />
for current bind variable values</em></p>
<p><em>3) Explain plan treats all bind variables as VARCHAR2, thus you ma have<br />
implicit datatype conversion happening during the plan execution, (meaning<br />
to_char,to_number functions are added around variables/columns) and this for<br />
example may make optimizer to ignore some indexes if you get unlucky.</em></p>
<p><em>&#8230;Of course explain plan doesn&#8217;t really<br />
execute the plan so the implicit datatype conversion you see is in the<br />
explained plan only, but if you actually execute the statement (with correct<br />
bind datatypes) then there&#8217;s no implicit datatype conversion. And that&#8217;s<br />
where the difference comes from&#8230;</em></p></blockquote>
<p>And here comes an example of condition number 3 above. Lets use a little bit of bad design out there and put numeric values into varchar2 columns:</p>
<pre>SQL&gt; create table t (id varchar2(10), name varchar2(100));

Table created.

SQL&gt; insert into t select to_char(object_id), object_name from dba_objects;

51449 rows created.</pre>
<p>Now we add a little index for lookup performance and gather stats:</p>
<pre>SQL&gt; create index i on t(id);

Index created.

SQL&gt; exec dbms_stats.gather_table_stats(user,'T',cascade=&gt;true);

PL/SQL procedure successfully completed.</pre>
<p>Now lets define a bind variable of NUMBER type and set a value for it:</p>
<pre>SQL&gt; var x number
SQL&gt;
SQL&gt; exec :x:=99999

PL/SQL procedure successfully completed.</pre>
<p>Now lets use &#8220;explain plan for&#8221; to estimate the execution plan:</p>
<pre>SQL&gt; <strong>explain plan for</strong>
 2  select sum(length(name)) from t where id &gt;  :x;

Explained.

SQL&gt; select * from table(dbms_xplan.display) ;

PLAN_TABLE_OUTPUT
-------------------------------------------------------------------------------------
Plan hash value: 3694077449

-------------------------------------------------------------------------------------
| Id  | Operation                    | Name | Rows  | Bytes | Cost (%CPU)| Time     |
-------------------------------------------------------------------------------------
|   0 | SELECT STATEMENT             |      |     1 |    29 |    56   (0)| 00:00:01 |
|   1 |  SORT AGGREGATE              |      |     1 |    29 |            |          |
|   2 |   TABLE ACCESS BY INDEX ROWID| T    |  2572 | 74588 |    56   (0)| 00:00:01 |
|*  3 |    <strong>INDEX RANGE SCAN</strong>          | I    |   463 |       |     3   (0)| 00:00:01 |
-------------------------------------------------------------------------------------

Predicate Information (identified by operation id):
---------------------------------------------------

 3 - access("ID"&gt;:X)

15 rows selected.</pre>
<p>Explain plan command nicely reports that we&#8217;d be using an index range scan, which would be a good thing to do given my test data and search condition.</p>
<p>Now lets actually run the statement and see the REAL execution plan <em>actually used</em> for the execution. I&#8217;ll use dbms_xplan.display_CURSOR for this. If you don&#8217;t pass SQL_ID/child into that function it will just report the last SQL statement executed in your current session. But the key difference between the dbms_xplan.DISPLAY and DISPLAY_CURSOR is that the latter goes to library cache and fetches the <em>actual</em> SQL plan used from there. The explain plan command just reparses the statement and estimates a plan, ignoring any bind variable values and assuming that all bind variables are of type varchar2:</p>
<pre>SQL&gt; select sum(length(name)) from t where id &gt;  :x;

SUM(LENGTH(NAME))
-----------------

SQL&gt; select * from table(dbms_xplan.display_<strong>cursor</strong>);

PLAN_TABLE_OUTPUT
----------------------------------------------------------------------------------
SQL_ID  7zm570j6kj597, child number 0
-------------------------------------
select sum(length(name)) from t where id &gt;  :x

Plan hash value: 2966233522

---------------------------------------------------------------------------
| Id  | Operation          | Name | Rows  | Bytes | Cost (%CPU)| Time     |
---------------------------------------------------------------------------
|   0 | SELECT STATEMENT   |      |       |       |    60 (100)|          |
|   1 |  SORT AGGREGATE    |      |     1 |    29 |            |          |
|*  2 |   <strong>TABLE ACCESS FULL</strong>| T    |  2572 | 74588 |    60   (5)| 00:00:01 |
---------------------------------------------------------------------------

Predicate Information (identified by operation id):
---------------------------------------------------

 2 - filter(<strong>TO_NUMBER</strong>("ID")&gt;:X)

19 rows selected.</pre>
<p>Whatta? We actually used a full table scan!</p>
<p>2nd part will follow soon :-)</p>
<div class="facebook_like_button"><iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fblog.tanelpoder.com%2F2009%2F11%2F17%2Fexplain-plan-for-command-may-show-you-the-wrong-execution-plan-part-1%2F&amp;layout=standard&amp;show-faces=true&amp;width=450&amp;action=like&amp;font=arial&amp;colorscheme=light" scrolling="no" frameborder="0" allowTransparency="true" style="padding: 0px 0px; border:none; overflow:hidden; width:450px; height:70px;"></iframe></div> <img src="http://blog.tanelpoder.com/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?view=1&post_id=494" width="1" height="1" style="display: none;" /><p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save"><img src="http://blog.tanelpoder.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://blog.tanelpoder.com/2009/11/17/explain-plan-for-command-may-show-you-the-wrong-execution-plan-part-1/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>
