Class: RubyPgExtras::IndexInfo

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby_pg_extras/index_info.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.call(table_name = nil) ⇒ Object



3
4
5
# File 'lib/ruby_pg_extras/index_info.rb', line 3

def self.call(table_name = nil)
  new.call(table_name)
end

Instance Method Details

#call(table_name = nil) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/ruby_pg_extras/index_info.rb', line 7

def call(table_name = nil)
  indexes_data.select do |index_data|
    if table_name == nil
      true
    else
      index_data.fetch("tablename") == table_name
    end
  end.sort_by do |index_data|
    index_data.fetch("tablename")
  end.map do |index_data|
    index_name = index_data.fetch("indexname")

    {
      index_name: index_name,
      table_name: index_data.fetch("tablename"),
      columns: index_data.fetch("columns").split(',').map(&:strip),
      index_size: index_size_data.find do |el|
        el.fetch("name") == index_name
      end.fetch("size", "N/A"),
      index_scans:  index_scans_data.find do |el|
        el.fetch("index") == index_name
      end.fetch("index_scans", "N/A"),
      null_frac: null_indexes_data.find do |el|
        el.fetch("index") == index_name
      end&.fetch("null_frac", "N/A")&.strip || "0.00%"
    }
  end
end

#index_scans_dataObject



47
48
49
# File 'lib/ruby_pg_extras/index_info.rb', line 47

def index_scans_data
  @_index_scans_data ||= query_module.index_scans(in_format: :hash)
end

#index_size_dataObject



36
37
38
# File 'lib/ruby_pg_extras/index_info.rb', line 36

def index_size_data
  @_index_size_data ||= query_module.index_size(in_format: :hash)
end

#indexes_dataObject



51
52
53
# File 'lib/ruby_pg_extras/index_info.rb', line 51

def indexes_data
  @_indexes_data ||= query_module.indexes(in_format: :hash)
end

#null_indexes_dataObject



40
41
42
43
44
45
# File 'lib/ruby_pg_extras/index_info.rb', line 40

def null_indexes_data
  @_null_indexes_data ||= query_module.null_indexes(
    in_format: :hash,
    args: { min_relation_size_mb: 0 }
  )
end