All pastes #387949 Raw Edit

Someone

public text v1 · immutable
·published 2007-03-09 19:01 UTC
rendered paste body
postgres=# \d test
     Table "public.test"
 Column |  Type   | Modifiers 
--------+---------+-----------
 bit    | boolean | 
 but    | integer | 

postgres=# select count(*) from test;
  count  
---------
 1010023
(1 row)

postgres=# select count(but) from test where bit;
 count 
-------
  1049
(1 row)

postgres=# explain select but from test where bit limit 1000;
                           QUERY PLAN                            
-----------------------------------------------------------------
 Limit  (cost=0.00..7451.00 rows=1000 width=4)
   ->  Seq Scan on test  (cost=0.00..15051.03 rows=2020 width=4)
         Filter: "bit"
(3 rows)

postgres=# create index bits on test(bit);
CREATE INDEX

postgres=# explain select but from test where bit limit 1000;
                                 QUERY PLAN                                 
----------------------------------------------------------------------------
 Limit  (cost=0.00..62.88 rows=1000 width=4)
   ->  Index Scan using bits on test  (cost=0.00..127.02 rows=2020 width=4)
         Index Cond: ("bit" = true)
         Filter: "bit"
(4 rows)