Received: from localhost (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id CB23B475B8A for ; Tue, 29 Oct 2002 21:12:42 -0500 (EST) Received: from wolff.to (unknown [66.93.197.35]) by postgresql.org (Postfix) with SMTP id 25108475AFA for ; Tue, 29 Oct 2002 21:12:42 -0500 (EST) Received: (qmail 32703 invoked by uid 500); 30 Oct 2002 02:22:00 -0000 Date: Tue, 29 Oct 2002 20:22:00 -0600 From: Bruno Wolff III To: Peter Eisentraut Cc: Josh Berkus , Stephan Szabo , pgsql-sql@postgresql.org Subject: Re: BOOLEAN question Message-ID: <20021030022200.GB32582@wolff.to> Mail-Followup-To: Peter Eisentraut , Josh Berkus , Stephan Szabo , pgsql-sql@postgresql.org References: <200210281729.35967.josh@agliodbs.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.3.25i X-Virus-Scanned: by AMaViS new-20020517 X-Archive-Number: 200210/396 X-Sequence-Number: 10113 On Tue, Oct 29, 2002 at 23:19:55 +0100, Peter Eisentraut wrote: > Josh Berkus writes: > > > I wrote a MAX(bool), what are the chances it would get added to the core? I > > don't see any good reason not to have one. > > One reason not to have one is that Boolean values are not naturally > ordered, so a maximum doesn't exist. (Yes, I know there are comparison > operators defined for boolean, but that doesn't make it right.) > > What seems more reasonable is to define conjuntion and disjunction > aggregates, which would mostly do the same thing but their semantics > wouldn't be as controversial. However they would be slow. If you use an aggregate you don't get to short circuit the calculation. And for even distributed true and false values, most of the time the aggregate result would be known after just a few rows were checked. When checking for such values in long lived tables where one of the values occurs seldomly, using a partial index and a select could be a big win. I don't think this will work in the case that started this thread since it postulated checking the output of a complex query. However even in this case it may be worthwhile to rewrite the query as an exists test for boolcol to be the short circuit value so that the complex query need not be fully calculated.