I have gone through documentation and previous stackoverflow questions but not findings those helpful. Postgres version 10.6
Even for index only scans values of idx_tup_fetch is increasing. So I am not able to understand difference between idx_tup_read and idx_tup_fetch.
Initially understanding was: idx_tup_read: matching records read from index.
idx_tup_fetch: live rows fetched from table after records are matched on index. So my understanding is that for index only scan since no data is fetched from table so this should not increment.
But when I ran the tests then this understanding is not true.
postgres=> select * from pg_stat_all_indexes where indexrelname like 'test_monika_rank';
relid | indexrelid | schemaname | relname | indexrelname | idx_scan | idx_tup_read | idx_tup_fetch
-------+------------+------------+-------------+------------------+----------+--------------+---------------
16413 | 16418 | public | test_monika | test_monika_rank | 4 | 2 | 2
(1 row)
postgres=> select * from test_monika where rank=100;
id | name | rank
----+------+------
95 | | 100
(1 row)
postgres=> select * from pg_stat_all_indexes where indexrelname like 'test_monika_rank';
relid | indexrelid | schemaname | relname | indexrelname | idx_scan | idx_tup_read | idx_tup_fetch
-------+------------+------------+-------------+------------------+----------+--------------+---------------
16413 | 16418 | public | test_monika | test_monika_rank | 5 | 3 | 3
(1 row)
postgres=> select rank from test_monika where rank=100;
rank
------
100
(1 row)
postgres=> select * from pg_stat_all_indexes where indexrelname like 'test_monika_rank';
relid | indexrelid | schemaname | relname | indexrelname | idx_scan | idx_tup_read | idx_tup_fetch
-------+------------+------------+-------------+------------------+----------+--------------+---------------
16413 | 16418 | public | test_monika | test_monika_rank | 6 | 4 | 4
(1 row)
postgres=> select id from test_monika where rank=100;
id
----
95
(1 row)
postgres=> select * from pg_stat_all_indexes where indexrelname like 'test_monika_rank';
relid | indexrelid | schemaname | relname | indexrelname | idx_scan | idx_tup_read | idx_tup_fetch
-------+------------+------------+-------------+------------------+----------+--------------+---------------
16413 | 16418 | public | test_monika | test_monika_rank | 7 | 5 | 5
(1 row)
postgres=> select 1 from test_monika where rank=100;
?column?
----------
1
(1 row)
postgres=> select * from pg_stat_all_indexes where indexrelname like 'test_monika_rank';
relid | indexrelid | schemaname | relname | indexrelname | idx_scan | idx_tup_read | idx_tup_fetch
-------+------------+------------+-------------+------------------+----------+--------------+---------------
16413 | 16418 | public | test_monika | test_monika_rank | 8 | 6 | 6
(1 row)