diff options
author | Xavier Noria <fxn@hashref.com> | 2011-12-02 11:16:07 -0800 |
---|---|---|
committer | Xavier Noria <fxn@hashref.com> | 2011-12-02 11:16:26 -0800 |
commit | 0be5adaedf6565630bed04c6c651f3ff8d77c5b8 (patch) | |
tree | 93659d4d00d89bca44b2b3fbd6e49a757602f5ca /railties | |
parent | 36c014193ee5de84b1ac7ef50524c656e01b142d (diff) | |
download | rails-0be5adaedf6565630bed04c6c651f3ff8d77c5b8.tar.gz rails-0be5adaedf6565630bed04c6c651f3ff8d77c5b8.tar.bz2 rails-0be5adaedf6565630bed04c6c651f3ff8d77c5b8.zip |
implements AR::Base(.|#)silence_auto_explain
Diffstat (limited to 'railties')
-rw-r--r-- | railties/guides/source/active_record_querying.textile | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/railties/guides/source/active_record_querying.textile b/railties/guides/source/active_record_querying.textile index 352f23dc01..0ccaffe45e 100644 --- a/railties/guides/source/active_record_querying.textile +++ b/railties/guides/source/active_record_querying.textile @@ -1369,6 +1369,43 @@ EXPLAIN for: SELECT `posts`.* FROM `posts` WHERE `posts`.`user_id` IN (1) under MySQL. +h4. Automatic EXPLAIN + +Active Record is able to run EXPLAIN automatically on slow queries and log its +output. This feature is controlled by the configuration parameter + +<ruby> +config.active_record.auto_explain_threshold_in_seconds +</ruby> + +If set to a number, any query exceeding those many seconds will have its EXPLAIN +automatically triggered and logged. In the case of relations, the threshold is +compared to the total time needed to fetch records. So, a relation is seen as a +unit of work, no matter whether the implementation of eager loading involves +several queries under the hood. + +A threshold of +nil+ disables automatic EXPLAINs. + +The default threshold in development mode is 0.5 seconds, and +nil+ in test and +production modes. + +h5. Disabling Automatic EXPLAIN + +Automatic EXPLAIN can be selectively silenced with +silence_auto_explain+, which +is a class and instance method of +ActiveRecord::Base+: + +<ruby> +silence_auto_explain do + # no automatic EXPLAIN is triggered here +end +</ruby> + +That may be useful for queries you know are slow but fine, like a heavyweigth +report of an admin interface. + +As its name suggests, +silence_auto_explain+ only silences automatic EXPLAINs. +Explicit calls to +ActiveRecord::Relation#explain+ run. + h4. Interpreting EXPLAIN Interpretation of the output of EXPLAIN is beyond the scope of this guide. The |