lib/dexter/query.rb in pgdexter-0.1.3 vs lib/dexter/query.rb in pgdexter-0.1.4
- old
+ new
@@ -1,15 +1,28 @@
module Dexter
class Query
- attr_reader :statement, :fingerprint
- attr_accessor :initial_cost, :new_cost, :missing_tables
+ attr_reader :statement, :fingerprint, :plans
+ attr_accessor :missing_tables, :new_cost
def initialize(statement, fingerprint)
@statement = statement
@fingerprint = fingerprint
+ @plans = []
end
def tables
@tables ||= PgQuery.parse(statement).tables rescue []
+ end
+
+ def explainable?
+ plans.any?
+ end
+
+ def costs
+ plans.map { |plan| plan["Total Cost"] }
+ end
+
+ def initial_cost
+ costs[0]
end
end
end