Class: Dexter::Query

Inherits:
Object
  • Object
show all
Defined in:
lib/dexter/query.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(statement, fingerprint = nil) ⇒ Query



6
7
8
9
10
11
12
13
# File 'lib/dexter/query.rb', line 6

def initialize(statement, fingerprint = nil)
  @statement = statement
  unless fingerprint
    fingerprint = PgQuery.fingerprint(statement) rescue "unknown"
  end
  @fingerprint = fingerprint
  @plans = []
end

Instance Attribute Details

#fingerprintObject (readonly)

Returns the value of attribute fingerprint.



3
4
5
# File 'lib/dexter/query.rb', line 3

def fingerprint
  @fingerprint
end

#missing_tablesObject

Returns the value of attribute missing_tables.



4
5
6
# File 'lib/dexter/query.rb', line 4

def missing_tables
  @missing_tables
end

#new_costObject

Returns the value of attribute new_cost.



4
5
6
# File 'lib/dexter/query.rb', line 4

def new_cost
  @new_cost
end

#plansObject (readonly)

Returns the value of attribute plans.



3
4
5
# File 'lib/dexter/query.rb', line 3

def plans
  @plans
end

#statementObject (readonly)

Returns the value of attribute statement.



3
4
5
# File 'lib/dexter/query.rb', line 3

def statement
  @statement
end

Instance Method Details

#costsObject



27
28
29
# File 'lib/dexter/query.rb', line 27

def costs
  plans.map { |plan| plan["Total Cost"] }
end

#explainable?Boolean



23
24
25
# File 'lib/dexter/query.rb', line 23

def explainable?
  plans.any?
end

#high_cost?Boolean



35
36
37
# File 'lib/dexter/query.rb', line 35

def high_cost?
  initial_cost && initial_cost >= 100
end

#initial_costObject



31
32
33
# File 'lib/dexter/query.rb', line 31

def initial_cost
  costs[0]
end

#tablesObject



15
16
17
# File 'lib/dexter/query.rb', line 15

def tables
  @tables ||= parse ? parse.tables : []
end

#treeObject



19
20
21
# File 'lib/dexter/query.rb', line 19

def tree
  parse.tree
end