X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 4E0323A506A for ; Sun, 23 Jan 2005 22:29:45 +0000 (GMT) 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 87017-04 for ; Sun, 23 Jan 2005 22:29:40 +0000 (GMT) Received: from flake.decibel.org (flake.decibel.org [66.143.173.58]) by svr1.postgresql.org (Postfix) with ESMTP id 2413C3A4F38 for ; Sun, 23 Jan 2005 22:29:41 +0000 (GMT) Received: by flake.decibel.org (Postfix, from userid 1001) id 2C0D71C8F3; Sun, 23 Jan 2005 16:29:42 -0600 (CST) Date: Sun, 23 Jan 2005 16:29:42 -0600 From: "Jim C. Nasby" To: Tom Lane Cc: pgsql-performance@postgresql.org Subject: Re: Odd number of rows expected Message-ID: <20050123222942.GE67721@decibel.org> References: <20050121203827.GW67721@decibel.org> <26465.1106450280@sss.pgh.pa.us> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <26465.1106450280@sss.pgh.pa.us> X-Operating-System: FreeBSD 4.10-RELEASE-p3 i386 X-Distributed: Join the Effort! http://www.distributed.net User-Agent: Mutt/1.5.6i X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.001 tagged_above=0 required=5 tests=AWL X-Spam-Level: X-Archive-Number: 200501/426 X-Sequence-Number: 10116 On Sat, Jan 22, 2005 at 10:18:00PM -0500, Tom Lane wrote: > "Jim C. Nasby" writes: > > (SELECT b.bucket_id AS rrs_bucket_id, s.* > > FROM rrs.bucket b > > JOIN page_log.log s > > ON ( > > b.prev_end_time < log_time > > AND b.end_time >= log_time ) > > WHERE b.rrs_id = '1' > > AND b.end_time <= '2005-01-21 20:23:00+00' > > AND b.end_time > '1970-01-01 00:00:00+00' > > ) a > > > Basically, it seems that it doesn't understand that each row in log will > > match up with at most one row in bucket. There is a unique index on > > bucket(rrs_id, end_time), so it should be able to tell this. > > Why should it be able to tell that? Indexes: "rrs_bucket__rrs_id__end_time" unique, btree (rrs_id, end_time) Err, crap, I guess that wouldn't work, because of prev_end_time not being in there... In english, each bucket defines a specific time period, and no two buckets can over-lap (though there's no constraints defined to actually prevent that). So reality is that each row in page_log.log will in fact only match one row in bucket (at least for each value of rrs_id). Given that, would the optimizer make a better choice if it knew that (since it means a much smaller result set). Is there any way to tell the optimizer this is the case? Maybe what I ultimately need is a timestamp with interval datatype, that specifies an interval that's fixed in time. -- Jim C. Nasby, Database Consultant decibel@decibel.org Give your computer some brain candy! www.distributed.net Team #1828 Windows: "Where do you want to go today?" Linux: "Where do you want to go tomorrow?" FreeBSD: "Are you guys coming, or what?"