<?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>To Hell in a Handbasket &#187; PL/SQL</title>
	<atom:link href="http://ericsilva.org/tag/plsql/feed/" rel="self" type="application/rss+xml" />
	<link>http://ericsilva.org</link>
	<description>General Views, Opinions, and Observations in the World Around Me</description>
	<lastBuildDate>Tue, 22 May 2012 07:44:54 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>Quickly Create Indexes on Foreign Key Columns</title>
		<link>http://ericsilva.org/2009/01/25/quickly-create-indexes-on-foreign-key-columns/</link>
		<comments>http://ericsilva.org/2009/01/25/quickly-create-indexes-on-foreign-key-columns/#comments</comments>
		<pubDate>Sun, 25 Jan 2009 17:53:48 +0000</pubDate>
		<dc:creator>Eric Silva</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Database]]></category>
		<category><![CDATA[Hibernate]]></category>
		<category><![CDATA[LinkedIn]]></category>
		<category><![CDATA[PL/SQL]]></category>

		<guid isPermaLink="false">http://ericsilva.org/?p=177</guid>
		<description><![CDATA[When using Hibernate as a ORM solution, it is natural to fall into a sense of ease with the tool and what it can do.  However, once you begin to load data into your application, there are several performance gaps that will quickly become apparent.  One of these gaps is the absence of indexes on &#8230; </p><p><a class="more-link block-button" href="http://ericsilva.org/2009/01/25/quickly-create-indexes-on-foreign-key-columns/">Continue reading &#187;</a>]]></description>
			<content:encoded><![CDATA[<p>When using Hibernate as a ORM solution, it is natural to fall into a sense of ease with the tool and what it can do.  However, once you begin to load data into your application, there are several performance gaps that will quickly become apparent.  One of these gaps is the absence of indexes on the parent foreign key column in the child table.</p>
<p>When you create a <code>&lt;many-to-one&gt;</code> association in Hibernate, the child table (the many) holds a foreign key to the parent table (the one).  When a call is made in Java to <code>parent.getChildren()</code>,  Hibernate will execute the query equivalent to: <code>select * from child where parent_id = ?</code>.  With the absence of the index, the database will be forced to perform a full table scan to load the children.  With an index, the database can simply use the index to perform an optimized fetch of the child records.</p>
<p>To create an index on each foreign key in the application&#8217;s domain tables would be quite tedious; as I encountered.   To add the indexes quickly, I wrote the following PL/SQL routine that can be run on the database (I am using Oracle).  The function will iterate over all tables except for the <code>&lt;many-to-many&gt;</code> JOIN tables and create an index on each foreign key column.</p>
<p>After creating the indexes, the performance of your application should be quite noticeable, especially for the parents that have large collections of children.</p>
<p>Obviously any additional tables that should be excluded from this function would be added by modifying the <code>SELECT</code> statement that loads the foreign key constraints into the cursor in the <code>DECLARE</code> section of the PL/SQL block.</p>
<p>You can download the PL/SQL function here: <a href="http://ericsilva.org/wp-content/uploads/2009/01/fk_index_builder.sql">fk_index_builder.sql</a></p>
]]></content:encoded>
			<wfw:commentRss>http://ericsilva.org/2009/01/25/quickly-create-indexes-on-foreign-key-columns/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

