The following bug has been logged online:
Bug reference: 4800
Logged by: Alex
Email address: alex@xdcom.org
PostgreSQL version: 8.3.6
Operating system: rhel5
Description: constraint_exclusion could be smarter with bool
conversion
Details:
Table "public.foo1"
Column | Type | Modifiers
-------------+------------------------+--------------------
val | character varying(16) | not null
mask | integer | default 0
Check constraints:
"foo_1_mask_check" CHECK (mask = 1)
Inherits: foo
=> EXPLAIN select * from foo1 where mask >1;
QUERY PLAN
------------------------------------------
Result (cost=0.00..0.01 rows=1 width=0)
One-Time Filter: false
(2 rows)
=> EXPLAIN select * from foo1 where (mask &2)::bool;
QUERY PLAN
-----------------------------------------------------------------
Seq Scan on foo1 (cost=0.00..100.32 rows=896 width=59)
Filter: ((mask & 2))::boolean
(2 rows)
There many children of table foo like foo1,..fooN. with different
check(mask=2^N).
I wish constraint_exclusion to be smarter with bool conversion so that
'select * from foo where (mask&5)::bool' can be faster;