Sha256: fef88b9c6e9b1f3d60195e570841c419b4208a89c9a6956cec428cd8857d80f1

Contents?: true

Size: 1.62 KB

Versions: 13

Compression:

Stored size: 1.62 KB

Contents

module Shiba
  class Explain
    class MysqlExplain
      def transform_table(table, extra = {})
        t = table
        res = {}
        res['table'] = t['table_name']
        res['access_type'] = t['access_type']
        res['key'] = t['key']
        res['used_key_parts'] = t['used_key_parts'] if t['used_key_parts']
        res['rows'] = t['rows_examined_per_scan']
        res['filtered'] = t['filtered']

        if t['ref'] && t['ref'].any? { |r| r != "const" }
          res['join_ref'] = t['ref']
        end

        if t['possible_keys'] && t['possible_keys'] != [res['key']]
          res['possible_keys'] = t['possible_keys']
        end
        res['using_index'] = t['using_index'] if t['using_index']

        res.merge!(extra)

        res
      end

      def transform_json(json, res = [], extra = {})
        rows = []

        if (ordering = json['ordering_operation'])
          index_walk = (ordering['using_filesort'] == false)
          return transform_json(json['ordering_operation'], res, { "index_walk" => index_walk } )
        elsif json['duplicates_removal']
          return transform_json(json['duplicates_removal'], res, extra)
        elsif json['grouping_operation']
          return transform_json(json['grouping_operation'], res, extra)
        elsif !json['nested_loop'] && !json['table']
          return [{'Extra' => json['message']}]
        elsif json['nested_loop']
          json['nested_loop'].map do |nested|
            transform_json(nested, res, extra)
          end
        elsif json['table']
          res << transform_table(json['table'], extra)
        end
        res
      end
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
shiba-0.9.4 lib/shiba/explain/mysql_explain.rb
shiba-0.9.3 lib/shiba/explain/mysql_explain.rb
shiba-0.9.2 lib/shiba/explain/mysql_explain.rb
shiba-0.9.1 lib/shiba/explain/mysql_explain.rb
shiba-0.9.0 lib/shiba/explain/mysql_explain.rb
shiba-0.8.1 lib/shiba/explain/mysql_explain.rb
shiba-0.6.4 lib/shiba/explain/mysql_explain.rb
shiba-0.6.3 lib/shiba/explain/mysql_explain.rb
shiba-0.6.2 lib/shiba/explain/mysql_explain.rb
shiba-0.6.1 lib/shiba/explain/mysql_explain.rb
shiba-0.6.0 lib/shiba/explain/mysql_explain.rb
shiba-0.5.0 lib/shiba/explain/mysql_explain.rb
shiba-0.4.0 lib/shiba/explain/mysql_explain.rb