Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>It looks like in PostgreSQL constraint exclusion on booleans does not work. When you use <code>integer</code> or <code>enum</code> then it works well.</p> <p>Integer:</p> <pre><code>CREATE TABLE mos (type_id INTEGER UNIQUE, expired int); CREATE TABLE mos_expired_1 ( CHECK ( expired = 0 ) ) INHERITS (mos); CREATE TABLE mos_active_1 ( CHECK ( expired = 1 ) ) INHERITS (mos); INSERT INTO mos_expired_1 (type_id,expired) VALUES(1, 0); INSERT INTO mos_active_1 (type_id,expired) VALUES(2, 1); analyze; EXPLAIN SELECT * from mos where expired = 0; QUERY PLAN ----------------------------------------------------------------------------- Result (cost=0.00..37.76 rows=12 width=8) -&gt; Append (cost=0.00..37.76 rows=12 width=8) -&gt; Seq Scan on mos (cost=0.00..36.75 rows=11 width=8) Filter: (expired = 0) -&gt; Seq Scan on mos_expired_1 mos (cost=0.00..1.01 rows=1 width=8) Filter: (expired = 0) (6 rows) EXPLAIN SELECT * from mos where expired = 1; QUERY PLAN ---------------------------------------------------------------------------- Result (cost=0.00..37.76 rows=12 width=8) -&gt; Append (cost=0.00..37.76 rows=12 width=8) -&gt; Seq Scan on mos (cost=0.00..36.75 rows=11 width=8) Filter: (expired = 1) -&gt; Seq Scan on mos_active_1 mos (cost=0.00..1.01 rows=1 width=8) Filter: (expired = 1) (6 rows) </code></pre> <p>Enum:</p> <pre><code>CREATE TYPE mybool AS ENUM ('true', 'false'); CREATE TABLE mos (type_id INTEGER UNIQUE, expired mybool); CREATE TABLE mos_expired_1 ( CHECK ( expired = 'true' ) ) INHERITS (mos); CREATE TABLE mos_active_1 ( CHECK ( expired = 'false' ) ) INHERITS (mos); INSERT INTO mos_expired_1 (type_id,expired) VALUES(1, 'true'); INSERT INTO mos_active_1 (type_id,expired) VALUES(2, 'false'); analyze; EXPLAIN SELECT * from mos where expired = 'true'; QUERY PLAN ----------------------------------------------------------------------------- Result (cost=0.00..37.76 rows=12 width=8) -&gt; Append (cost=0.00..37.76 rows=12 width=8) -&gt; Seq Scan on mos (cost=0.00..36.75 rows=11 width=8) Filter: (expired = 'true'::mybool) -&gt; Seq Scan on mos_expired_1 mos (cost=0.00..1.01 rows=1 width=8) Filter: (expired = 'true'::mybool) (6 rows) EXPLAIN SELECT * from mos where expired = 'false'; QUERY PLAN ---------------------------------------------------------------------------- Result (cost=0.00..37.76 rows=12 width=8) -&gt; Append (cost=0.00..37.76 rows=12 width=8) -&gt; Seq Scan on mos (cost=0.00..36.75 rows=11 width=8) Filter: (expired = 'false'::mybool) -&gt; Seq Scan on mos_active_1 mos (cost=0.00..1.01 rows=1 width=8) Filter: (expired = 'false'::mybool) (6 rows) </code></pre> <p>I don't know if it is a bug. I think it is not documented anywhere.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload