Why isn't Postgres using the index?

前端 未结 1 1970
日久生厌
日久生厌 2020-12-19 21:32

I have a table with an integer column called account_id. I have an index on that column.

But seems Postgres doesn\'t want to use my index:



        
相关标签:
1条回答
  • 2020-12-19 21:57

    Because of:

    Seq Scan on invoices  (...) (actual ... rows=118027 <— this
       Filter: (account_id = 1)
       Rows Removed by Filter: 51462                    <— vs this
     Total runtime: 39.917 ms
    

    You're selecting so many rows that it's cheaper to read the entire table.

    Related earlier questions and answers from today for further reading:

    • Why doesn't Postgresql use index for IN query?

    • Postgres using wrong index when querying a view of indexed expressions?

    (See also Craig's longer answer on the second one for additional notes on indexes subtleties.)

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