Return-Path: X-Original-To: apmail-couchdb-user-archive@www.apache.org Delivered-To: apmail-couchdb-user-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 33F0DE350 for ; Fri, 22 Feb 2013 05:49:51 +0000 (UTC) Received: (qmail 7990 invoked by uid 500); 22 Feb 2013 05:49:49 -0000 Delivered-To: apmail-couchdb-user-archive@couchdb.apache.org Received: (qmail 7954 invoked by uid 500); 22 Feb 2013 05:49:49 -0000 Mailing-List: contact user-help@couchdb.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: user@couchdb.apache.org Delivered-To: mailing list user@couchdb.apache.org Received: (qmail 7934 invoked by uid 99); 22 Feb 2013 05:49:49 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 22 Feb 2013 05:49:49 +0000 X-ASF-Spam-Status: No, hits=1.5 required=5.0 tests=HTML_MESSAGE,RCVD_IN_DNSWL_LOW,SPF_PASS,T_FILL_THIS_FORM_SHORT X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: domain of andrey.kouprianov@gmail.com designates 74.125.82.46 as permitted sender) Received: from [74.125.82.46] (HELO mail-wg0-f46.google.com) (74.125.82.46) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 22 Feb 2013 05:49:42 +0000 Received: by mail-wg0-f46.google.com with SMTP id fg15so218160wgb.13 for ; Thu, 21 Feb 2013 21:49:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=x-received:mime-version:in-reply-to:references:from:date:message-id :subject:to:content-type; bh=qOToK+OjfMt5aL+60AlZ77MKHALDqAxIIp4HBg5B4Rk=; b=YXdfQb17cvrK6xVRl1UxA8Nu/ox+VmuKEPbLi9UjMoZ9jIwqrm4bEQPoLccb/Xb5dH aELZpAB6Uid4nVH9WqCsyf0qTYdjBETDK6ubzbpuSx0oEXrHRnHxmx74gZNq/INIahYe LAcSOsJV4BGTzqMhKjh67PsB9nZ2lRHQDaHVxC6ji/M9KlEDJTUUlDHFArIo5eX4Byjj WJl06K70V5dMc1XCBje9QuvRsgvXJ4CA9YaIVTrEsH3F80KuV8CaIPfioKpRVrcsP77c L13fx0aFMybzBOPI+vmCh3w65rXyUjlrn10i2bTBT2n73mIIV7icIcnx8gYbxCLkQKca JsRQ== X-Received: by 10.194.176.165 with SMTP id cj5mr960613wjc.37.1361512162150; Thu, 21 Feb 2013 21:49:22 -0800 (PST) MIME-Version: 1.0 Received: by 10.217.82.195 with HTTP; Thu, 21 Feb 2013 21:49:01 -0800 (PST) In-Reply-To: References: <5126F04D.8010305@binarykitchen.com> <20130222132727.5b04d528@dede> <5126FEC9.3080900@binarykitchen.com> From: Andrey Kuprianov Date: Fri, 22 Feb 2013 13:49:01 +0800 Message-ID: Subject: Re: Tree like structures in CouchDB To: user@couchdb.apache.org Content-Type: multipart/alternative; boundary=089e013d15d8c855e204d649c0df X-Virus-Checked: Checked by ClamAV on apache.org --089e013d15d8c855e204d649c0df Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable PS - storing only an immediate parent id would be the solution for an infinite tree depth. On Fri, Feb 22, 2013 at 1:48 PM, Andrey Kuprianov < andrey.kouprianov@gmail.com> wrote: > Storing immediate children in a parent is a bad idea in a sense that you > will never be able to traverse your tree back to the root, given a child > node. > > Storing all in one doc - you will run out of space before you know it. > Documents have a finite length and the larger the document, the slower it > will get to serialize and unserialize it. > > Storing just an immediate parent in children might result in a costly > multiple read operations, if you want to get root of the tree given an > arbitrary child. > > Therefore the only feasible solution is to store references to the parent > chain - i.e. ancestors - starting from an immediate parent and ending wit= h > a tree root. > > > Here's a simple calculation for ancestors approach: > > Suppose the maximum document size is 1MB. A uuid is 32 characters in > length + taking into account commas and brackets, then the depth of your > tree (I am not taking content into account) could be roughly: > > ((32 + 1)*n + 2 - 1) =3D 1024 * 1024 =3D=3D> n =3D 31775 levels > > However, max document size is configurable from the settings (as of > CouchDB 1.2) and could easily be up to 4GB, giving you over 130mil of > levels. Should be enough... :) > > > > On Fri, Feb 22, 2013 at 1:14 PM, Michael Heuberger < > michael.heuberger@binarykitchen.com> wrote: > >> thanks andrey and svil >> >> depth is infinite. in theory a message can have million replies forth an= d >> back. similar like a very long email thread. >> >> i think storing ancestors =C4=85 la andrey would be too much hassle but = works >> well for few levels. >> >> svil, what did you mean with dicts and with keeping all children in one >> doc? can you tell me more? >> >> thanks, >> michael >> >> >> On 22/02/13 17:27, svilen wrote: >> >>> my rough guess: >>> >>> if it's finite depth, then all in one doc: >>> - list of (item or (list of ...)) >>> - or same with dicts >>> >>> else, one doc per message keeping just link-to-parent, >>> or multiple links-to-grand...grand-parents and/or root. >>> similar to the strategies in SQL - nested etc. >>> keeping all chidlren of same node in one doc is also possible.. >>> >>> in any case either traversal or storing or both will be >>> difficult. >>> >>> ciao >>> svil >>> >>> On Fri, 22 Feb 2013 17:13:01 +1300 >>> Michael Heuberger > >>> wrote: >>> >>> Hello guys >>>> >>>> I'd like to store messages in a tree like structure. Whenever you >>>> reply to a message, then the original message becomes the parent >>>> message. >>>> >>>> How would you implement something like this in CouchDB? Just curious >>>> and need a little guidance + advice here. >>>> >>>> Thanks, >>>> Michael >>>> >>>> -- >>>> >>>> Binary Kitchen >>>> Michael Heuberger >>>> 4c Dunbar Road >>>> Mt Eden >>>> Auckland 1024 >>>> (New Zealand) >>>> >>>> Mobile (text only) ... +64 21 261 89 81 >>>> Email ................ michael@binarykitchen.com >>>> Website .............. http://www.binarykitchen.com >>>> >>>> >> -- >> >> Binary Kitchen >> Michael Heuberger >> 4c Dunbar Road >> Mt Eden >> Auckland 1024 >> (New Zealand) >> >> Mobile (text only) ... +64 21 261 89 81 >> Email ................ michael@binarykitchen.com >> Website .............. http://www.binarykitchen.com >> >> > --089e013d15d8c855e204d649c0df--