postgresql 查看索引是否有效及索引使用情况
查看索引是否有效
1.未使用索引前
jinbo=# explain analyze select * from jinbo.student where score < 80 and score < 90 and sex = 1;QUERY PLAN
----------------------------------------------------------------------------------------------------Seq Scan on student (cost=0.00..220.45 rows=4 width=23) (actual time=0.030..2.195 rows=1 loops=1)Filter: ((score < 80) AND (score < 90) AND (sex = 1))Rows Removed by Filter: 11453Planning time: 0.119 msExecution time: 2.217 ms
(5 rows)
使用索引后
jinbo=# create index on jinbo.student(score, sex);
CREATE INDEX
jinbo=# explain analyze select * from jinbo.student where score < 80 and score < 90 and sex = 1;QUERY PLAN
------------------------------------------------------------------------------------------------------------------------------Bitmap Heap Scan on student (cost=4.40..10.54 rows=2 width=23) (actual time=0.063..0.064 rows=1 loops=1)Recheck Cond: ((score < 80) AND (score < 90) AND (sex = 1))Heap Blocks: exact=1-> Bitmap Index Scan on student_score_sex_idx (cost=0.00..4.40 rows=2 width=0) (actual time=0.058..0.058 rows=1 loops=1)Index Cond: ((score < 80) AND (score < 90) AND (sex = 1))Planning time: 0.398 msExecution time: 0.093 ms
(7 rows)
查看索引使用情况
查看索引使用的统计情况的表:
pg_stat_user_indexes
jinbo=# \d+ pg_stat_user_indexes;View "pg_catalog.pg_stat_user_indexes"Column | Type | Collation | Nullable | Default | Storage | Description
---------------+--------+-----------+----------+---------+---------+-------------relid | oid | | | | plain | indexrelid | oid | | | | plain | schemaname | name | | | | plain | relname | name | | | | plain | indexrelname | name | | | | plain | idx_scan | bigint | | | | plain | idx_tup_read | bigint | | | | plain | idx_tup_fetch | bigint | | | | plain |
View definition:SELECT pg_stat_all_indexes.relid,pg_stat_all_indexes.indexrelid,pg_stat_all_indexes.schemaname,pg_stat_all_indexes.relname,pg_stat_all_indexes.indexrelname,pg_stat_all_indexes.idx_scan,pg_stat_all_indexes.idx_tup_read,pg_stat_all_indexes.idx_tup_fetchFROM pg_stat_all_indexesWHERE (pg_stat_all_indexes.schemaname <> ALL (ARRAY['pg_catalog'::name, 'information_schema'::name])) AND pg_stat_all_indexes.schemaname !~ '^pg_toast'::text;
pg_stat_all_indexes
jinbo=# \d+ pg_stat_all_indexes View "pg_catalog.pg_stat_all_indexes"Column | Type | Collation | Nullable | Default | Storage | Description
---------------+--------+-----------+----------+---------+---------+-------------relid | oid | | | | plain | indexrelid | oid | | | | plain | schemaname | name | | | | plain | relname | name | | | | plain | indexrelname | name | | | | plain | idx_scan | bigint | | | | plain | idx_tup_read | bigint | | | | plain | idx_tup_fetch | bigint | | | | plain |
View definition:SELECT c.oid AS relid,i.oid AS indexrelid,n.nspname AS schemaname,c.relname,i.relname AS indexrelname,pg_stat_get_numscans(i.oid) AS idx_scan,pg_stat_get_tuples_returned(i.oid) AS idx_tup_read,pg_stat_get_tuples_fetched(i.oid) AS idx_tup_fetchFROM pg_class cJOIN pg_index x ON c.oid = x.indrelidJOIN pg_class i ON i.oid = x.indexrelidLEFT JOIN pg_namespace n ON n.oid = c.relnamespaceWHERE c.relkind = ANY (ARRAY['r'::"char", 't'::"char", 'm'::"char"]);
查看使用记录
jinbo=# select * from pg_stat_all_indexes where schemaname = 'jinbo' and relname = 'student';relid | indexrelid | schemaname | relname | indexrelname | idx_scan | idx_tup_read | idx_tup_fetch --------+------------+------------+---------+-----------------------+----------+--------------+---------------111451 | 228633 | jinbo | student | student_score_sex_idx | 3 | 3 | 2//---------------------------------------------------分割线---------------------------------------------jinbo=# select * from pg_stat_user_indexes where schemaname = 'jinbo' and relname = 'student';relid | indexrelid | schemaname | relname | indexrelname | idx_scan | idx_tup_read | idx_tup_fetch
--------+------------+------------+---------+-----------------------+----------+--------------+---------------111451 | 228633 | jinbo | student | student_score_sex_idx | 3 | 3 | 2
(1 row)
postgresql 查看索引是否有效及索引使用情况相关推荐
- postgresql 查看数据库,表,索引,表空间以及大小
为什么80%的码农都做不了架构师?>>> postgresql 查看数据库,表,索引,表空间以及大小 1.查看数据库 #psql -U postgres //\加上字母l,相当 ...
- PostgreSQL 查看数据库,索引,表,表空间大小
转载来源 :PostgreSQL 查看数据库,索引,表,表空间大小 : https://www.cnblogs.com/mchina/archive/2013/04/19/3028573.html 一 ...
- Postgresql杂谈 04—Postgresql中的五种常规索引
一.索引的分类 Postgresql中索引一共分为5种,每一种都有它合适的应用场景,我们在使用时要根据不同业务的特点,选择合适的索引,这样才能加快sql语句的查询效率.下面,我们将就每种不同的索引,介 ...
- postgresql索引_PostgreSQL中的索引— 6(SP-GiST)
postgresql索引 indexing engine, 索引引擎 , the interface of access methods, and three methods: 访问方法的接口以及三种 ...
- PostgreSQL pg_qualstats 解决索引缺失,添加索引
商业数据库中,很多新版本都可以自动创建索引,给出索引创建的建议,并且以此作为卖点,ORACLE ,SQL SERVER 均有类似的功能,实际上通过查询语句,与全表扫描的语句,与谓词的比对,做出这样的系 ...
- Postgresql杂谈 11—深入学习SP-Gist索引
本文,我们深入学习下Posgresql中的SP-Gist索引.SP-Gist是Space-Partition Gist(空间分区Gist索引)的简写.和Gist索引一样,它也是一个索引框架,但是相比较 ...
- MySQL查看、创建和删除索引的方法
本文实例讲述了MySQL查看.创建和删除索引的方法.分享给大家供大家参考.具体如下: 1.索引作用 在索引列上,除了上面提到的有序查找之外,数据库利用各种各样的快速定位技术,能够大大提高查询效率.特别 ...
- is NULL , is NOT NULL 有时索引失效 || in 走索引, not in 索引失效 ||单列索引和复合索引 || 查看索引使用情况
is NULL , is NOT NULL 有时索引失效 in 走索引, not in 索引失效 单列索引和复合索引 尽量使用复合索引,而少使用单列索引 数据库会选择一个最优的索引(辨识度最高索引)来 ...
- 查看oracle索引状态,oracle监控索引的使用情况
1.使用monitor index来监控索引使用 监控单个索引使用情况:alter index monitoring usage; 关闭监控: alter index nomonitoring usa ...
- mysql中索引创建 查看和删除语句_MySQL索引的创建、删除和查看(学习中)
1.索引作用 在索引列上,除了上面提到的有序查找之外,数据库利用各种各样的快速定位技术,能够大大提高查询效率.特别是当数据量非常大,查询涉及多个表时,使用索引往往能使查询速度加快成千上万倍. 例如,有 ...
最新文章
- 能量平衡_500kA 铝电解槽的能量平衡分析
- SAP Forecasting and Replenishment for Retail – A short Overview【中英文双语版】
- python基础代码库-python3.4第三方库的安装?python基础代码库
- Android 代码优化工具FindBugs
- 五、开始学习Excel函数,效率快速提高
- linux 查看系统进程命令
- 运行VINS-mono:/home/tony-ws1/output/pose_graph/ not exists, trying to create it /home/tony-ws1/ou错误解决
- 谷歌修复十多个安卓高危漏洞
- jquery上传图片_MVC 上传图片,裁剪头像
- Android的JNI【实战教程】2⃣️--AS下NDK环境配置及第一个工程
- stm32实现红外自发自收
- ppt加html链接,ppt制作中如何添加超链接(完整版).doc
- 程序设计思维与实践 Week7 作业 A TT的魔法猫
- java计算机毕业设计交通规则考试系统源码+mysql数据库+系统+lw文档+部署
- Ubuntu下启动图形界面startx报错connection to X server lost
- 华为智慧屏鸿蒙20,华为智慧屏SE系列首销 搭载鸿蒙分布式跨屏技术
- adb命令——adb命令大全
- c语言中 指针的研究,C语言中指针的研究与总结
- 【QT-QSS】QSS介绍
- 3.6Python之sys模块
热门文章
- MATLAB 绘图合集:等高线图contour
- 《会计学》简单的思维导图(第一版)
- 职业教育计算机教学,浅析职业教育中的计算机教学思考.doc
- 皮带撕裂检测matlab,基于机器视觉的皮带纵向撕裂检测方法
- 代沐研:渡尽劫波非农在,空头有望脱苦海
- C# 添加PDF页眉/页脚
- 完全数据驱动的对话模型和社交机器人
- 穿山甲android对接错误码40029,空Android项目集成Cocos、穿山甲。Lua调用网络接口。...
- pytho中的json序列化与反序列化操作
- 报错:For input string