<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
		>
<channel>
	<title>Komentar di: Adjacency list tree on Mysql</title>
	<atom:link href="http://kod34fr33.wordpress.com/2008/05/06/adjacency-list-tree-on-mysql/feed/" rel="self" type="application/rss+xml" />
	<link>http://kod34fr33.wordpress.com/2008/05/06/adjacency-list-tree-on-mysql/</link>
	<description>Another koding mind</description>
	<lastBuildDate>Tue, 22 Dec 2009 19:53:51 +0000</lastBuildDate>
	<generator>http://wordpress.com/</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>Oleh: Dealsghost</title>
		<link>http://kod34fr33.wordpress.com/2008/05/06/adjacency-list-tree-on-mysql/#comment-377</link>
		<dc:creator>Dealsghost</dc:creator>
		<pubDate>Fri, 31 Oct 2008 12:27:58 +0000</pubDate>
		<guid isPermaLink="false">http://kod34fr33.wordpress.com/?p=19#comment-377</guid>
		<description>Good Article

www.dealsghost.com</description>
		<content:encoded><![CDATA[<p>Good Article</p>
<p><a href="http://www.dealsghost.com" rel="nofollow">http://www.dealsghost.com</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>Oleh: Chris</title>
		<link>http://kod34fr33.wordpress.com/2008/05/06/adjacency-list-tree-on-mysql/#comment-375</link>
		<dc:creator>Chris</dc:creator>
		<pubDate>Fri, 22 Aug 2008 23:11:09 +0000</pubDate>
		<guid isPermaLink="false">http://kod34fr33.wordpress.com/?p=19#comment-375</guid>
		<description>&lt;b&gt;&lt;i&gt;HIERARCHY SORTING SOLUTION&lt;/i&gt;&lt;/b&gt;
Having embarrassed myself by suggesting a non workable sort solution (see above) I have found one that works.
The most user friendly sort order for any hierarchy (eg product categories, staff positions, index in a book etc ) is to have all the same-level entries sorted alphabetically, like this:


Director
  Sales Mgr
    Region 1 Mgr
      Employee 3
      Employee 4
      Employee 5
    Region 2 Mgr
      Subregion A Mgr
        Employee 6
        Employee 7
      Subregion B Mgr
        Employee 8
        Employee 9
  Secretary
  Treasury Mgr
    Employee 1
    Employee 2

The level two employees are Sales Mgr, Secretary and Treasury Mgr, in that order.
Under the Sales Mgr is Region 1 Mgr and Region 2 Mgr, in that order, and so on.
They must be sorted alphabetically regardless of the sequence in which they were added to the table.  Sorting by the primary key is not a good idea.

The reason why kod34fr33`s Region 2 Mgr sorted before Region 1 Mgr is that /1/6/11/ is alphabetically before /1/6/7/.
One can achieve an alphabetic sort within a depth level, by adding a `sort` column to the helper table.  The sort column must be built the same way as the path column, but using employee.name rather than emp_id and adding a few lines to the triggers.

The sort keys for Region 1 Mgr and Region 2 Mgr would then be &quot;/Director/Sales Mgr/Region 1 Mgr&quot; and &quot;/Director/Sales Mgr/Region 2 Mgr&quot;
and when the same select is done but using &quot;order by p.sort&quot; the results are sorted alphabetically within each level.

I would not be concerned about the fact that the sort column will hold long strings.  These hierarchy tables are typically static lookup tables with relatively few rows  (compared to business transaction tables which grow every day), so disk space is not a serious consideration.</description>
		<content:encoded><![CDATA[<p><b><i>HIERARCHY SORTING SOLUTION</i></b><br />
Having embarrassed myself by suggesting a non workable sort solution (see above) I have found one that works.<br />
The most user friendly sort order for any hierarchy (eg product categories, staff positions, index in a book etc ) is to have all the same-level entries sorted alphabetically, like this:</p>
<p>Director<br />
  Sales Mgr<br />
    Region 1 Mgr<br />
      Employee 3<br />
      Employee 4<br />
      Employee 5<br />
    Region 2 Mgr<br />
      Subregion A Mgr<br />
        Employee 6<br />
        Employee 7<br />
      Subregion B Mgr<br />
        Employee 8<br />
        Employee 9<br />
  Secretary<br />
  Treasury Mgr<br />
    Employee 1<br />
    Employee 2</p>
<p>The level two employees are Sales Mgr, Secretary and Treasury Mgr, in that order.<br />
Under the Sales Mgr is Region 1 Mgr and Region 2 Mgr, in that order, and so on.<br />
They must be sorted alphabetically regardless of the sequence in which they were added to the table.  Sorting by the primary key is not a good idea.</p>
<p>The reason why kod34fr33`s Region 2 Mgr sorted before Region 1 Mgr is that /1/6/11/ is alphabetically before /1/6/7/.<br />
One can achieve an alphabetic sort within a depth level, by adding a `sort` column to the helper table.  The sort column must be built the same way as the path column, but using employee.name rather than emp_id and adding a few lines to the triggers.</p>
<p>The sort keys for Region 1 Mgr and Region 2 Mgr would then be &#8220;/Director/Sales Mgr/Region 1 Mgr&#8221; and &#8220;/Director/Sales Mgr/Region 2 Mgr&#8221;<br />
and when the same select is done but using &#8220;order by p.sort&#8221; the results are sorted alphabetically within each level.</p>
<p>I would not be concerned about the fact that the sort column will hold long strings.  These hierarchy tables are typically static lookup tables with relatively few rows  (compared to business transaction tables which grow every day), so disk space is not a serious consideration.</p>
]]></content:encoded>
	</item>
	<item>
		<title>Oleh: Chris</title>
		<link>http://kod34fr33.wordpress.com/2008/05/06/adjacency-list-tree-on-mysql/#comment-374</link>
		<dc:creator>Chris</dc:creator>
		<pubDate>Fri, 22 Aug 2008 20:53:28 +0000</pubDate>
		<guid isPermaLink="false">http://kod34fr33.wordpress.com/?p=19#comment-374</guid>
		<description>Sorry the sort cannot be fixed as I suggested</description>
		<content:encoded><![CDATA[<p>Sorry the sort cannot be fixed as I suggested</p>
]]></content:encoded>
	</item>
	<item>
		<title>Oleh: Chris</title>
		<link>http://kod34fr33.wordpress.com/2008/05/06/adjacency-list-tree-on-mysql/#comment-373</link>
		<dc:creator>Chris</dc:creator>
		<pubDate>Fri, 22 Aug 2008 15:10:49 +0000</pubDate>
		<guid isPermaLink="false">http://kod34fr33.wordpress.com/?p=19#comment-373</guid>
		<description>Oops.  order by p.path ASC,p.name ASC should be
