<?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>Gojko Adzic &#187; oracle</title>
	<atom:link href="http://gojko.net/tag/oracle/feed/" rel="self" type="application/rss+xml" />
	<link>http://gojko.net</link>
	<description>Building software that matters</description>
	<lastBuildDate>Tue, 31 Jan 2012 09:07:39 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>DbFit 1.0: support for in/out parameters, blank-padded strings and querying stored results</title>
		<link>http://gojko.net/2008/03/10/dbfit-10-support-for-inout-parameters-blank-padded-strings-and-querying-stored-results/</link>
		<comments>http://gojko.net/2008/03/10/dbfit-10-support-for-inout-parameters-blank-padded-strings-and-querying-stored-results/#comments</comments>
		<pubDate>Mon, 10 Mar 2008 02:38:49 +0000</pubDate>
		<dc:creator>gojko</dc:creator>
				<category><![CDATA[dbfit]]></category>
		<category><![CDATA[.net]]></category>
		<category><![CDATA[databases]]></category>
		<category><![CDATA[fitnesse]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[oracle]]></category>
		<category><![CDATA[sql server]]></category>
		<category><![CDATA[tdd]]></category>

		<guid isPermaLink="false">http://gojko.net/2008/03/10/dbfit-10-support-for-inout-parameters-blank-padded-strings-and-querying-stored-results/</guid>
		<description><![CDATA[I am pleased to finally announce version 1.0 of DbFit. DbFit is an extension to FIT/FitNesse that makes test-driven database development easy. Version 1.0 (2008-03-10) is a major cleanup release, finally bringing proper documentation for the library as well. Grab it from SourceForge. Major updates 1. Support for in/out parameters...]]></description>
			<content:encoded><![CDATA[<p>I am pleased to finally announce version 1.0 of <a target="_blank" href="http://gojko.net/fitnesse/dbfit">DbFit</a>. DbFit is an extension to FIT/FitNesse that makes test-driven database development easy. Version 1.0 (2008-03-10) is a major cleanup release, finally bringing proper documentation for the library as well.  Grab it from <a target="_blank" href="http://sourceforge.net/project/showfiles.php?group_id=191053&#038;package_id=224326">SourceForge</a>.<br />
<span id="more-107"></span></p>
<h2>Major updates</h2>
<p>   1. Support for <a target="_blank" href="http://dbfit.svn.sourceforge.net/svnroot/dbfit/dbfit/FitNesseRoot/AcceptanceTests/DotNetTests/OracleTests/FlowMode/InOutParams/content.txt"> in/out parameters in stored procedures</a>.<br />
   2. Support for  <a target="_blank" href="http://dbfit.svn.sourceforge.net/svnroot/dbfit/dbfit/FitNesseRoot/AcceptanceTests/DotNetTests/SqlServerTests/FlowMode/QueryStored/content.txt">querying stored results</a><br />
   3. Support for SQL Server 2000 in .NET. Not as complete as Sql Server 2005, but should work in most cases.<br />
   4. Support for testing <a target="_blank" href="http://dbfit.svn.sourceforge.net/svnroot/dbfit/dbfit/FitNesseRoot/AcceptanceTests/DotNetTests/SqlServerTests/FlowMode/DataTypes/FixedStringLengthTest/content.txt">blank-padded fixed length CHAR types.</a><br />
   5. .NET version now compiled with FitNesse.NET 1.5<br />
   6. Proper documentation &#8212; finally. The documentation is available as <a target="_blank" href="http://downloads.sourceforge.net/dbfit/dbfit-docs-20080310.pdf">PDF</a> and FitNesse (included in the <a target="_blank" href="http://downloads.sourceforge.net/dbfit/dbfit-complete-20080310.zip">dbfit-complete</a> package) and also online at <a href="http://fitnesse.info/dbfit:reference" target="_blank" target="_blank">FitNesse.Info</a>.</p>
<h2>Minor updates</h2>
<p>   1. Oracle date used as Timestamp to allow V8 compatibility switch to work<br />
   2. Stored procedure params no longer have to be listed in the same order as in db<br />
   3. GUID handler now just redirecting to standard GUID handler in .NET<br />
   4. OrderedQuery and StoreParameter fixtures for standalone mode<br />
   5. bugfix for transactions not getting rolled back in Java after tests in flow mode<br />
   6. bugfix for ntext and text field sizes in sql server<br />
   7. bugfix for fail[null] NullPointerException in Java<br />
   8. workaround for fail[null] bug in fitnesse.net 1.5<br />
   9. Acceptance tests now reorganised better. </p>
<p>Many thanks to Marisa Seal for her help with the documentation and Oscar Centeno for his help with Sql Server 2000 implementation. </p>
]]></content:encoded>
			<wfw:commentRss>http://gojko.net/2008/03/10/dbfit-10-support-for-inout-parameters-blank-padded-strings-and-querying-stored-results/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>DbFit &#8211; experimental support for In/Out parameters</title>
		<link>http://gojko.net/2008/02/04/dbfit-experimental-support-for-inout-parameters/</link>
		<comments>http://gojko.net/2008/02/04/dbfit-experimental-support-for-inout-parameters/#comments</comments>
		<pubDate>Mon, 04 Feb 2008 02:49:48 +0000</pubDate>
		<dc:creator>gojko</dc:creator>
				<category><![CDATA[dbfit]]></category>
		<category><![CDATA[.net]]></category>
		<category><![CDATA[databases]]></category>
		<category><![CDATA[fitnesse]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[oracle]]></category>
		<category><![CDATA[sql server]]></category>
		<category><![CDATA[tdd]]></category>

		<guid isPermaLink="false">http://gojko.net/2008/02/04/dbfit-experimental-support-for-inout-parameters/</guid>
		<description><![CDATA[I&#8217;m preparing for release 1.0 of DbFit &#8212; one of the new things will be support for In/Out parameters. A pre-release with this functionality is now available for testing. - To use In/Out parameters, just define two columns for the same parameter. The one for OUT direction should have a...]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m preparing for release 1.0 of DbFit &mdash; one of the new things will be support for In/Out parameters. A pre-release with this functionality is now available for testing.<br />
- To use In/Out parameters, just define two columns for the same parameter. The one for OUT direction should have a question mark<br />
- Order of parameters in the table is no longer important (it was in Java), so you should be able to put parameters in FitNesse pages in a different order then those in the database.</p>
<p>Here is an example:</p>
<blockquote>
<pre>
|Execute procedure|MultiplyIO|
|factor|val|val?|
|10|5|50|
|2|8|16|
</pre>
</blockquote>
<p>Introducing IN/OUT parameters required a huge change in the underlying parameter processing, please help by testing a pre-release and verifying that your old tests work with the new system as well. </p>
<p>SQL Server turned out to be especially tricky because there is no explicit IN/OUT flag on stored procedure parameters, and .NET driver does not expect all outputs to be simply declared as InputOutput, so there is an ugly workaround in the code to check whether an output parameter is also used for input. I do not expect any problems with this, but it&#8217;s best to double-check. </p>
<p>Get the binary builds for <a href="http://dbfit.svn.sourceforge.net/svnroot/dbfit/dbfit/dist/dbfit-dotnet-20080203.zip">.NET</a> and <a href="http://dbfit.svn.sourceforge.net/svnroot/dbfit/dbfit/dist/dbfit-java-20080203.jar">Java</a> from SourceForge.</p>
]]></content:encoded>
			<wfw:commentRss>http://gojko.net/2008/02/04/dbfit-experimental-support-for-inout-parameters/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Catalogue of SQL and PL/SQL bad practices: Call for participation</title>
		<link>http://gojko.net/2007/12/20/catalogue-of-sql-and-plsql-bad-practices-call-for-participation/</link>
		<comments>http://gojko.net/2007/12/20/catalogue-of-sql-and-plsql-bad-practices-call-for-participation/#comments</comments>
		<pubDate>Thu, 20 Dec 2007 08:04:16 +0000</pubDate>
		<dc:creator>gojko</dc:creator>
				<category><![CDATA[articles]]></category>
		<category><![CDATA[tutorials]]></category>
		<category><![CDATA[best practices]]></category>
		<category><![CDATA[oracle]]></category>

		<guid isPermaLink="false">http://gojko.net/2007/12/20/catalogue-of-sql-and-plsql-bad-practices-call-for-participation/</guid>
		<description><![CDATA[I started compiling a list of Oracle SQL and PL/SQL bad practices, with the intention of producing a comprehensive catalogue of common and recurring programming mistakes, that can be used as a check-list for code reviews or given to junior developers. I have identified about 30 bad practices so far....]]></description>
			<content:encoded><![CDATA[<p>I started compiling a list of Oracle SQL and PL/SQL bad practices, with the intention of producing a comprehensive catalogue of common and recurring programming mistakes, that can be used as a check-list for code reviews or given to junior developers. I have identified about 30 bad practices so far. For each bad practice, I provided a list of symptoms in the code, an explanation why it causes problems and a list of preferred solutions.</p>
<p>My goal with this list is primarily to start a discussion about similar recurring issues that other people have noticed. That discussion should lead to a more complete list which the community will then be able to use, hopefully, to learn something from the mistakes of others and to produce better code. </p>
<p>You can download the first version of the catalogue in PDF form from <a href="http://gojko.net/effective-oracle">http://gojko.net/effective-oracle</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://gojko.net/2007/12/20/catalogue-of-sql-and-plsql-bad-practices-call-for-participation/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Speed up database code with result caching</title>
		<link>http://gojko.net/2007/11/02/speed-up-database-code-with-result-caching/</link>
		<comments>http://gojko.net/2007/11/02/speed-up-database-code-with-result-caching/#comments</comments>
		<pubDate>Fri, 02 Nov 2007 07:55:27 +0000</pubDate>
		<dc:creator>gojko</dc:creator>
				<category><![CDATA[articles]]></category>
		<category><![CDATA[caching]]></category>
		<category><![CDATA[databases]]></category>
		<category><![CDATA[oracle]]></category>
		<category><![CDATA[scalability]]></category>

		<guid isPermaLink="false">http://gojko.net/2007/11/02/speed-up-database-code-with-result-caching/</guid>
		<description><![CDATA[One of the most interesting new features of Oracle 11 for me is the new function result caching mechanism. Until now, making sure that a PL/SQL function gets executed only as many times as necessary was a black art. The new caching system makes that quite easy &#8211; here is...]]></description>
			<content:encoded><![CDATA[<p>One of the most interesting new features of Oracle 11 for me is the new function result caching mechanism. Until now, making sure that a PL/SQL function gets executed only as many times as necessary was a black art. The new caching system makes that quite easy &#8211; here is how it works.<span id="more-68"></span></p>
<h2>Enabling the cache</h2>
<p>To turn on caching for a function, add RESULT_CACHE immediately before IS or AS in the function declaration. There is an optional RELIES_ON clause which can specify a database table or column dependency. If a dependency is specified, any change to the underlying object invalidates cached results. So, for example, we can write a function that does some on-the-fly statistics depending on a configuration parameter. If the parameter table changes, function results are automatically deleted from the cache. This mechanism is intended to replace all in-house caching systems developed over the years using triggers and PL/SQL package variables. </p>
<p>A new DBMS package dbms_result_cache can be used to get statistics and manipulate cache directly. Two most interesting methods in that package are memory_report and FLUSH. Flush clears the cache, and memory_report prints a nice memory usage report to serveroutput.</p>
<h2>A practical example</h2>
<p>So let&#8217;s try it out. We&#8217;ll do some statistics on a table, and run the query a couple of times without and with caching. I typically run tests like these on sys.all_objects, but for some reason result caching is disabled on SYS structures. For the test, we&#8217;ll first copy ALL_OBJECTS into a table in some user schema. You&#8217;ll probably need the DBA role to run this script because of the memory flushing, but result caching is available to normal user roles.</p>
<blockquote>
<pre>

spool c:\log.txt 

drop table BIGTABLE;

create table BIGTABLE as
select * from all_objects;

SET SERVEROUTPUT ON

exec dbms_result_cache.flush;

alter system flush shared_pool
/

exec dbms_result_cache.memory_report;

create or replace function COUNT_OBJECTS(pOBJECT_TYPE varchar2) return number as
lCount number;
begin
	select count(*) into lCOUNT from BIGTABLE where object_type=pOBJECT_TYPE;
	return lCOUNT;
end;
/

create or replace function COUNT_OBJECTS2(pOBJECT_TYPE varchar2) return number
<b>RESULT_CACHE relies_on (BIGTABLE) </b>
as
lCount number;
begin
	select count(*) into lCOUNT from BIGTABLE where object_type=pOBJECT_TYPE;
	return lCOUNT;
end;
/

set timing on;

set autotrace traceonly;

select object_type, COUNT_OBJECTS(object_type) from BIGTABLE group by object_type;

select object_type, COUNT_OBJECTS(object_type) from BIGTABLE group by object_type;

select object_type, COUNT_OBJECTS2(object_type) from BIGTABLE group by object_type;

exec dbms_result_cache.memory_report;

select object_type, COUNT_OBJECTS2(object_type) from BIGTABLE group by object_type;

exec dbms_result_cache.memory_report;

spool off;
</pre>
</blockquote>
<p>Methods COUNT_OBJECTS and COUNT_OBJECTS2 are absolutely the same, except for the result caching. When the script is executed, we see the difference in the trace and memory report. The first execution, without caching, comes to this:</p>
<blockquote>
<pre>

36 rows selected.

Elapsed: 00:00:00.42

Execution Plan
----------------------------------------------------------
Plan hash value: 2406321947                                                     

-------------------------------------------------------------------------------
| Id  | Operation          | Name     | Rows  | Bytes | Cost (%CPU)| Time     |
-------------------------------------------------------------------------------
|   0 | SELECT STATEMENT   |          | 63870 |   686K|   284   (2)| 00:00:04 |
|   1 |  HASH GROUP BY     |          | 63870 |   686K|   284   (2)| 00:00:04 |
|   2 |   TABLE ACCESS FULL| BIGTABLE | 63870 |   686K|   281   (1)| 00:00:04 |
------------------------------------------------------------------------------- 

Note
-----
   - dynamic sampling used for this statement                                   

Statistics
----------------------------------------------------------
        248  recursive calls
          0  db block gets
      37423  consistent gets
       1006  physical reads
          0  redo size
       1179  bytes sent via SQL*Net to client
        356  bytes received via SQL*Net from client
          4  SQL*Net roundtrips to/from client
          2  sorts (memory)
          0  sorts (disk)
         36  rows processed                                                     
</pre>
</blockquote>
<p>The second one, calling the same function but without caching, leads to this:</p>
<blockquote>
<pre>
36 rows selected.

Elapsed: 00:00:00.37

Execution Plan
----------------------------------------------------------
Plan hash value: 2406321947                                                     

-------------------------------------------------------------------------------
| Id  | Operation          | Name     | Rows  | Bytes | Cost (%CPU)| Time     |
-------------------------------------------------------------------------------
|   0 | SELECT STATEMENT   |          | 63870 |   686K|   284   (2)| 00:00:04 |
|   1 |  HASH GROUP BY     |          | 63870 |   686K|   284   (2)| 00:00:04 |
|   2 |   TABLE ACCESS FULL| BIGTABLE | 63870 |   686K|   281   (1)| 00:00:04 |
------------------------------------------------------------------------------- 

Note
-----
   - dynamic sampling used for this statement                                   

Statistics
----------------------------------------------------------
         38  recursive calls
          0  db block gets
      37222  consistent gets
          0  physical reads
          0  redo size
       1179  bytes sent via SQL*Net to client
        356  bytes received via SQL*Net from client
          4  SQL*Net roundtrips to/from client
          0  sorts (memory)
          0  sorts (disk)
         36  rows processed                                                     
</pre>
</blockquote>
<p>The number of physical reads and recursive calls is much lower, because of internal caching mechanisms. Execution time drops from 42 to 37 ms. Now, the third execution with caching turned on:</p>
<blockquote>
<pre>

36 rows selected.

Elapsed: 00:00:00.37

Execution Plan
----------------------------------------------------------
Plan hash value: 2406321947                                                     

-------------------------------------------------------------------------------
| Id  | Operation          | Name     | Rows  | Bytes | Cost (%CPU)| Time     |
-------------------------------------------------------------------------------
|   0 | SELECT STATEMENT   |          | 63870 |   686K|   284   (2)| 00:00:04 |
|   1 |  HASH GROUP BY     |          | 63870 |   686K|   284   (2)| 00:00:04 |
|   2 |   TABLE ACCESS FULL| BIGTABLE | 63870 |   686K|   281   (1)| 00:00:04 |
------------------------------------------------------------------------------- 

Note
-----
   - dynamic sampling used for this statement                                   

Statistics
----------------------------------------------------------
         58  recursive calls
          0  db block gets
      37310  consistent gets
          0  physical reads
          0  redo size
       1180  bytes sent via SQL*Net to client
        356  bytes received via SQL*Net from client
          4  SQL*Net roundtrips to/from client
          0  sorts (memory)
          0  sorts (disk)
         36  rows processed
</pre>
</blockquote>
<p>Number of recursive calls and physical reads is still lower than in the first case, because table data is loaded into the memory. Execution took about 37 ms, more or less the same as in the second run. Consistent gets show that we are still processing the whole table, because they are basically the same as in the first run.</p>
<p>The memory_report procedure after this call shows that some data is in the cache:</p>
<blockquote>
<pre>
R e s u l t   C a c h e   M e m o r y   R e p o r t
[Parameters]
Block Size          = 1K bytes
Maximum Cache Size  = 4064K bytes (4064 blocks)
Maximum Result Size = 203K bytes (203 blocks)
[Memory]
Total Memory = 202184 bytes [0.057% of the Shared Pool]
... Fixed Memory = 5296 bytes [0.002% of the Shared Pool]
... Dynamic Memory = 196888 bytes [0.056% of the Shared Pool]
....... Overhead = 131352 bytes
....... Cache Memory = 64K bytes (64 blocks)
........... Unused Memory = 26 blocks
........... Used Memory = 38 blocks
............... Dependencies = 2 blocks (2 count)
............... Results = 36 blocks
................... PLSQL   = 36 blocks (36 count)
PL/SQL procedure successfully completed.
</pre>
</blockquote>
<p>Now the last execution &#8211; repeating the function with caching turned on:</p>
<blockquote>
<pre>
36 rows selected.

Elapsed: 00:00:00.01

Execution Plan
----------------------------------------------------------
Plan hash value: 2406321947                                                     

-------------------------------------------------------------------------------
| Id  | Operation          | Name     | Rows  | Bytes | Cost (%CPU)| Time     |
-------------------------------------------------------------------------------
|   0 | SELECT STATEMENT   |          | 63870 |   686K|   284   (2)| 00:00:04 |
|   1 |  HASH GROUP BY     |          | 63870 |   686K|   284   (2)| 00:00:04 |
|   2 |   TABLE ACCESS FULL| BIGTABLE | 63870 |   686K|   281   (1)| 00:00:04 |
------------------------------------------------------------------------------- 

Note
-----
   - dynamic sampling used for this statement                                   

Statistics
----------------------------------------------------------
          0  recursive calls
          0  db block gets
       1006  consistent gets
          0  physical reads
          0  redo size
       1180  bytes sent via SQL*Net to client
        356  bytes received via SQL*Net from client
          4  SQL*Net roundtrips to/from client
          0  sorts (memory)
          0  sorts (disk)
         36  rows processed                                                     
</pre>
</blockquote>
<p>So between third and fourth call, number of consistent gets dropped significantly. There were no recursive calls and no function executions. All values were read straight from the cache. Notice how the execution time dropped from 36 ms to 1 ms.</p>
<p>The cache is in the system global area (SGA), so cached values are available across database sessions. So, to conclude, adding RESULT_CACHE is an easy way to optimise dynamic statistics and parametrisation. Here are some links for the end: </p>
<ul>
<li>
<a target='_blank'  href='http://www.oracle.com/technology/obe/11gr1_db/perform/rescache/res_cache.htm'>Improving Application Performance with Result Cache</a> article from OTN.
</li>
<li>
<a target='_blank' href='http://download.oracle.com/docs/cd/B28359_01/appdev.111/b28419/d_result_cache.htm'>DMBS_RESULT_CACHE API docs</a></p>
</li>
<li>
<a target='_blank' href='http://download.oracle.com/docs/cd/B28359_01/appdev.111/b28370/subprograms.htm#BABCDCFA'>Result caching syntax docs</a></p>
</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://gojko.net/2007/11/02/speed-up-database-code-with-result-caching/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

