Unix Technical Forum

BUG #1510: Indexes on boolean fields

This is a discussion on BUG #1510: Indexes on boolean fields within the pgsql Bugs forums, part of the PostgreSQL category; --> The following bug has been logged online: Bug reference: 1510 Logged by: Sergey Koshcheyev Email address: sergey.p.k@gmail.com PostgreSQL version: ...


Go Back   Unix Technical Forum > Database Server Software > PostgreSQL > pgsql Bugs

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 04-10-2008, 09:36 AM
Sergey Koshcheyev
 
Posts: n/a
Default BUG #1510: Indexes on boolean fields


The following bug has been logged online:

Bug reference: 1510
Logged by: Sergey Koshcheyev
Email address: sergey.p.k@gmail.com
PostgreSQL version: 7.4.7
Operating system: Debian Linux
Description: Indexes on boolean fields
Details:

Hi,

this is an addition to my bug report #1470. I have found that if I have a
boolean column and create an index on it, it doesn't get picked up for
conditions like "WHERE column" or "WHERE NOT column", only "WHERE column =
true" or "WHERE column = false".

Do you consider this worth fixing? I believe that #1470 would then be fixed
also, and it would be very useful for me.

Here's a complete listing of what I did, the two last EXPLAINs show the
problem.

office=> create table booltest (id serial not null primary key, b boolean);
NOTICE: CREATE TABLE will create implicit sequence "booltest_id_seq" for
"serial" column "booltest.id"
NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index
"booltest_pkey" for table "booltest"
CREATE TABLE

(insert 57336 values into booltest(b), 6211 of them are false - based on
some real data)

office=> create index booltest_b on booltest (b);
CREATE INDEX

office=> analyze booltest;
ANALYZE
office=> explain select * from booltest where b = true;
QUERY PLAN
---------------------------------------------------------------
Seq Scan on booltest (cost=0.00..1001.10 rows=51776 width=5)
Filter: (b = true)
(2 rows)

office=> explain select * from booltest where b = false;
QUERY PLAN
----------------------------------------------------------------------------
----
Index Scan using booltest_b on booltest (cost=0.00..586.29 rows=5753
width=5)
Index Cond: (b = false)
(2 rows)

office=> explain select * from booltest where not b;
QUERY PLAN
-------------------------------------------------------------
Seq Scan on booltest (cost=0.00..857.28 rows=5753 width=5)
Filter: (NOT b)
(2 rows)

office=> explain select * from booltest where b = false;
QUERY PLAN
----------------------------------------------------------------------------
----
Index Scan using booltest_b on booltest (cost=0.00..586.29 rows=5753
width=5)
Index Cond: (b = false)
(2 rows)

Thanks,
Sergey.

P.S. I can't write to psql-bugs, even though I am subscribed - my messages
don't reach the list (they don't appear on Gmane). Have I been banned?

---------------------------(end of broadcast)---------------------------
TIP 5: Have you checked our extensive FAQ?

http://www.postgresql.org/docs/faq

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 04-10-2008, 09:36 AM
Tom Lane
 
Posts: n/a
Default Re: BUG #1510: Indexes on boolean fields

"Sergey Koshcheyev" <sergey.p.k@gmail.com> writes:
> this is an addition to my bug report #1470. I have found that if I have a
> boolean column and create an index on it, it doesn't get picked up for
> conditions like "WHERE column" or "WHERE NOT column", only "WHERE column =
> true" or "WHERE column = false".


> Do you consider this worth fixing?


No; mainly because a btree index on a boolean column is ordinarily a
waste of disk space.

A partial index (with some non-boolean column as the nominally indexed
data) is generally a better solution.

regards, tom lane

---------------------------(end of broadcast)---------------------------
TIP 1: subscribe and unsubscribe commands go to majordomo@postgresql.org

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 03:03 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com