order by p.path ASC,e.name ASC</description>
		<content:encoded><![CDATA[<p>Oops.  order by p.path ASC,p.name ASC should be<br />
order by p.path ASC,e.name ASC</p>
]]></content:encoded>
	</item>
	<item>
		<title>Oleh: Chris</title>
		<link>http://kod34fr33.wordpress.com/2008/05/06/adjacency-list-tree-on-mysql/#comment-372</link>
		<dc:creator>Chris</dc:creator>
		<pubDate>Fri, 22 Aug 2008 14:40:37 +0000</pubDate>
		<guid isPermaLink="false">http://kod34fr33.wordpress.com/?p=19#comment-372</guid>
		<description>Tx for good thinking - neat, simple and efficient.

Is the reason for the second helper table to avoid table mutating problems on the triggers? Otherwise the `path` could just be another column in the employee table.

I think your triggers should read after insert and before update in EMPLOYEE rather than on SITE.

Maybe your note about &quot;node weight&quot; to fix the sort order can be solved by adding columns to the order by clause, eg order by p.path ASC,p.name ASC</description>
		<content:encoded><![CDATA[<p>Tx for good thinking &#8211; neat, simple and efficient.</p>
<p>Is the reason for the second helper table to avoid table mutating problems on the triggers? Otherwise the `path` could just be another column in the employee table.</p>
<p>I think your triggers should read after insert and before update in EMPLOYEE rather than on SITE.</p>
<p>Maybe your note about &#8220;node weight&#8221; to fix the sort order can be solved by adding columns to the order by clause, eg order by p.path ASC,p.name ASC</p>
]]></content:encoded>
	</item>
	<item>
		<title>Oleh: John Haugeland</title>
		<link>http://kod34fr33.wordpress.com/2008/05/06/adjacency-list-tree-on-mysql/#comment-371</link>
		<dc:creator>John Haugeland</dc:creator>
		<pubDate>Thu, 21 Aug 2008 18:11:43 +0000</pubDate>
		<guid isPermaLink="false">http://kod34fr33.wordpress.com/?p=19#comment-371</guid>
		<description>This is actually copied verbatim from the book he links at the beginning.  You can find stolen versions of this content all over the web.

