ruby-pg-extras 1.4.0 → 1.5.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 943bbbbd7e2de25570164a5bbd5e6015708ca2f808e7f0b25523a4125ad1bbf0
4
- data.tar.gz: dd4e28f9900f2b50eae39232828c47ebb7c6b57dbb9ca4042be074cda1214e75
3
+ metadata.gz: 741b8ec49ba2e7b4933ddbe085bd3c4f90ab1640e951fdec1dfa1178c4bf8ab0
4
+ data.tar.gz: d1b7d405ef8da4bcd450e461a6ff4411b760128bd22e660c1dc102aaa1cf9453
5
5
  SHA512:
6
- metadata.gz: 12dd59913848f989fe6c186fefcdeb6418ab41cd6082b65f072b48d7d961e5d43b5c41822f8527bfda64e4557d284d52e74c0c3bd6dc1ca722fc958fa77d6b2a
7
- data.tar.gz: 6c2d5445c0acb5eb93f614f778464c1059807112ca310efac9f135ca025985783ee553b7dca99e269d932a7d447c736011b54e791897e7e8671832492ee87add
6
+ metadata.gz: ce5011d3e926a7b1a246b6268d7d58a8f05f26bbab22bd665209daec81f4d03867b78c8306f6d3ebd4661acc1ae96640427ea33486d3ab6f91b1716c20b11cc1
7
+ data.tar.gz: 1cee23d5f7e171bdd13eeea76102a59ff1ad6774a9b1c80b614e76e9d4a60d4b76b098403fd69e7e5913c001d98e0b4792fc1f58762234d0b10af7cbd6a1ef6e
data/README.md CHANGED
@@ -351,6 +351,22 @@ RubyPGExtras.unused_indexes(args: { min_scans: 20 })
351
351
 
352
352
  This command displays indexes that have < 50 scans recorded against them, and are greater than 5 pages in size, ordered by size relative to the number of index scans. This command is generally useful for eliminating indexes that are unused, which can impact write performance, as well as read performance should they occupy space in memory.
353
353
 
354
+ ### `null_indexes`
355
+
356
+ ```ruby
357
+
358
+ RubyPGExtras.null_indexes
359
+
360
+ oid | index | index_size | unique | indexed_column | null_frac | expected_saving
361
+ ---------+--------------------+------------+--------+----------------+-----------+-----------------
362
+ 183764 | users_reset_token | 1418 MB | t | reset_token | 96.15% | 1363 MB
363
+ 88732 | plan_cancelled_at | 1651 MB | f | cancelled_at | 6.11% | 101 MB
364
+ 9827345 | users_email | 22 MB | t | email | 11.21% | 2494 kB
365
+
366
+ ```
367
+
368
+ This commands displays indexes that contain `NULL` values. A high ratio of `NULL` values means that using a partial index excluding them will be beneficial in case they are not used for searching. [Source and more info](https://hakibenita.com/postgresql-unused-index-size).
369
+
354
370
  ### `seq_scans`
355
371
 
356
372
  ```ruby
@@ -10,7 +10,7 @@ module RubyPGExtras
10
10
  QUERIES = %i(
11
11
  bloat blocking cache_hit
12
12
  calls extensions table_cache_hit index_cache_hit
13
- index_size index_usage locks all_locks
13
+ index_size index_usage null_indexes locks all_locks
14
14
  long_running_queries mandelbrot outliers
15
15
  records_rank seq_scans table_indexes_size
16
16
  table_size total_index_size total_table_size
@@ -0,0 +1,32 @@
1
+ /* Find indexed columns with high null_frac */
2
+ SELECT
3
+ c.oid,
4
+ c.relname AS index,
5
+ pg_size_pretty(pg_relation_size(c.oid)) AS index_size,
6
+ i.indisunique AS unique,
7
+ a.attname AS indexed_column,
8
+ CASE s.null_frac
9
+ WHEN 0 THEN ''
10
+ ELSE to_char(s.null_frac * 100, '999.00%')
11
+ END AS null_frac,
12
+ pg_size_pretty((pg_relation_size(c.oid) * s.null_frac)::bigint) AS expected_saving
13
+ FROM
14
+ pg_class c
15
+ JOIN pg_index i ON i.indexrelid = c.oid
16
+ JOIN pg_attribute a ON a.attrelid = c.oid
17
+ JOIN pg_class c_table ON c_table.oid = i.indrelid
18
+ JOIN pg_indexes ixs ON c.relname = ixs.indexname
19
+ LEFT JOIN pg_stats s ON s.tablename = c_table.relname AND a.attname = s.attname
20
+ WHERE
21
+ -- Primary key cannot be partial
22
+ NOT i.indisprimary
23
+ -- Exclude already partial indexes
24
+ AND i.indpred IS NULL
25
+ -- Exclude composite indexes
26
+ AND array_length(i.indkey, 1) = 1
27
+ -- Exclude indexes without null_frac ratio
28
+ AND coalesce(s.null_frac, 0) != 0
29
+ -- Larger than 10MB
30
+ AND pg_relation_size(c.oid) > 10 * 1024 ^ 2
31
+ ORDER BY
32
+ pg_relation_size(c.oid) * s.null_frac DESC;
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RubyPGExtras
4
- VERSION = "1.4.0"
4
+ VERSION = "1.5.0"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-pg-extras
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.0
4
+ version: 1.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - pawurb
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-01-26 00:00:00.000000000 Z
11
+ date: 2021-02-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: pg
@@ -96,6 +96,7 @@ files:
96
96
  - lib/ruby-pg-extras/queries/locks.sql
97
97
  - lib/ruby-pg-extras/queries/long_running_queries.sql
98
98
  - lib/ruby-pg-extras/queries/mandelbrot.sql
99
+ - lib/ruby-pg-extras/queries/null_indexes.sql
99
100
  - lib/ruby-pg-extras/queries/outliers.sql
100
101
  - lib/ruby-pg-extras/queries/records_rank.sql
101
102
  - lib/ruby-pg-extras/queries/seq_scans.sql