查 Postgres 的 index 使用情况
source link: https://blog.niclin.tw/2018/06/09/%E6%9F%A5-postgres-%E7%9A%84-index-%E4%BD%BF%E7%94%A8%E6%83%85%E5%86%B5/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Nic Lin's Blog
喜歡在地上滾的工程師
一般來說,打了 index 都會想看成效,使用的情況如何,在 postgreSQL 內可以直接下這行指令
SELECT * FROM pg_stat_user_indexes;
就可以拿到完整的資料去分析每個 index 的使用情況。
SELECT * FROM pg_stat_user_indexes;
relid | indexrelid | schemaname | relname | indexrelname | idx_scan | idx_tup_read | idx_tup_fetch
-------+------------+------------+------------+-------------------------+----------+--------------+---------------
16454 | 16491 | public | categories | categories_pkey | 0 | 0 | 0
16463 | 16493 | public | customers | customers_pkey | 0 | 0 | 0
16470 | 16495 | public | inventory | inventory_pkey | 0 | 0 | 0
16478 | 16497 | public | orders | orders_pkey | 0 | 0 | 0
16484 | 16499 | public | products | products_pkey | 0 | 0 | 0
16458 | 16501 | public | cust_hist | ix_cust_hist_customerid | 0 | 0 | 0
16463 | 16502 | public | customers | ix_cust_username | 0 | 0 | 0
16478 | 16503 | public | orders | ix_order_custid | 0 | 0 | 0
16473 | 16504 | public | orderlines | ix_orderlines_orderid | 0 | 0 | 0
16484 | 16505 | public | products | ix_prod_category | 0 | 0 | 0
16484 | 16506 | public | products | ix_prod_special | 0 | 0 | 0
(11 rows)
值得注意的是,有些數據為 0 並不代表真的沒用到,因為
- unique 也是一種 index
- primary key 也是一種 index
Recommend
-
12
The first thing we need to do is to create a lot of fake data so we can test our indexex, it's also important to use real words dependending on the index that you're trying to use, there's a clever way of doing this on linux, if you're...
-
13
Why isn’t Postgres using my index? — pgMustardCover photo: Emily MorterIf you spend any amount...
-
4
rails Published on 21 December 2021...
-
7
How Postgres Chooses Which Index To Use For A QueryBy Lukas FittlApril 01, 2022
-
6
最近在分析影響效能的 Query,發現 PostgreSQL 有時的查詢效能不如我們預期,用了 EXPLAIN 下去分析索引,發現確實新增的 index 並沒有在 query plain 裡面,我想瞭解為什麼。評估結果是 seq scan 更快在數據量很小的時候, seq scan 會比 inde...
-
3
使用 HammerDB 对 Citus 和 Postgres 进行 Benchmark,每分钟200万新订单处理测试(官方博客) ...
-
7
Index Merges vs Composite Indexes in Postgres and MySQLNov 2022Composite indexes are about 10x faster than index merges. In Postgres, the gap is larger than in MySQL because Postgres doesn't s...
-
4
Postgres 中使用 Zhparser 插件进行中文全文检索 兰玉磊 • 2天前 • Linux • 阅读 123
-
5
ChatGPT API使用案例:通过pgvector在Postgres中存储OpenAI嵌入 解道Jdon ...
-
6
10个Postgres使用高级技巧 PostgreSQL不仅仅是另一个数据库,它是一个包含可以改变您处理数据方式的功能的系统。1、元组...
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK