aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorXavier Noria <fxn@hashref.com>2012-04-26 08:00:28 -0700
committerXavier Noria <fxn@hashref.com>2012-04-26 08:00:28 -0700
commit9a3d5792a1fd2fca1554af4efcb98c2553930ac4 (patch)
tree9e3bcf6e358aa9a09903d89ebccdba7455dcf649
parent8cd14c0bc9f9429f03d1181912355d2f48b98157 (diff)
parent9fd640376efb9cdc8b213c2397f21ac57c85a90a (diff)
downloadrails-9a3d5792a1fd2fca1554af4efcb98c2553930ac4.tar.gz
rails-9a3d5792a1fd2fca1554af4efcb98c2553930ac4.tar.bz2
rails-9a3d5792a1fd2fca1554af4efcb98c2553930ac4.zip
Merge pull request #5998 from aderyabin/fix7
EXPLAIN only for sqlite3
-rw-r--r--activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb25
-rw-r--r--activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb24
2 files changed, 25 insertions, 24 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb b/activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb
index ee5d10859c..ae5eaa5f1b 100644
--- a/activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb
+++ b/activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb
@@ -50,6 +50,31 @@ module ActiveRecord
@connection.encoding.to_s
end
+ # Returns true.
+ def supports_explain?
+ true
+ end
+
+ # DATABASE STATEMENTS ======================================
+
+ def explain(arel, binds = [])
+ sql = "EXPLAIN QUERY PLAN #{to_sql(arel, binds)}"
+ ExplainPrettyPrinter.new.pp(exec_query(sql, 'EXPLAIN', binds))
+ end
+
+ class ExplainPrettyPrinter
+ # Pretty prints the result of a EXPLAIN QUERY PLAN in a way that resembles
+ # the output of the SQLite shell:
+ #
+ # 0|0|0|SEARCH TABLE users USING INTEGER PRIMARY KEY (rowid=?) (~1 rows)
+ # 0|1|1|SCAN TABLE posts (~100000 rows)
+ #
+ def pp(result) # :nodoc:
+ result.rows.map do |row|
+ row.join('|')
+ end.join("\n") + "\n"
+ end
+ end
end
end
end
diff --git a/activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb b/activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb
index 91e1482ffd..e698e7f360 100644
--- a/activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb
+++ b/activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb
@@ -116,11 +116,6 @@ module ActiveRecord
true
end
- # Returns true.
- def supports_explain?
- true
- end
-
def requires_reloading?
true
end
@@ -210,25 +205,6 @@ module ActiveRecord
# DATABASE STATEMENTS ======================================
- def explain(arel, binds = [])
- sql = "EXPLAIN QUERY PLAN #{to_sql(arel, binds)}"
- ExplainPrettyPrinter.new.pp(exec_query(sql, 'EXPLAIN', binds))
- end
-
- class ExplainPrettyPrinter
- # Pretty prints the result of a EXPLAIN QUERY PLAN in a way that resembles
- # the output of the SQLite shell:
- #
- # 0|0|0|SEARCH TABLE users USING INTEGER PRIMARY KEY (rowid=?) (~1 rows)
- # 0|1|1|SCAN TABLE posts (~100000 rows)
- #
- def pp(result) # :nodoc:
- result.rows.map do |row|
- row.join('|')
- end.join("\n") + "\n"
- end
- end
-
def exec_query(sql, name = nil, binds = [])
log(sql, name, binds) do