Hi!

I recently noticed that the default indexes that Django generates for 
foreign keys also index NULL values, at least for PostgreSQL. Is this on 
purpose?

>From my digging, it looks like PostgreSQL used to exclude NULL values from 
the index, but not since some years. It's relatively easy to skip them by 
appending "where ... is not null" to the index creation, like this:

  create index for_bar_id_index on foo (bar_id) where bar_id is not null;

This comes up because nullable foreign keys are for optional relations, and 
I sometimes have big tables with a bunch of mostly NULL foreign keys (NULLs 
are cheap in PostgreSQL), and the indexes can then dwarf the table.

I have always assumed that the default indexes where for reverse joining 
and deleting purposes only so keeping track of NULLs doesn't actually seem 
necessary.


Ole


-- 
You received this message because you are subscribed to the Google Groups 
"Django developers  (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-developers+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-developers/d26f0ed4-94f3-48a5-8671-a3dfa3d5440b%40googlegroups.com.

Reply via email to