Shameful, really.</description>
		<content:encoded><![CDATA[<p>This is actually copied verbatim from the book he links at the beginning.  You can find stolen versions of this content all over the web.</p>
<p>Shameful, really.</p>
]]></content:encoded>
	</item>
	<item>
		<title>Oleh: Some Visitor</title>
		<link>http://kod34fr33.wordpress.com/2008/05/06/adjacency-list-tree-on-mysql/#comment-369</link>
		<dc:creator>Some Visitor</dc:creator>
		<pubDate>Thu, 07 Aug 2008 19:53:43 +0000</pubDate>
		<guid isPermaLink="false">http://kod34fr33.wordpress.com/?p=19#comment-369</guid>
		<description>Someone is copying information, do you have two blogs? The exact same article is at http://icreativelabs.com/blog/2008/05/adjacency-list-tree-on-mysql - but it seems that your&#039;s is the original?</description>
		<content:encoded><![CDATA[<p>Someone is copying information, do you have two blogs? The exact same article is at <a href="http://icreativelabs.com/blog/2008/05/adjacency-list-tree-on-mysql" rel="nofollow">http://icreativelabs.com/blog/2008/05/adjacency-list-tree-on-mysql</a> &#8211; but it seems that your&#8217;s is the original?</p>
]]></content:encoded>
	</item>
	<item>
		<title>Oleh: andback</title>
		<link>http://kod34fr33.wordpress.com/2008/05/06/adjacency-list-tree-on-mysql/#comment-368</link>
		<dc:creator>andback</dc:creator>
		<pubDate>Sun, 03 Aug 2008 05:19:55 +0000</pubDate>
		<guid isPermaLink="false">http://kod34fr33.wordpress.com/?p=19#comment-368</guid>
		<description>This is great!
I working on a project to implement Decision tree for predictions.

Regards from india</description>
		<content:encoded><![CDATA[<p>This is great!<br />
I working on a project to implement Decision tree for predictions.</p>
<p>Regards from india</p>
]]></content:encoded>
	</item>
	<item>
		<title>Oleh: /dev/null</title>
		<link>http://kod34fr33.wordpress.com/2008/05/06/adjacency-list-tree-on-mysql/#comment-367</link>
		<dc:creator>/dev/null</dc:creator>
		<pubDate>Mon, 02 Jun 2008 11:04:58 +0000</pubDate>
		<guid isPermaLink="false">http://kod34fr33.wordpress.com/?p=19#comment-367</guid>
		<description>Dear kod34fr33,

Thank you very much for you work.
using a helper table quite an nice approach id one wants to go with the adjacency list model.
However, I&#039;ve got one question:
In your first trigger you use the following select:
&quot;SELECT `path` INTO `parent_path` FROM `employee_path` WHERE `emp_id` = NEW.`emp_id`;&quot;
As the trigger starts &quot;AFTER INSERT&quot;, I ask myself how there can ever be a result for that query?
An employee with the emp_id of the employee just inserted into the &quot;employee&quot;-table will never be found in the path-table.
I suppose if you changed this to &quot;SELECT `path` INTO `parent_path` FROM `employee_path` WHERE `emp_id` = NEW.`emp_parent_id`;&quot; it should work.
Thanks again,

/dev/null

&lt;strong&gt;/dev/null&lt;/strong&gt;
After read Joe Celko&#039;s book and &lt;a href=&quot;http://www.dbazine.com/oracle/or-articles/tropashko4&quot; rel=&quot;nofollow&quot;&gt;Tropashko&#039;s&lt;/a&gt; article, my approach more relevant to call as materialized path a.k.a path enumeration than adjacency list.
and you are right about the trigger. that&#039;s my mistake.  thanks for pointing that out. --kod34fr33</description>
		<content:encoded><![CDATA[<p>Dear kod34fr33,</p>
<p>Thank you very much for you work.<br />
using a helper table quite an nice approach id one wants to go with the adjacency list model.<br />
However, I&#8217;ve got one question:<br />
In your first trigger you use the following select:<br />
&#8220;SELECT `path` INTO `parent_path` FROM `employee_path` WHERE `emp_id` = NEW.`emp_id`;&#8221;<br />
As the trigger starts &#8220;AFTER INSERT&#8221;, I ask myself how there can ever be a result for that query?<br />
An employee with the emp_id of the employee just inserted into the &#8220;employee&#8221;-table will never be found in the path-table.<br />
I suppose if you changed this to &#8220;SELECT `path` INTO `parent_path` FROM `employee_path` WHERE `emp_id` = NEW.`emp_parent_id`;&#8221; it should work.<br />
Thanks again,</p>
<p>/dev/null</p>
<p><strong>/dev/null</strong><br />
After read Joe Celko&#8217;s book and <a href="http://www.dbazine.com/oracle/or-articles/tropashko4" rel="nofollow">Tropashko&#8217;s</a> article, my approach more relevant to call as materialized path a.k.a path enumeration than adjacency list.<br />
and you are right about the trigger. that&#8217;s my mistake.  thanks for pointing that out. &#8211;kod34fr33</p>
]]></content:encoded>
	</item>
</channel>
</rss>
