Skip to content

Business intelligence made simple

Added explain method

Andrew Kaned5d4af71c180
diff --git a/lib/blazer/data_source.rb b/lib/blazer/data_source.rb
index 5cd11d22..ce2f0a6a 100644
--- a/lib/blazer/data_source.rb
+++ b/lib/blazer/data_source.rb
@@ -83,15 +83,17 @@ module Blazer
end
def cost(statement)
+ result = explain(statement)
+ match = /cost=\d+\.\d+..(\d+\.\d+) /.match(result)
+ match[1] if match
+ end
+
+ def explain(statement)
if postgresql? || redshift?
- begin
- result = connection_model.connection.select_all("EXPLAIN #{statement}")
- match = /cost=\d+\.\d+..(\d+\.\d+) /.match(result.rows.first.first)
- match[1] if match
- rescue ActiveRecord::StatementInvalid
- # do nothing
- end
+ connection_model.connection.select_all("EXPLAIN #{statement}").rows.first.first
end
+ rescue
+ nil
end
def run_main_statement(statement, options = {})