Whether NULL
values get to the index or not depend at least on the type of the index.
Basically, this would be YES for btree
and gist
index types, NO for hash
, and it seems YES or NO for gin
index types depending on PostgreSQL version.
There used to be a boolean column amindexnulls
in the pg_catalog.pg_am
table that carried that information, but it's gone in 9.1. Probably because indexes have got even more sophisticated among PG improvements.
In the specific case of your data, the best way to know would be to measure the size difference of indexes, using the pg_relation_size('index_name')
function, between contents entirely NULL and entirely NOT NULL, with your exact PG version, exact datatype, exact index type and definition. And know that possibly, a future change in any of these parameters may change the outcome.
But in any case, if you "just" want to avoid indexing NULLs, it's always possible to create a partial index:
CREATE INDEX partial_idx(col) ON table WHERE (col is not null)
This is going to take less space, but whether this is going to help or not with the performance of queries depend on these queries.