Why doesn't Postgresql use index for IN query?

前端 未结 1 2022
春和景丽
春和景丽 2021-01-27 12:44

I have a table social_accounts with a partial index on column facebook_id where user_id IS NULL.

If I do a simple query WHER

1条回答
  •  -上瘾入骨i
    2021-01-27 13:11

    Actually, it is using an index. Just doing so differently.

    An index scan visit rows one by one, going back and forth from one disk page to the next in random order.

    A bitmap index scan starts by filtering disk pages to visit, and then visits the latter one by one sequentially. The recheck cond is because, in each page, you then need to filter out invalid rows.

    For tiny numbers of rows, index scan is cheapest. For more rows, bitmap index scan becomes cheapest. For even larger numbers of rows, a seq scan eventually becomes cheapest.

    0 讨论(0)
提交回复
热议问题