<?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>Matthew Turland &#187; Forkr</title>
	<atom:link href="http://matthewturland.com/tag/forkr/feed/" rel="self" type="application/rss+xml" />
	<link>http://matthewturland.com</link>
	<description></description>
	<lastBuildDate>Tue, 24 Jan 2012 04:03:47 +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>Supporting Hierarchical Data Sets</title>
		<link>http://matthewturland.com/2007/09/17/supporting-hierarchical-data-sets/</link>
		<comments>http://matthewturland.com/2007/09/17/supporting-hierarchical-data-sets/#comments</comments>
		<pubDate>Mon, 17 Sep 2007 00:43:40 +0000</pubDate>
		<dc:creator>Matthew Turland</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Databases]]></category>
		<category><![CDATA[Forkr]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://ishouldbecoding.com/2007/09/16/supporting-hierarchical-data-sets/</guid>
		<description><![CDATA[If you deal with relational database systems on any semi-regular basis, you&#8217;ve probably had to support hierarchical data sets before. In genealogical terms, each record may have a logical &#8220;parent&#8221; record and zero or more &#8220;child&#8221; records. The approach that you&#8217;ve likely taken to support these data sets has been to include a foreign key [...]]]></description>
			<content:encoded><![CDATA[<p>If you deal with relational database systems on any semi-regular basis, you&#8217;ve probably had to support hierarchical data sets before. In genealogical terms, each record may have a logical &#8220;parent&#8221; record and zero or more &#8220;child&#8221; records. The approach that you&#8217;ve likely taken to support these data sets has been to include a foreign key column in the table in question that references the primary key column in the same table. This approach is called the adjacency list model, where the name is taken from the <a title="Adjacency list - Wikipedia, the free encyclopedia" href="http://en.wikipedia.org/wiki/Adjacency_list">same concept in graph theory</a>. This model is simple and intuitive, but it has a drawback: to obtain any significant portion of the hierarchy stored in a table can take up to as many queries as there are levels of depth in the hierarchy.</p>
<p>There is an alternative approach, called the nested set model, which finds its basis in <a title="Set theory - Wikipedia, the free encyclopedia" href="http://en.wikipedia.org/wiki/Set_theory">set theory</a>. Its development is credited to a man by the name of Joe Celko, who&#8217;s written <a title="Bookpool: joe celko" href="http://www.amazon.com/Joe-Celko/e/B000ARBFVQ/ref=sr_tc_2_0?qid=1282254734&amp;sr=8-2-ent">a number of books</a> related to SQL and database design. The basis of the approach is this: each record has numerical left and right bounds that represent the boundaries of a set, where everything within that set is a descendant of that record. By employing some simple joins, most of the subsets of data commonly desired in a hierarchical data set can be retrieved with a single query, which is much more efficient in terms of the number of queries required to fulfill an individual request.</p>
<p>If <a title="MySQL AB :: The world's most popular open source database" href="http://mysql.com">MySQL</a> is your database server of choice, its main web site has <a title="MySQL AB :: Managing Hierarchical Data in MySQL" href="http://dev.mysql.com/tech-resources/articles/hierarchical-data.html" class="broken_link">an excellent article</a> that outlines what the nested set model is and how to implement it within MySQL. <a title="Storing Hierarchical Data in a Database [PHP &amp; MySQL Tutorials]" href="http://articles.sitepoint.com/article/hierarchical-data-database">This article</a> on Sitepoint also explains it and its examples use <a title="PHP: Hypertext Preprocessor" href="http://php.net">PHP</a> in conjunction with MySQL. There&#8217;s also <a title="Using the Nested Set Data Model for Breadcrumb Links" href="http://www.developer.com/db/article.php/3517366/Using-the-Nested-Set-Data-Model-for-Breadcrumb-Links.htm">another great article</a> on developer.com that gives a visual walk through of the nested set model and its implementation in <a title="Oracle 11g, Siebel, PeopleSoft | Oracle, The World's Largest Enterprise Software Company" href="http://www.oracle.com/index.html">Oracle</a> for use in generating breadcrumb trail navigation on a web site. <a title="dotvoid.com - experiments on php, javascript, ajax and web application development" href="http://www.dotvoid.com">Danne Lundqvist</a> also has <a title="dotvoid.com - Reordering nested sets using PHP and Javascript" href="http://www.dotvoid.com/">a blog entry</a> describing his experiences in using PHP and JavaScript (specifically <a title="mootools - home" href="http://mootools.net/">Mootools</a>) to transfer data back and forth between the nested set model and an ordered depth model. These articles explain the concepts well enough that I doubt I&#8217;d do much better in trying to reiterate them here.</p>
<p>I found out about the nested set model through <a title="Dreaming of Dawn" href="http://elizabethmariesmith.com">Elizabeth Smith</a>, one of my fellow developers on the Forkr project. One of my tasks while working on the project was to adapt information from various resources, including code she&#8217;d written to implement a combined adjacency list/nested set model approach on a <a title="PostgreSQL: The world's most advanced open source database" href="http://www.postgresql.org">PostgreSQL</a> database, to a component for Forkr to support hierarchical data sets. Why a combined approach? There are several reasons why that is actually better than each individual approach by itself.</p>
<ol>
<li>Some of its common queries, mostly those involving only two levels worth of data (i.e. a parent and its children), are more simple and efficient in the adjacency list model than in the nested set model.</li>
<li>Most sites that support hierarchical data sets already use the adjacency list model, so roughly half the work of implementing a combined approach is already done.</li>
<li>The adjacency list model is fairly easy to understand and, when effectively laid side-by-side with the nested set model, makes it somewhat easier to follow when looking at data that uses a combined approach.</li>
<li>When developing an application that uses the nested set model, the logic which controls the bound values for each record can be error-prone early in development. By also maintaining a foreign key column that points back to the parent, the bound values can easily be regenerated at any time.</li>
</ol>
<p>My work in Forkr is still very much in an alpha stage, but once it&#8217;s completed I&#8217;ll likely post another blog entry on this topic that outlines how to implement the nested set model with specific SQL examples. So, keep your eyes peeled for it.</p>
<p><strong>Update</strong>: Wow&#8230; apparently I unknowingly struck a nerve. :P The earlier comments are correct in that manipulating nested set bounds does indeed require updates on many records of a table. The extra speed in retrieving the hierarchy has to come from somewhere, right? The nested set model is admittedly better for instances where the tree isn&#8217;t likely to change often or have multiple potential points of modification that can run concurrently. My apologies for not making that clear earlier on.</p>
]]></content:encoded>
			<wfw:commentRss>http://matthewturland.com/2007/09/17/supporting-hierarchical-data-sets/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Now on Ohloh</title>
		<link>http://matthewturland.com/2007/08/24/now-on-ohloh/</link>
		<comments>http://matthewturland.com/2007/08/24/now-on-ohloh/#comments</comments>
		<pubDate>Fri, 24 Aug 2007 08:20:01 +0000</pubDate>
		<dc:creator>Matthew Turland</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Forkr]]></category>

		<guid isPermaLink="false">http://ishouldbecoding.com/2007/08/24/now-on-ohloh/</guid>
		<description><![CDATA[I finally got around to getting an Ohloh profile and setting it up to reflect my work on the Zend Framework and Forkr. Hopefully my list of work will grow as time goes on.]]></description>
			<content:encoded><![CDATA[<p>I finally got around to getting an <a href="http://www.ohloh.net/accounts/Elazar" title="Elazar - Ohloh">Ohloh profile</a> and setting it up to reflect my work on the <a href="http://framework.zend.com" title="Zend Framework">Zend Framework</a> and <a href="http://www.google.com/" title="Forkr">Forkr</a>. Hopefully my list of work will grow as time goes on.</p>
]]></content:encoded>
			<wfw:commentRss>http://matthewturland.com/2007/08/24/now-on-ohloh/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
<!-- WP Super Cache is installed but broken. The path to wp-cache-phase1.php in wp-content/advanced-cache.php must be fixed! -->
