X-Original-To: pgsql-sql-postgresql.org@postgresql.org Received: from localhost (mx1.hub.org [200.46.208.251]) by postgresql.org (Postfix) with ESMTP id B261B9FB2D6 for ; Mon, 14 Aug 2006 22:07:08 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.208.251]) (amavisd-new, port 10024) with ESMTP id 24922-05 for ; Mon, 14 Aug 2006 22:06:58 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey- Received: from svr4.postgresql.org (svr4.postgresql.org [66.98.251.159]) by postgresql.org (Postfix) with ESMTP id 770B09FB1C8 for ; Mon, 14 Aug 2006 22:06:57 -0300 (ADT) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.3 Received: from pow.actarg.com (host25.actarg.com [209.180.91.25]) by svr4.postgresql.org (Postfix) with ESMTP id 8CA6A5AF039 for ; Tue, 15 Aug 2006 01:06:56 +0000 (GMT) Received: from [192.168.5.50] (bateman.cc [65.73.113.56]) (authenticated bits=0) by pow.actarg.com (8.13.1/8.13.1) with ESMTP id k7F16ixY016105 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Mon, 14 Aug 2006 19:06:49 -0600 Message-ID: <44E11E1A.8020507@actarg.com> Date: Mon, 14 Aug 2006 19:06:34 -0600 From: Kyle Bateman User-Agent: Mozilla Thunderbird 1.0.8-1.1.fc4 (X11/20060501) X-Accept-Language: en-us, en MIME-Version: 1.0 To: pgsql-sql@postgresql.org Cc: Florian Weimer Subject: Re: Using bitmap index scans-more efficient References: <44DF6582.4000806@actarg.com> <82mza77rch.fsf@mid.bfk.de> In-Reply-To: <82mza77rch.fsf@mid.bfk.de> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: ClamAV 0.88/1656/Sun Aug 13 21:24:35 2006 on pow.actarg.com X-Virus-Status: Clean X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0 tagged_above=0 required=5 tests= X-Spam-Level: X-Archive-Number: 200608/100 X-Sequence-Number: 26058 Florian Weimer wrote: >* Kyle Bateman: > > > >>Any ideas about whether/how this can be done? >> >> > >If the project tree is fairly consistent, it's convenient to encode it >using intervals instead of parent/child intervals. IIRC, Celko's "SQL >for smarties" explains how to do this, and Kristian Koehntopp has >written some PHP code to implement it. > > > I agree that this produces a more efficient query for finding the projects that are the progeny of another project, but I'm trying to figure out how that helps me select the right project transactions from my ledger efficiently. This query produces wonderful results (very fast): select * from ledger where proj >= 4737 and proj <= 4740; But I'm assuming that using an interval-encoded project tree, I would have to do something like the following to get a progency group: select * from ledger l, proj p where p.proj_id = l.proj and p.left > 1234 and p.right < 2345; The problem (at least according to my initial testing) is that this forces a join of the entire ledger and I get my slowest performance group (5 seconds). What am I missing? Kyle