Unix Technical Forum

Speeding up Hierarchical Data quering

This is a discussion on Speeding up Hierarchical Data quering within the MySQL forums, part of the Database Server Software category; --> Hi, I have a table with hierarchical data, which is stored using the Modified Preorder Tree Traversal algorithm (MPTT). ...


Go Back   Unix Technical Forum > Database Server Software > MySQL

Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 02-28-2008, 10:32 AM
pieter.thoma@gmail.com
 
Posts: n/a
Default Speeding up Hierarchical Data quering

Hi,

I have a table with hierarchical data, which is stored using the
Modified Preorder Tree Traversal algorithm (MPTT).

More information about MPTT can be found here:
http://dev.mysql.com/tech-resources/...ical-data.html.

I was wondering if indexing on the lft and rgt column will have speed
advantages, as the cardinality of the index will always be the same as
the number of rows there are in the database.

In my case, there are about 40000 rows in my hierarchical data table.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 02-28-2008, 10:32 AM
Rik Wasmus
 
Posts: n/a
Default Re: Speeding up Hierarchical Data quering

On Wed, 06 Feb 2008 12:25:55 +0100, <pieter.thoma@gmail.com> wrote:

> Hi,
>
> I have a table with hierarchical data, which is stored using the
> Modified Preorder Tree Traversal algorithm (MPTT).
>
> More information about MPTT can be found here:
> http://dev.mysql.com/tech-resources/...ical-data.html.
>
> I was wondering if indexing on the lft and rgt column will have speed
> advantages, as the cardinality of the index will always be the same as
> the number of rows there are in the database.


It will have advantages in selecting, it will make
inserting/altering/deleting slower.
--
Rik Wasmus
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 02-28-2008, 10:32 AM
Rik Wasmus
 
Posts: n/a
Default Re: Speeding up Hierarchical Data quering

On Wed, 06 Feb 2008 12:31:30 +0100, Rik Wasmus
<luiheidsgoeroe@hotmail.com> wrote:

> On Wed, 06 Feb 2008 12:25:55 +0100, <pieter.thoma@gmail.com> wrote:
>
>> Hi,
>>
>> I have a table with hierarchical data, which is stored using the
>> Modified Preorder Tree Traversal algorithm (MPTT).
>>
>> More information about MPTT can be found here:
>> http://dev.mysql.com/tech-resources/...ical-data.html.
>>
>> I was wondering if indexing on the lft and rgt column will have speed
>> advantages, as the cardinality of the index will always be the same as
>> the number of rows there are in the database.

>
> It will have advantages in selecting, it will make
> inserting/altering/deleting slower.


BTW, one way to speed up inserting/deleting/updating, is to leave quite
huge gaps between lft & rgt values. This way, on almost all record
changes, no altering of other records (save for possible descendants) is
required (yet). This speeds up things a lot, but requires quite some
carefull code checking for gaps & need, and possibly a scheduled
'reindexing' at some regular interval.
--
Rik Wasmus
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 02-28-2008, 10:32 AM
pieter.thoma@gmail.com
 
Posts: n/a
Default Re: Speeding up Hierarchical Data quering

On Feb 6, 12:42 pm, "Rik Wasmus" <luiheidsgoe...@hotmail.com> wrote:
> On Wed, 06 Feb 2008 12:31:30 +0100, Rik Wasmus
>
>
>
> <luiheidsgoe...@hotmail.com> wrote:
> > On Wed, 06 Feb 2008 12:25:55 +0100, <pieter.th...@gmail.com> wrote:

>
> >> Hi,

>
> >> I have a table with hierarchical data, which is stored using the
> >> Modified Preorder Tree Traversal algorithm (MPTT).

>
> >> More information about MPTT can be found here:
> >>http://dev.mysql.com/tech-resources/...ical-data.html.

>
> >> I was wondering if indexing on the lft and rgt column will have speed
> >> advantages, as the cardinality of the index will always be the same as
> >> the number of rows there are in the database.

>
> > It will have advantages in selecting, it will make
> > inserting/altering/deleting slower.

>
> BTW, one way to speed up inserting/deleting/updating, is to leave quite
> huge gaps between lft & rgt values. This way, on almost all record
> changes, no altering of other records (save for possible descendants) is
> required (yet). This speeds up things a lot, but requires quite some
> carefull code checking for gaps & need, and possibly a scheduled
> 'reindexing' at some regular interval.
> --
> Rik Wasmus


Yes it will. Luckily in my case, the data is static. It's a write
once, read many.

But inserting is slow indeed.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 12:17 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com