I need help understanding why a partial index would be used in one query and would not in second one which is effectively the same.
I have the following table:
Column | Type | Collation | Nullable | Default
----------------+--------------------------+-----------+----------+-------------
id | text | | not null |
field1 | text | | not null |
field2 | text | | not null |
field3 | boolean | | not null | false
With a partial index:
CREATE INDEX idx__my_table_index
ON my_table(field1, field2)
WHERE field3 IS FALSE;
and the following two queries:
postgres=> explain select distinct field1, field2 from my_table where not field3;
-[ RECORD 1 ]----------------------------------------------------------------------------
QUERY PLAN | Unique (cost=113849.28..113849.66 rows=36 width=29)
-[ RECORD 2 ]----------------------------------------------------------------------------
QUERY PLAN | -> Sort (cost=113849.28..113849.37 rows=38 width=29)
-[ RECORD 3 ]----------------------------------------------------------------------------
QUERY PLAN | Sort Key: field1, field2
-[ RECORD 4 ]----------------------------------------------------------------------------
QUERY PLAN | -> Seq Scan on my_table (cost=0.00..113848.28 rows=38 width=29)
-[ RECORD 5 ]----------------------------------------------------------------------------
QUERY PLAN | Filter: (NOT field3)
and the second:
postgres=> explain select distinct field1, field2 from my_table where field3 IS FALSE;
-[ RECORD 1 ]-----------------------------------------------------------------------------------------------------------------------
QUERY PLAN | Unique (cost=0.14..13.03 rows=36 width=29)
-[ RECORD 2 ]-----------------------------------------------------------------------------------------------------------------------
QUERY PLAN | -> Index Only Scan using idx__my_table_index on reservation (cost=0.14..12.75 rows=38 width=29)
P.S. I'm using PostgreSQL 9.6
WHERE field3 = FALSE?