Pavel Stehule <pavel.stehule@gmail.com> writes: > I am trying to fix slow query on PostgreSQL 9.5.4. > The data are almost in RAM
If it's all in RAM, you'd likely be well-served to lower random_page_cost. It looks to me like the planner is estimating pretty accurately how many heap fetches will be eliminated by using the extra index; where it's off seems to be in the cost of those heap fetches relative to the index work.
When I decrease random page cost, then the cost of bitmapscan was decreased too