今までis null での検索ではindexは見てないと勘違いしていた。
ふと実行計画を確認したら、どうやらindexを参照している。。。
(* users.nameにはインデックスを作成してる。)
explain select * from users where name is null;
Bitmap Heap Scan on users
(cost=4.20..13.65 rows=6 width=37)
Recheck Cond: (name IS NULL)
-> Bitmap Index Scan on index_users_on_name
(cost=0.00..4.20 rows=6 width=0)
Index Cond: (name IS NULL)
考察
nullは値じゃないので、並び替えが必要なb-treeインデックスを貼るのは無理かと思っていた。
nullは末尾か先頭に配置することでnullを含めてインデックスを作ってるのかな?
参考