Show heap fetches as percent %
pgiraud opened this issue · 3 comments
It would be nice to get the percentage of rows that are read from the heap.
https://explain.dalibo.com/plan/da11bg7302g59e03#plan/node/11
Plan comes from https://twitter.com/pgMustard/status/1636800885320712216
Also, the warning level may need some adjustments.
The % of blocks is perhaps more important, but you can't have that.
The threshold should be rather low. A rather small proportion is already the sign that you need a VACUUM.
I hope to find time to test soon.
I confirm: a few percent of heap fetches is already a disaster.
Examples (in the worst case: old computer, default configuration, not enough RAM, slow HDD) :
- clean table after an INSERT, vacuumed:
QUERY PLAN
═════════════════════════════════════════════════════════════════════════════════════════════════════════════════════
Index Only Scan using demoheapfetches_i_j_idx on demoheapfetches (actual time=0.984..1477.217 rows=1000000 loops=1)
Heap Fetches: 0
Buffers: shared hit=601242 read=2735
Planning:
Buffers: shared hit=6
Planning Time: 0.273 ms
Execution Time: 1751.430 ms
- 10% new lines, autovacuum is lagging: execution time +100 %
QUERY PLAN
═════════════════════════════════════════════════════════════════════════════════════════════════════════════════════
Index Only Scan using demoheapfetches_i_j_idx on demoheapfetches (actual time=0.066..2935.111 rows=1100000 loops=1)
Heap Fetches: 100001
Buffers: shared hit=745883 read=2486
Planning Time: 0.186 ms
Execution Time: 3365.290 ms
- 30% new lines, autovacuum still lagging: execution time × 78 !!
QUERY PLAN
═══════════════════════════════════════════════════════════════════════════════════════════════════════════════════════
Index Only Scan using demoheapfetches_i_j_idx on demoheapfetches (actual time=0.069..136461.243 rows=1300000 loops=1)
Heap Fetches: 300001
Buffers: shared hit=894764 read=112141
Planning Time: 0.205 ms
Execution Time: 136901.507 ms
- after a vacuum: almost back to normal
QUERY PLAN
═════════════════════════════════════════════════════════════════════════════════════════════════════════════════════
Index Only Scan using demoheapfetches_i_j_idx on demoheapfetches (actual time=0.112..2040.199 rows=1300000 loops=1)
Heap Fetches: 0
Buffers: shared hit=811331 read=2857
Planning:
Buffers: shared hit=15 read=2
Planning Time: 349.595 ms
Execution Time: 2405.755 ms
Won't fix. This doesn't seem very relevant. Instead a warning is displayed each times there's at least one heap fetch.