Class: NoSE::IndexEnumerator
Overview
Produces potential indices to be used in schemas
Instance Method Summary collapse
-
#indexes_for_query(query) ⇒ Array<Index>
Produce all possible indices for a given query.
-
#indexes_for_workload(additional_indexes = [], by_id_graph = false) ⇒ Set<Index>
Produce all possible indices for a given workload.
-
#initialize(workload) ⇒ IndexEnumerator
constructor
A new instance of IndexEnumerator.
Constructor Details
#initialize(workload) ⇒ IndexEnumerator
Returns a new instance of IndexEnumerator.
8 9 10 11 12 |
# File 'lib/nose/enumerator.rb', line 8 def initialize(workload) @logger = Logging.logger['nose::enumerator'] @workload = workload end |
Instance Method Details
#indexes_for_query(query) ⇒ Array<Index>
Produce all possible indices for a given query
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/nose/enumerator.rb', line 16 def indexes_for_query(query) @logger.debug "Enumerating indexes for query #{query.text}" range = if query.range_field.nil? query.order else [query.range_field] + query.order end eq = query.eq_fields.group_by(&:parent) eq.default_proc = ->(*) { [] } range = range.group_by(&:parent) range.default_proc = ->(*) { [] } query.graph.subgraphs.flat_map do |graph| indexes_for_graph graph, query.select, eq, range end.uniq << query.materialize_view end |
#indexes_for_workload(additional_indexes = [], by_id_graph = false) ⇒ Set<Index>
Produce all possible indices for a given workload
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/nose/enumerator.rb', line 38 def indexes_for_workload(additional_indexes = [], by_id_graph = false) queries = @workload.queries indexes = Parallel.map(queries) do |query| indexes_for_query(query).to_a end.inject(additional_indexes, &:+) # Add indexes generated for support queries supporting = support_indexes indexes, by_id_graph supporting += support_indexes supporting, by_id_graph indexes += supporting # Deduplicate indexes, combine them and deduplicate again indexes.uniq! combine_indexes indexes indexes.uniq! @logger.debug do "Indexes for workload:\n" + indexes.map.with_index do |index, i| "#{i} #{index.inspect}" end.join("\n") end indexes end |