Class: Exwiw::ExplainRunner
- Inherits:
-
Object
- Object
- Exwiw::ExplainRunner
- Defined in:
- lib/exwiw/explain_runner.rb
Instance Method Summary collapse
-
#initialize(connection_config:, config_dir:, dump_target:, logger:, io: $stdout) ⇒ ExplainRunner
constructor
A new instance of ExplainRunner.
- #run ⇒ Object
Constructor Details
#initialize(connection_config:, config_dir:, dump_target:, logger:, io: $stdout) ⇒ ExplainRunner
Returns a new instance of ExplainRunner.
5 6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/exwiw/explain_runner.rb', line 5 def initialize( connection_config:, config_dir:, dump_target:, logger:, io: $stdout ) @connection_config = connection_config @config_dir = config_dir @dump_target = dump_target @logger = logger @io = io end |
Instance Method Details
#run ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/exwiw/explain_runner.rb', line 19 def run adapter = Adapter.build(@connection_config, @logger) configs = load_table_config(adapter.class.table_config_class) configs = reject_and_validate_skipped(configs) table_by_name = configs.each_with_object({}) { |config, hash| hash[config.name] = config } target = table_by_name[@dump_target.table_name] adapter.validate_as_dump_target!(target) if target @logger.debug("Determining table processing order...") ordered_table_names = DetermineTableProcessingOrder.run(configs.select { |c| adapter.dumpable?(c) }) total_size = ordered_table_names.size ordered_table_names.each_with_index do |table_name, idx| @logger.debug("Explaining '#{table_name}'... (#{idx + 1}/#{total_size})") table = table_by_name.fetch(table_name) query_ast = adapter.build_query(table, @dump_target, table_by_name) sql = adapter.compile_ast(query_ast) explain_text = adapter.explain(query_ast) @io.puts "-- [#{idx + 1}/#{total_size}] #{table_name}" @io.puts sql @io.puts @io.puts "-- EXPLAIN:" @io.puts explain_text @io.puts end end |