Sha256: b1d16ed26e0352080b999429222a1e700d552be853eb73db5159c83d3fca7c72
Contents?: true
Size: 1.3 KB
Versions: 3
Compression:
Stored size: 1.3 KB
Contents
module Dexter class Query attr_reader :statement, :fingerprint, :plans attr_writer :tables attr_accessor :missing_tables, :new_cost, :total_time, :calls, :indexes, :suggest_index, :pass1_indexes, :pass2_indexes, :pass3_indexes, :candidate_tables, :tables_from_views, :candidates def initialize(statement, fingerprint = nil) @statement = statement unless fingerprint fingerprint = PgQuery.fingerprint(statement) rescue "unknown" end @fingerprint = fingerprint @plans = [] @tables_from_views = [] end def tables @tables ||= begin parse ? parse.tables : [] rescue => e # possible pg_query bug $stderr.puts "Error extracting tables. Please report to https://github.com/ankane/dexter/issues" $stderr.puts "#{e.class.name}: #{e.message}" $stderr.puts statement [] end end def tree parse.tree end def explainable? plans.size >= 3 end def costs plans.map { |plan| plan["Total Cost"] } end def initial_cost costs[0] end def high_cost? initial_cost && initial_cost >= 100 end private def parse unless defined?(@parse) @parse = PgQuery.parse(statement) rescue nil end @parse end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
pgdexter-0.5.5 | lib/dexter/query.rb |
pgdexter-0.5.4 | lib/dexter/query.rb |
pgdexter-0.5.3 | lib/dexter/query.rb |