在pg11之后,引入了indnkeyatts字段,根据官方文档解释其作用:The number of key columns in the index, not counting any included columns, which are merely stored and do not participate in the index semantics

第一感觉,和indnatts字段差不多,但两者的说明存在差异。后者是参与索引的列的计数,前者是关键列的计数。

于是做了一个小测试,如下:

新建test表

CREATE TABLE test (
a _int8 NULL,
b _int8 NULL,
c _int8 NULL
);
CREATE INDEX test_a_idx ON test (a);
--单列索引
CREATE INDEX test_a_idx1 ON test (a,b);
--组合索引
CREATE INDEX test_a_idx2 ON test (a,b) include (c);
--使用inclue创建非键列
---查询各个索引的计数
SELECT
indnkeyatts,indnatts,i_c.relname
FROM
pg_index i
JOIN
pg_class c ON c.oid = i.indrelid
JOIN
pg_class i_c ON i_c.oid = i.indexrelid
JOIN
pg_am am ON am.oid = i_c.relam
LEFT JOIN
pg_attribute a ON a.attrelid = c.oid AND a.attnum = ANY(i.indkey)
JOIN
pg_namespace n ON n.oid = c.relnamespace
WHERE
c.relname = 'test'

结果如下

indnkeyatts indnatts relname
2 3 test_a_idx2
2 3 test_a_idx2
2 3 test_a_idx2
1 1 test_a_idx
2 2 test_a_idx1
2 2 test_a_idx1

感觉差异就在于对include字段的处理上。不知道还有其他情况,会影响计数的值,有了解的可以留言讨论下。

pg_index的更多相关文章

  1. PG CREATEINDEX CONCURRENTLY

    PG CREATEINDEX CONCURRENTLY [TOC] 官方说法 根据9.1的文档 Creating an index can interfere with regular operati ...

  2. Greenplum获取表结构

    最近在折腾greenplum,遇到一个蛋疼的问题,那就是获取表结构,也就是建表语句.大家都知道在MySQL里面是非常easy的,show create table table_name 就搞定了,在g ...

  3. 使用pgstatspack分析PostgreSQL数据库性能

    pgstatspack [root@test01 soft]# wget http://pgfoundry.org/frs/download.php/3151/pgstatspack_version_ ...

  4. PostgreSQL auto_explain

    The auto_explain module provides a means for logging execution plans of slow statements automaticall ...

  5. PG sys function

    The System Catalogs of PostgreSQLscott=# \dS List of relations Schema | Name | Type | Owner -------- ...

  6. PostgreSQL9.1 upgrade to PostgreSQL9.5rc1

    PostgreSQL9.1.0 upgrade to PostgreSQL9.5rc1 安装PG9.1端口为5432 [pgup@minion1 pg]$ ls postgresql-9.1.0.ta ...

  7. PostgreSQL 系统的基本体系结构

    PostgreSQL 使用客户机/服务器(C/S)的模式提供服务,一个PostgreSQL会话由下列相关的进程(程序)组成: (1)一个服务器端进程.该进程管理数据库文件,接受客户端与数据库的连接,且 ...

  8. PostgreSQL and bloat

    The bucardo project has released its nagios plugins for PostgreSQL and we can extract from them this ...

  9. Heap Only Tuples (HOT)

    Introduction ------------ The Heap Only Tuple (HOT) feature eliminates redundant index entries and a ...

  10. Understanding postgresql.conf : log*

    After loooong pause, adding next (well, second) post to the “series“. This time, I'd like to describ ...

随机推荐

  1. Maven 使用方法

    Maven Maven是一个项目管理工具,它包含了一个项目对象模型(POM:Project Object Model),其表现于一个XML文件(pom.xml),其中包含了项目的基本学习,依赖关系,插 ...

  2. Task 笔记

    1.计时器类Stopwatch Stopwatch stopwatch=new Stopwatch() stopwatch.Start();//开始计时 stopwatch.Stop();//停止计时 ...

  3. LeetCode 1000. Minimum Cost to Merge Stones (区间 DP)

    根据寒神题解 https://leetcode.com/problems/minimum-cost-to-merge-stones/discuss/247567/JavaC%2B%2BPython-D ...

  4. CPU缓存伪共享

    CPU缓存什么东西?当然这个问题很多人有可能觉得比较傻,CPU缓存什么,肯定是缓存数据(代码)啊,要不然还能缓存啥,这个确实没问题,但是CPU到底缓存什么样的数据呢?因为对CPU来说,无论是指令,还是 ...

  5. yarn serve 不能开启vue项目 the project seem to require yarn but isnot install

    error: answer: 删除 yarn.lock 或者使用 npm run serve 替换 ; ps: yarn.lock 是锁定第三方包版本的文件:

  6. CSharp的Where底层实现

    using System; using System.Collections.Generic; using System.Linq; using System.Net.Http; using Syst ...

  7. 08 ELMo模型(双向LSTM模型解决词向量多义问题)

    博客配套视频链接: https://space.bilibili.com/383551518?spm_id_from=333.1007.0.0 b 站直接看 配套 github 链接:https:// ...

  8. python 打包 py 文件 为exe

    使用 pyinstaller 来进行打包 pip install pyinstaller 可能需要全局 科学 代理上网 或者 修改 下载源地址 执行命令 图标path:C:\desktop\icon ...

  9. Module Warning (from ./node_modules/postcss-loader/dist/cjs.js): Warning

    .markdown-body { line-height: 1.75; font-weight: 400; font-size: 16px; overflow-x: hidden; color: rg ...

  10. MP4 转 TXT 项目与 M3U8 下载脚本

    项目背景 在当今信息社会,视频学习已成为一种重要的知识获取方式.然而,许多用户在观看视频的过程中,效率往往低于预期.为了提升学习效率,我们决定开发一个将 MP4 视频转换为 TXT 文稿的项目.此外, ...