Received: from maia.hub.org (unknown [200.46.208.211]) by mail.postgresql.org (Postfix) with ESMTP id B98C36331C5 for ; Fri, 12 Feb 2010 09:31:38 -0400 (AST) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.208.211]) (amavisd-maia, port 10024) with ESMTP id 27555-08 for ; Fri, 12 Feb 2010 13:31:02 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mail-ew0-f214.google.com (mail-ew0-f214.google.com [209.85.219.214]) by mail.postgresql.org (Postfix) with ESMTP id D5A2663261E for ; Fri, 12 Feb 2010 09:31:27 -0400 (AST) Received: by ewy6 with SMTP id 6so13851ewy.34 for ; Fri, 12 Feb 2010 05:31:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from :user-agent:mime-version:to:cc:subject:references:in-reply-to :content-type:content-transfer-encoding; bh=HCf1ruJgeAD7U3VVpXJn402ZWz5833e8nwqbEfa0+/s=; b=stXCmcj+Pv/3y+oKklHN8W1YWdCjvRFZhAXVdWyKJ2q8xjCB782IEmXzAvIO3tOTHM nl/zuWWwOpBkIFmlNedna6VtrjqJxS9ctjxpmC9Ebf+KPyloCr1jCfs0Bb/+gDh+yyqj yQ7MQUtainO15iqP0zWNGyh/PHyIDYIO5CiUo= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:user-agent:mime-version:to:cc:subject :references:in-reply-to:content-type:content-transfer-encoding; b=nZj1XN2HgKAqwu7JunSAHGTZI3QdeRYacDWqv5nn6nR1Xfa8F6gp13mc6PheKSmPc5 EdlKLywYVc81vuNEAYiMl/EUgknXO3AAW+5WH4hJ709tWBNxiNjSyKOsUdbiuJgRysNk 9dgxcYjMaLPiCLVsVJZbqlzY3Wg+2I96lt/Rk= Received: by 10.213.37.82 with SMTP id w18mr944430ebd.97.1265981485620; Fri, 12 Feb 2010 05:31:25 -0800 (PST) Received: from ?0.0.0.0? (5357DA75.cable.casema.nl [83.87.218.117]) by mx.google.com with ESMTPS id 14sm2341567ewy.3.2010.02.12.05.31.22 (version=TLSv1/SSLv3 cipher=RC4-MD5); Fri, 12 Feb 2010 05:31:23 -0800 (PST) Message-ID: <4B75582A.9090100@gmail.com> Date: Fri, 12 Feb 2010 14:31:22 +0100 From: Yeb Havinga User-Agent: Thunderbird 2.0.0.23 (Windows/20090812) MIME-Version: 1.0 To: Luiz Angelo Daros de Luca CC: pgsql-performance@postgresql.org Subject: Re: Immutable table functions References: <8b96e3d21002120454q77b1d72eq38a91b7f486e8f29@mail.gmail.com> In-Reply-To: <8b96e3d21002120454q77b1d72eq38a91b7f486e8f29@mail.gmail.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-2.339 tagged_above=-10 required=5 tests=AWL=0.260, BAYES_00=-2.599 X-Spam-Level: X-Archive-Number: 201002/198 X-Sequence-Number: 37619 Luiz Angelo Daros de Luca wrote: > > I have a directed graph, or better, a tree in postgresql 8.3. One > table are the nodes and another one are the connections. Given any > node, I need to get all nodes down to it(to the leafs) that have > relation with anotherTable. Also, this connection change on time, so I > have a connectionDate and a disconnectionDate for each connection > (which might be null to represent open interval). This way, I wrote a > pgsql function (I rename the tables and columns to generic names). > These are the tables and the function: > Hello Luiz, If you could upgrade to 8.4, you could use WITH RECURSIVE - my experience is that it is several orders of magnitude faster than recursive functions. http://developer.postgresql.org/pgdocs/postgres/queries-with.html regards, Yeb Havinga