Re: BOOLEAN question - Mailing list pgsql-sql

From Bruno Wolff III
Subject Re: BOOLEAN question
Date
Msg-id 20021030022200.GB32582@wolff.to
Whole thread Raw
In response to Re: BOOLEAN question  (Peter Eisentraut <peter_e@gmx.net>)
List pgsql-sql
On Tue, Oct 29, 2002 at 23:19:55 +0100, Peter Eisentraut <peter_e@gmx.net> 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.


pgsql-sql by date:

Previous
From: "James Adams"
Date:
Subject: Selecting * from the base table but getting the inheriteds columns
Next
From: Viacheslav N Tararin
Date:
Subject: Database Design tool