I have a table which is basically a tree structure with a column parent_id
and id
.
parent_id
is null
for root nodes.
There is also a self referential foreign key, so that every parent_id
has a corresponding id
.
This table is mainly read-only with mostly infrequent batch updates.
One of the most common queries from the application which accesses this table is select ... where parent_id = X
. I thought this might be faster if this table was index organised on parent_id
.
However, I'm not sure how to index organise this table if parent_id
can be null
. I'd rather not fudge things so that parent_id=0
is some special id, as I'd have to add dummy values to the table to ensure the foreign key constraints are satisfied, and it also changes the application logic.
Is there any way to index organise a table by possible null
value columns?