Re: Efficient Boolean Storage
От | Felipe Schnack |
---|---|
Тема | Re: Efficient Boolean Storage |
Дата | |
Msg-id | 1039017682.2456.107.camel@desenv1.ritterdosreis.br обсуждение исходный текст |
Ответ на | Re: Efficient Boolean Storage (Ericson Smith <eric@did-it.com>) |
Список | 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@did-it.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@postgresql.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@ritterdosreis.br Cel.: (51)91287530 Linux Counter #281893 Faculdade Ritter dos Reis www.ritterdosreis.br felipes@ritterdosreis.br Fone/Fax.: (51)32303328
В списке pgsql-general по дате отправления: