首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >idx_tup_read中的差异和postgres中的idx_tup_fetch

idx_tup_read中的差异和postgres中的idx_tup_fetch
EN

Database Administration用户
提问于 2021-01-04 00:23:17
回答 1查看 350关注 0票数 1

我已经看过文档和以前的堆叠溢出问题,但没有发现那些有用的问题。Postgres版本10.6

即使是索引,仅扫描idx_tup_fetch的值也在增加。因此,我无法理解idx_tup_read和idx_tup_fetch之间的区别。

最初的理解是: idx_tup_read:从索引读取的匹配记录。

idx_tup_fetch:在索引上匹配记录之后从表中获取的活行。因此,我的理解是,对于索引,只扫描,因为没有从表中获取数据,所以这不应该增加。

但是当我运行测试时,这种理解就不正确了。

代码语言:javascript
复制
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)
EN

回答 1

Database Administration用户

回答已采纳

发布于 2021-01-07 08:50:26

每当读取索引项时,idx_tup_read就会增加。

每当索引扫描获取表条目时,idx_tup_fetch都会增加。

如果您的仅索引扫描增加idx_tup_fetch,它并不是真正的索引-只。无论如何,PostgreSQL必须获取表行,以检查它们是否可见,这是一个没有存储在索引中的信息。

您可以在EXPLAIN (ANALYZE)输出中看到“获取的堆元组”。

解决方案是对表进行VACUUM,以便更新可见性映射。

票数 1
EN
页面原文内容由Database Administration提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://dba.stackexchange.com/questions/282506

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档