Class: Dexter::Query
- Inherits:
-
Object
- Object
- Dexter::Query
- Defined in:
- lib/dexter/query.rb
Instance Attribute Summary collapse
-
#calls ⇒ Object
Returns the value of attribute calls.
-
#candidate_tables ⇒ Object
Returns the value of attribute candidate_tables.
-
#candidates ⇒ Object
Returns the value of attribute candidates.
-
#fingerprint ⇒ Object
readonly
Returns the value of attribute fingerprint.
-
#indexes ⇒ Object
Returns the value of attribute indexes.
-
#missing_tables ⇒ Object
Returns the value of attribute missing_tables.
-
#new_cost ⇒ Object
Returns the value of attribute new_cost.
-
#pass1_indexes ⇒ Object
Returns the value of attribute pass1_indexes.
-
#pass2_indexes ⇒ Object
Returns the value of attribute pass2_indexes.
-
#pass3_indexes ⇒ Object
Returns the value of attribute pass3_indexes.
-
#plans ⇒ Object
readonly
Returns the value of attribute plans.
-
#statement ⇒ Object
readonly
Returns the value of attribute statement.
-
#suggest_index ⇒ Object
Returns the value of attribute suggest_index.
- #tables ⇒ Object
-
#tables_from_views ⇒ Object
Returns the value of attribute tables_from_views.
-
#total_time ⇒ Object
Returns the value of attribute total_time.
Instance Method Summary collapse
- #costs ⇒ Object
- #explainable? ⇒ Boolean
- #high_cost? ⇒ Boolean
- #initial_cost ⇒ Object
-
#initialize(statement, fingerprint = nil) ⇒ Query
constructor
A new instance of Query.
- #tree ⇒ Object
Constructor Details
#initialize(statement, fingerprint = nil) ⇒ Query
Returns a new instance of Query.
7 8 9 10 11 12 13 14 15 |
# 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 |
Instance Attribute Details
#calls ⇒ Object
Returns the value of attribute calls.
5 6 7 |
# File 'lib/dexter/query.rb', line 5 def calls @calls end |
#candidate_tables ⇒ Object
Returns the value of attribute candidate_tables.
5 6 7 |
# File 'lib/dexter/query.rb', line 5 def candidate_tables @candidate_tables end |
#candidates ⇒ Object
Returns the value of attribute candidates.
5 6 7 |
# File 'lib/dexter/query.rb', line 5 def candidates @candidates end |
#fingerprint ⇒ Object (readonly)
Returns the value of attribute fingerprint.
3 4 5 |
# File 'lib/dexter/query.rb', line 3 def fingerprint @fingerprint end |
#indexes ⇒ Object
Returns the value of attribute indexes.
5 6 7 |
# File 'lib/dexter/query.rb', line 5 def indexes @indexes end |
#missing_tables ⇒ Object
Returns the value of attribute missing_tables.
5 6 7 |
# File 'lib/dexter/query.rb', line 5 def missing_tables @missing_tables end |
#new_cost ⇒ Object
Returns the value of attribute new_cost.
5 6 7 |
# File 'lib/dexter/query.rb', line 5 def new_cost @new_cost end |
#pass1_indexes ⇒ Object
Returns the value of attribute pass1_indexes.
5 6 7 |
# File 'lib/dexter/query.rb', line 5 def pass1_indexes @pass1_indexes end |
#pass2_indexes ⇒ Object
Returns the value of attribute pass2_indexes.
5 6 7 |
# File 'lib/dexter/query.rb', line 5 def pass2_indexes @pass2_indexes end |
#pass3_indexes ⇒ Object
Returns the value of attribute pass3_indexes.
5 6 7 |
# File 'lib/dexter/query.rb', line 5 def pass3_indexes @pass3_indexes end |
#plans ⇒ Object (readonly)
Returns the value of attribute plans.
3 4 5 |
# File 'lib/dexter/query.rb', line 3 def plans @plans end |
#statement ⇒ Object (readonly)
Returns the value of attribute statement.
3 4 5 |
# File 'lib/dexter/query.rb', line 3 def statement @statement end |
#suggest_index ⇒ Object
Returns the value of attribute suggest_index.
5 6 7 |
# File 'lib/dexter/query.rb', line 5 def suggest_index @suggest_index end |
#tables ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 |
# 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.}" $stderr.puts statement [] end end |
#tables_from_views ⇒ Object
Returns the value of attribute tables_from_views.
5 6 7 |
# File 'lib/dexter/query.rb', line 5 def tables_from_views @tables_from_views end |
#total_time ⇒ Object
Returns the value of attribute total_time.
5 6 7 |
# File 'lib/dexter/query.rb', line 5 def total_time @total_time end |
Instance Method Details
#costs ⇒ Object
37 38 39 |
# File 'lib/dexter/query.rb', line 37 def costs plans.map { |plan| plan["Total Cost"] } end |
#explainable? ⇒ Boolean
33 34 35 |
# File 'lib/dexter/query.rb', line 33 def explainable? plans.size >= 3 end |
#high_cost? ⇒ Boolean
45 46 47 |
# File 'lib/dexter/query.rb', line 45 def high_cost? initial_cost && initial_cost >= 100 end |
#initial_cost ⇒ Object
41 42 43 |
# File 'lib/dexter/query.rb', line 41 def initial_cost costs[0] end |
#tree ⇒ Object
29 30 31 |
# File 'lib/dexter/query.rb', line 29 def tree parse.tree end |