Recently I am facing with situation when in simple query with one where filter postgres doesn't use index. Query like this select * from book where obj_id=465789. Sometimes we have a lot of writes to this table and selects simultaneously. I read this article Postgres not using index when index scan is much better option and Erwin gave excellent answer. But one thing I didn't understand. How too much concurrent write load affects use index or not ?
Asked
Active
Viewed 47 times
0
-
2Please provide more information. What is the output of `EXPLAIN (ANALYZE, BUFFERS)` in both cases? Are you talking about an index scan or an index-only scan? – Laurenz Albe Feb 14 '23 at 13:40
-
About an index scan – Pioneer64 Feb 14 '23 at 14:04
-
It might be a problem with MVCC that keeps multiple versions of the same row into the datapages... – SQLpro Feb 14 '23 at 18:06
-
@LaurenzAlbe the support team is located in another country and they don't want to share the request plan for security reasons. I saw this behavior only when they shared their screen. Sorry( – Pioneer64 Feb 14 '23 at 22:24
-
@Pioneer64 I usually ask my customers to send me the execution plan so I can investigate it at leisure. – Laurenz Albe Feb 15 '23 at 06:10
1 Answers
1
The planner does not ponder the how much concurrent writing there is when making its decisions, so there is no direct effect.
I can think of three possible indirect effects. Concurrent writers might keep the data distribution changing faster than auto-analyze can keep up, so the planner is working with bad row estimates (how many rows have obj_id=465789
right now). Intense writing can clear the visibility map faster than autovacuum can reset it, which will penalize index-only scan cost estimates. And intense writing can bloat the index, and the index size plays a (minor) role in estimating index cost.

jjanes
- 37,812
- 5
- 27
- 34
-
The support team assured me that updating the statistics on the table did not solve the problem with the index at the time of intensive writes. They ran analyze by this table, that is, the statistics are relevant. Based on the answer above, this is not possible. Very bad when DBA don't have access to host to investigate issue( – Pioneer64 Feb 14 '23 at 22:40