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 02277D7738 for ; Fri, 26 Aug 2005 15:12:53 -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 52406-10 for ; Fri, 26 Aug 2005 18:12:51 +0000 (GMT) Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by svr1.postgresql.org (Postfix) with ESMTP id 8B5EBD6FEF for ; Fri, 26 Aug 2005 13:42:45 -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 j7QGgf4t009942; Fri, 26 Aug 2005 12:42:41 -0400 (EDT) To: "Jim C. Nasby" Cc: Mark Fox , pgsql-performance@postgresql.org Subject: Re: Performance indexing of a simple query In-reply-to: <20050826162801.GF11282@pervasive.com> References: <16554.1124926920@sss.pgh.pa.us> <20050826162801.GF11282@pervasive.com> Comments: In-reply-to "Jim C. Nasby" message dated "Fri, 26 Aug 2005 11:28:02 -0500" Date: Fri, 26 Aug 2005 12:42:41 -0400 Message-ID: <9941.1125074561@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/448 X-Sequence-Number: 14195 "Jim C. Nasby" writes: > Uh, the plain english and the SQL don't match. That query will find > every job that was NOT running at the time you said. No, I think it was right. But anyway it was just an example. > On Wed, Aug 24, 2005 at 07:42:00PM -0400, Tom Lane wrote: >> 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. > Ignoring the SQL and doing what the author actually wanted, wouldn't a > bitmap combination of indexes work here? > Or with an index on (start_time, completion_time), start an index scan > at start_time = SOMEDATE and only include rows where completion_time < > SOMEDATE. Of course if SOMEDATE is near the beginning of the table that > wouldn't help. The trouble with either of those is that you have to scan very large fractions of the index (if not indeed *all* of it) in order to get your answer; certainly you hit much more of the index than just the region containing matching rows. Btree just doesn't have a good way to answer this type of query. regards, tom lane