class Dexter::Query

Attributes

calls[RW]
candidate_tables[RW]
fingerprint[R]
indexes[RW]
missing_tables[RW]
new_cost[RW]
pass1_indexes[RW]
pass2_indexes[RW]
pass3_indexes[RW]
plans[R]
statement[R]
suggest_index[RW]
tables[W]
tables_from_views[RW]
total_time[RW]

Public Class Methods

new(statement, fingerprint = nil) click to toggle source
# File lib/dexter/query.rb, line 7
def initialize(statement, fingerprint = nil)
  @statement = statement
  unless fingerprint
    fingerprint = PgQuery.fingerprint(statement) rescue "unknown"
  end
  @fingerprint = fingerprint
  @plans = []
  @tables_from_views = []
end

Public Instance Methods

costs() click to toggle source
# File lib/dexter/query.rb, line 37
def costs
  plans.map { |plan| plan["Total Cost"] }
end
explainable?() click to toggle source
# File lib/dexter/query.rb, line 33
def explainable?
  plans.any?
end
high_cost?() click to toggle source
# File lib/dexter/query.rb, line 45
def high_cost?
  initial_cost && initial_cost >= 100
end
initial_cost() click to toggle source
# File lib/dexter/query.rb, line 41
def initial_cost
  costs[0]
end
tables() click to toggle source
# File lib/dexter/query.rb, line 17
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
tree() click to toggle source
# File lib/dexter/query.rb, line 29
def tree
  parse.tree
end

Private Instance Methods

parse() click to toggle source
# File lib/dexter/query.rb, line 51
def parse
  unless defined?(@parse)
    @parse = PgQuery.parse(statement) rescue nil
  end
  @parse
end