Postgres 上 idx_tup_read 和 idx_tup_fetch 的区别

Sim*_*mon 13 postgresql index-statistics

在 Postgres 8.4 上执行以下操作时:

select * from pg_stat_all_indexes where relname = 'table_name';
Run Code Online (Sandbox Code Playgroud)

它返回字段 idx_tup_read 和 idx_tup_fetch,有什么区别?

a_h*_*ame 14

在查看视图的源代码时,您会看到这idx_tup_read是调用的结果,pg_stat_get_tuples_returned()并且idx_tup_fetch是调用的结果pg_stat_get_tuples_fetched()

手册中对这两个功能的描述如下:

pg_stat_get_tuples_returned(oid)

参数为表时顺序扫描读取的行数,或参数为索引时返回的索引条目数

pg_stat_get_tuples_fetched(oid)

当参数是表时位图扫描获取的表行数,或者当参数是索引时使用索引通过简单索引扫描获取的表行数


Dev*_*evi 5

来自postgresql 文档

idx_tup_read is number of index entries returned by scans on this index
idx_tup_fetch is number of live table rows fetched by simple index scans using this index
Run Code Online (Sandbox Code Playgroud)

因此,reads 是指索引返回所需行的位置,fetches 是指索引返回表行本身。