Re: Using Ltree For Hierarchical Structures

From: Misa Simic <misa(dot)simic(at)gmail(dot)com>
To: Igor Neyman <ineyman(at)perceptron(dot)com>
Cc: Don Parris <parrisdc(at)gmail(dot)com>, "pgsql-sql(at)postgresql(dot)org" <pgsql-sql(at)postgresql(dot)org>
Subject: Re: Using Ltree For Hierarchical Structures
Date: 2013-02-26 16:14:04
Message-ID: CAH3i69m3kROAWSEOFBEMx+65PQdF7X-jjG3_mKWupicCLvuJpA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Hi Igor,

I agree it is all "in the eyes of beholder".

Would be good if you can show how to achieve the goal (Summing on Top
Levels categories in hierarchy) with CTE?

For example show all categories in level 2 (x), and sum amounts for each...
(Sum takes all amounts from all transactions of its child categories in any
bellow levels).

I have tested both scenarios - and indexed ltree has given better result -
though there is a possibility I haven't pick best approach to solve the
problem with CTE...

I am just interested in performance - implementation detail is less
important...

Data:

Total number of categories: 1000 (in all levels)
No of Categories in top level: 5
No of categories in level 2: 20
Total number of levels: can vary - max in my testing was 8...

Transaction rows with amounts: 1 000 000

(though I am not sure what u meant by: "2-table design using ltree", and
with CTE there are 2 tables... Categories and Transactions: just in
categories instead of ltree datatype, is integer datatype: parent_id)

Many thanks,

Misa

2013/2/26 Igor Neyman <ineyman(at)perceptron(dot)com>

>
>
> From: Don Parris [mailto:parrisdc(at)gmail(dot)com]
> Sent: Sunday, February 24, 2013 5:21 PM
> To: pgsql-sql(at)postgresql(dot)org
> Subject: Using Ltree For Hierarchical Structures
>
> Hi all,
> With many thanks to Misa and others who helped out with my question about
> working with hierarchical data, I have now written a blog post on how I
> implemented the ltree module to solve my problem.
>
> http://dcparris.net/2013/02/24/using-ltree-hierarchical-postgresql/
> Frankly, if you work with hierarchical data, I'm not sure I could
> recommend it strongly enough. I should think that even experienced,
> advanced SQL gurus would appreciate the simplicity ltree offers, when
> compared to the ugly table designs and recursive queries in order to work
> with hierarchical structures.
> I really hope this blog post will help others in the same boat.
>
>
> Regards,
> Don
>
>
> It's all "in the eyes of beholder".
> IMHO, recursive CTEs are perfect for hierarchical structures, and much
> cleaner than 2-table design using ltree, that you show in the blog.
>
> Regards,
> Igor Neyman
>
>
>
>
> --
> Sent via pgsql-sql mailing list (pgsql-sql(at)postgresql(dot)org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-sql
>

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message mkumbale 2013-02-26 18:20:42 Re: Creating a new database with a TEMPLATE did not work
Previous Message Igor Neyman 2013-02-26 14:01:58 Re: Using Ltree For Hierarchical Structures