Class: Dexter::Query
- Inherits:
-
Object
- Object
- Dexter::Query
- Defined in:
- lib/dexter/query.rb
Instance Attribute Summary collapse
-
#fingerprint ⇒ Object
readonly
Returns the value of attribute fingerprint.
-
#missing_tables ⇒ Object
Returns the value of attribute missing_tables.
-
#new_cost ⇒ Object
Returns the value of attribute new_cost.
-
#plans ⇒ Object
readonly
Returns the value of attribute plans.
-
#statement ⇒ Object
readonly
Returns the value of attribute statement.
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.
- #tables ⇒ Object
- #tree ⇒ Object
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
#fingerprint ⇒ Object (readonly)
Returns the value of attribute fingerprint.
3 4 5 |
# File 'lib/dexter/query.rb', line 3 def fingerprint @fingerprint end |
#missing_tables ⇒ Object
Returns the value of attribute missing_tables.
4 5 6 |
# File 'lib/dexter/query.rb', line 4 def missing_tables @missing_tables end |
#new_cost ⇒ Object
Returns the value of attribute new_cost.
4 5 6 |
# File 'lib/dexter/query.rb', line 4 def new_cost @new_cost 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 |
Instance Method Details
#costs ⇒ Object
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_cost ⇒ Object
31 32 33 |
# File 'lib/dexter/query.rb', line 31 def initial_cost costs[0] end |
#tables ⇒ Object
15 16 17 |
# File 'lib/dexter/query.rb', line 15 def tables @tables ||= parse ? parse.tables : [] end |
#tree ⇒ Object
19 20 21 |
# File 'lib/dexter/query.rb', line 19 def tree parse.tree end |