rails/rails — pull request #6197 by blakesmith (2012-05-07 21:38:06+00:00)
Title: Don't run explain on slow queries for database adapters that don't support it

When using the activerecord-jdbcmysql connection adapter, I received this exception after a slow query fired:

```

NoMethodError: undefined method `explain' for #
from /Users/blake/.rvm/gems/jruby-1.6.7-d19@myapp/gems/activerecord-3.2.3/lib/active_record/explain.rb:65:in `exec_explain'
from org/jruby/RubyKernel.java:1787:in `tap'
from /Users/blake/.rvm/gems/jruby-1.6.7-d19@myapp/gems/activerecord-3.2.3/lib/active_record/explain.rb:59:in `exec_explain'
from org/jruby/RubyArray.java:2339:in `collect'
from /Users/blake/.rvm/gems/jruby-1.6.7-d19@myapp/gems/activerecord-3.2.3/lib/active_record/explain.rb:58:in `exec_explain'
from /Users/blake/.rvm/gems/jruby-1.6.7-d19@myapp/gems/activerecord-3.2.3/lib/active_record/explain.rb:34:in `logging_query_plan'
from /Users/blake/.rvm/gems/jruby-1.6.7-d19@myapp/gems/activerecord-3.2.3/lib/active_record/relation.rb:159:in `to_a'
from /Users/blake/.rvm/gems/jruby-1.6.7-d19@myapp/gems/activerecord-3.2.3/lib/active_record/relation/finder_methods.rb:377:in `find_first'
from /Users/blake/.rvm/gems/jruby-1.6.7-d19@myapp/gems/activerecord-3.2.3/lib/active_record/relation/finder_methods.rb:122:in `first'
from org/jruby/RubyBasicObject.java:1698:in `__send__'
from /Users/blake/.rvm/gems/jruby-1.6.7-d19@myapp/gems/activerecord-3.2.3/lib/active_record/querying.rb:5:in `first'
from (irb):1:in `evaluate'
from org/jruby/RubyKernel.java:1088:in `eval'
from org/jruby/RubyKernel.java:1410:in `loop'
from org/jruby/RubyKernel.java:1197:in `catch'
from org/jruby/RubyKernel.java:1197:in `catch'
from /Users/blake/.rvm/gems/jruby-1.6.7-d19@myapp/gems/railties-3.2.3/lib/rails/commands/console.rb:47:in `start'
from /Users/blake/.rvm/gems/jruby-1.6.7-d19@myapp/gems/railties-3.2.3/lib/rails/commands/console.rb:8:in `start'
from /Users/blake/.rvm/gems/jruby-1.6.7-d19@myapp/gems/railties-3.2.3/lib/rails/commands.rb:41:in `(root)'
from org/jruby/RubyKernel.java:1042:in `require'
from script/rails:6:in `(root)'jruby-1.6.7-d19 :002 >
```

Digging a little deeper, it seems that only mysql2, postgres and sqlite3 support explain on the connection adapter. This change prevents the slow query explain from running if the connection adapter does not support it. Ideally, the test wouldn't stub out 'supports_explain?' on a connection that does indeed support it, but we don't yet have any tests that run end-to-end against a jruby runtime and use the jdbc drivers.

Feedback appreciated!

Blake