lib/dexter/query.rb in pgdexter-0.1.5 vs lib/dexter/query.rb in pgdexter-0.1.6
- old
+ new
@@ -11,21 +11,38 @@
@fingerprint = fingerprint
@plans = []
end
def tables
- @tables ||= PgQuery.parse(statement).tables rescue []
+ @tables ||= parse ? parse.tables : []
end
+ def tree
+ parse.tree
+ end
+
def explainable?
plans.any?
end
def costs
plans.map { |plan| plan["Total Cost"] }
end
def initial_cost
costs[0]
+ end
+
+ def high_cost?
+ initial_cost && initial_cost >= 100
+ end
+
+ private
+
+ def parse
+ unless defined?(@parse)
+ @parse = PgQuery.parse(statement) rescue nil
+ end
+ @parse
end
end
end