Postgres not using index when index scan is much better option

前端 未结 2 2001
花落未央
花落未央 2020-12-05 10:53

I have a simple query to join two tables that\'s being really slow. I found out that the query plan does a seq scan on the large table email_activities (~10m ro

2条回答
  •  余生分开走
    2020-12-05 11:05

    A sequential scan can be more efficient, even when an index exists. In this case, postgres seems to estimate things rather wrong. An ANALYZE

    on all related tables can help in such cases. If it doesnt, you can set the variable enable_seqscan to OFF, to force postgres to use an index whenever technically possible, at the expense, that sometimes an index-scan will be used when a sequential scan would perform better.

    提交回复
    热议问题