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, total_time: nil, calls: nil) ⇒ Query

Returns a new instance of Query.



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

def initialize(statement, fingerprint = nil, total_time: nil, calls: nil)
  @statement = statement
  @fingerprint = fingerprint
  @total_time = total_time
  @calls = calls
  @plans = []
  @tables_from_views = []
  @candidate_tables = []
  @columns = []
  @candidate_columns = []
end

Instance Attribute Details

#callsObject (readonly)

Returns the value of attribute calls.



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

def calls
  @calls
end

#candidate_columnsObject

Returns the value of attribute candidate_columns.



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

def candidate_columns
  @candidate_columns
end

#candidate_tablesObject

Returns the value of attribute candidate_tables.



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

def candidate_tables
  @candidate_tables
end

#columnsObject

Returns the value of attribute columns.



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

def columns
  @columns
end

#fingerprintObject (readonly)

Returns the value of attribute fingerprint.



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

def fingerprint
  @fingerprint
end

#index_mappingObject

Returns the value of attribute index_mapping.



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

def index_mapping
  @index_mapping
end

#indexesObject

Returns the value of attribute indexes.



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

def indexes
  @indexes
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

#pass1_indexesObject

Returns the value of attribute pass1_indexes.



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

def pass1_indexes
  @pass1_indexes
end

#pass2_indexesObject

Returns the value of attribute pass2_indexes.



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

def pass2_indexes
  @pass2_indexes
end

#pass3_indexesObject

Returns the value of attribute pass3_indexes.



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

def pass3_indexes
  @pass3_indexes
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

#suggest_indexObject

Returns the value of attribute suggest_index.



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

def suggest_index
  @suggest_index
end

#tablesObject

Returns the value of attribute tables.



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

def tables
  @tables
end

#tables_from_viewsObject

Returns the value of attribute tables_from_views.



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

def tables_from_views
  @tables_from_views
end

#total_timeObject (readonly)

Returns the value of attribute total_time.



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

def total_time
  @total_time
end

Instance Method Details

#costsObject



33
34
35
# File 'lib/dexter/query.rb', line 33

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

#fully_analyzed?Boolean

Returns:

  • (Boolean)


29
30
31
# File 'lib/dexter/query.rb', line 29

def fully_analyzed?
  plans.size >= 3
end

#initial_costObject



37
38
39
# File 'lib/dexter/query.rb', line 37

def initial_cost
  costs[0]
end

#parser_resultObject



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

def parser_result
  unless defined?(@parser_result)
    @parser_result = PgQuery.parse(statement) rescue nil
  end
  @parser_result
end

#treeObject



25
26
27
# File 'lib/dexter/query.rb', line 25

def tree
  parser_result.tree
end