Received: from maia.hub.org (unknown [200.46.204.183]) by mail.postgresql.org (Postfix) with ESMTP id 94B2563360E for ; Tue, 20 Apr 2010 16:32:56 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 30013-09 for ; Tue, 20 Apr 2010 19:32:44 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mail-pw0-f46.google.com (mail-pw0-f46.google.com [209.85.160.46]) by mail.postgresql.org (Postfix) with ESMTP id C5AE86335CB for ; Tue, 20 Apr 2010 16:32:43 -0300 (ADT) Received: by pwj9 with SMTP id 9so4569475pwj.19 for ; Tue, 20 Apr 2010 12:32:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:in-reply-to:references :date:received:message-id:subject:from:to:cc:content-type :content-transfer-encoding; bh=81A4SNx/89lvIJcuscZJJC/qOnrNhijCsQf9/oXIGxw=; b=yD50jUW3dJGSXguyKAeymRT6o0MUO1L8WD479hW+lWrXdLsNaCv1ycspzDacHY1yxO i9YACcA/CTlfBGZYvABPWtLtfy84OmKgd21SfM6nmiEc1Uw+dhz1dMM1H1uz+8jmG7/N HCsPXE5ER91d+OUTINGpfNouiFtVwh+GqgeBc= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type:content-transfer-encoding; b=iI8qS920+o758yE2tWtv3M2NlMwG5pRVHoXcO5LixhCqMFjPzzKTimt26Fltzi3tYQ dVXyUrMLw14eyclge5OqVKpvwu3VQFgaHLzgyE3BAzU4S8bXzSPJTMn8QLNsTe2VM0Ix BpW2DIIGvf6oeSbqUQfypQdqVfm8ytU1f0vWU= MIME-Version: 1.0 Received: by 10.142.103.11 with HTTP; Tue, 20 Apr 2010 12:32:42 -0700 (PDT) In-Reply-To: <74881095-CCEF-42DA-B1C7-6F1BC2650D44@solfertje.student.utwente.nl> References: <59670B22-30CB-4E6E-83C8-C1D1036C9B2A@solfertje.student.utwente.nl> <74881095-CCEF-42DA-B1C7-6F1BC2650D44@solfertje.student.utwente.nl> Date: Tue, 20 Apr 2010 14:32:42 -0500 Received: by 10.142.122.7 with SMTP id u7mr3176492wfc.212.1271791962457; Tue, 20 Apr 2010 12:32:42 -0700 (PDT) Message-ID: Subject: Re: Ltree - how to sort nodes on parent node From: Peter Hunsberger To: Alban Hertroys Cc: xcojack@gmail.com, pgsql-general@postgresql.org Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-0.499 tagged_above=-10 required=5 tests=BAYES_05=-0.5, FREEMAIL_FROM=0.001 X-Spam-Level: X-Archive-Number: 201004/663 X-Sequence-Number: 161861 On Tue, Apr 20, 2010 at 1:58 PM, Alban Hertroys wrote: > On 20 Apr 2010, at 11:59, cojack wrote: > > >> I am not interested about recursive queries, i think this kill ltree ide= a. > > > And IMHO it should. ltree is from a time when we didn't have any other me= ans to describe data organised as a tree in Postgres. Navigating a tree is = inherently recursive, so recursion is most likely the proper way to go abou= t it. > > A solution omitting recursion (like ltree) can be faster, but you will ru= n into limitations like the one you're currently struggling with. > > A solution with recursive queries will probably be more flexible and allo= ws for referential integrity without having to write your own triggers and = stuff - for example, what happens if you decide that Archeology isn't a Sci= ence but a Colour? What makes sure it's child-nodes get moved into Colors a= s well? > I've only been peripherally following this thread, so the following may be overkill for the requirements, but the non-recursive / flat query, solution is usually the set / subset pattern. It's been popularized by Joe Celko and he has gone as far as writing a book on the topic "Trees and hierarchies in SQL for smarties". If you don't have many requirements for reordering the tree this solution works well. It can be more of a pain if you need a GUI for tree management (but can be done). We use this type of solution to manage trees up to about 100,000 nodes in size with good performance. Other non-recursive solutions include Vadim Tropashko's (now with Oracle) Nested Interval Tree Encoding methods, which map directly to the dotted path (1.1.3) type tree notations in the examples in this thread and are a variation on the set / subset models. --=20 Peter Hunsberger