X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 7DF3CD7AA1 for ; Wed, 24 Aug 2005 20:42:01 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 34651-02 for ; Wed, 24 Aug 2005 23:42:00 +0000 (GMT) Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by svr1.postgresql.org (Postfix) with ESMTP id 651FFD78D3 for ; Wed, 24 Aug 2005 20:41:58 -0300 (ADT) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.13.1/8.13.1) with ESMTP id j7ONg0oU016555; Wed, 24 Aug 2005 19:42:00 -0400 (EDT) To: Mark Fox Cc: pgsql-performance@postgresql.org Subject: Re: Performance indexing of a simple query In-reply-to: References: Comments: In-reply-to Mark Fox message dated "Wed, 24 Aug 2005 14:43:51 -0600" Date: Wed, 24 Aug 2005 19:42:00 -0400 Message-ID: <16554.1124926920@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.006 required=5 tests=[AWL=0.006] X-Spam-Level: X-Archive-Number: 200508/412 X-Sequence-Number: 14159 Mark Fox writes: > The sort of queries I want to execute (among others) are like: > SELECT * FROM jobs > WHERE completion_time > SOMEDATE AND start_time < SOMEDATE; > In plain english: All the jobs that were running at SOMEDATE. AFAIK there is no good way to do this with btree indexes; the problem is that it's fundamentally a 2-dimensional query and btrees are 1-dimensional. There are various hacks you can try if you're willing to constrain the problem (eg, if you can assume some not-very-large maximum on the running time of jobs) but in full generality btrees are just the Wrong Thing. So what you want to look at is a non-btree index, ie, rtree or gist. For example, the contrib/seg data type could pretty directly be adapted to solve this problem, since it can index searches for overlapping line segments. The main drawback of these index types in existing releases is that they are bad on concurrent updates and don't have WAL support. Both those things are (allegedly) fixed for GIST in 8.1 ... are you interested in trying out 8.1beta? regards, tom lane