Re: Efficient Boolean Storage

From: Felipe Schnack <felipes(at)ritterdosreis(dot)br>
To: pgsql-general <pgsql-general(at)postgresql(dot)org>
Subject: Re: Efficient Boolean Storage
Date: 2002-12-04 16:01:22
Message-ID: 1039017682.2456.107.camel@desenv1.ritterdosreis.br
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Why worry if a boolean isn't a bit in database storage?
When they are loaded to your CPU they will fill a register anyway (32
bits)

On Wed, 2002-12-04 at 14:01, Ericson Smith wrote:
> Hmmm...
>
> You can store them in an int4 type (will take up to 31)
>
> To store your numbers:
> $num = (2^$num1) + (2^$num2) ...
> where $num1 and $num2 are your bit positions that you want to set to
> "1",
>
> To retrieve them...
> SELECT * FROM table WHERE ((mycol & 2^1) != 0 OR (mycol & 2^3) != 0)
> Here you are checking for the 1st bit position and the 3rd bit position.
>
> - Ericson Smith
> eric(at)did-it(dot)com
>
> On Wed, 2002-12-04 at 10:11, Richard Huxton wrote:
> > On Wednesday 04 Dec 2002 1:06 am, Chris White wrote:
> > > Hello,
> > >
> > > I need to store many (e.g. 30) booleans and am wondering what is the
> > > most efficient way to store them. I can think of four options.
> > >
> > > Option 1...Use 'bool' data type
> > > No good since each value will require 1 byte rather than 1 bit.
> >
> > Depends what you're going to use them for. Are these 30 flags that should be
> > grouped together? Will the users/app want all together or one at a time? Will
> > they feature in WHERE clauses?
> >
> > --
> > Richard Huxton
> >
> > ---------------------------(end of broadcast)---------------------------
> > TIP 3: if posting/reading through Usenet, please send an appropriate
> > subscribe-nomail command to majordomo(at)postgresql(dot)org so that your
> > message can get through to the mailing list cleanly
>
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 6: Have you searched our list archives?
>
> http://archives.postgresql.org
--

Felipe Schnack
Analista de Sistemas
felipes(at)ritterdosreis(dot)br
Cel.: (51)91287530
Linux Counter #281893

Faculdade Ritter dos Reis
www.ritterdosreis.br
felipes(at)ritterdosreis(dot)br
Fone/Fax.: (51)32303328

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Ericson Smith 2002-12-04 16:01:49 Re: Efficient Boolean Storage
Previous Message Scott Lamb 2002-12-04 15:55:31 Re: User date_trunc function in plpgsql function