Skip to content

Commit df364ec

Browse files
author
Anna
committed
attempted to update explain syntax. More to do, holidays
1 parent cac085e commit df364ec

File tree

2 files changed

+2
-13
lines changed

2 files changed

+2
-13
lines changed

README.md

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -188,9 +188,6 @@ Another configuration is the showplan option. Some might find the XML format mor
188188
```ruby
189189
ActiveRecord::ConnectionAdapters::SQLServerAdapter.showplan_option = 'SHOWPLAN_XML'
190190
```
191-
192-
# TODO auto_explain_threshold_in_seconds has been removed from rails 4
193-
194191
**NOTE:** The method we utilize to make SHOWPLANs work is very brittle to complex SQL. There is no getting around this as we have to deconstruct an already prepared statement for the sp_executesql method. If you find that explain breaks your app, simple disable it. Do not open a github issue unless you have a patch. Please [consult the Rails guides](http://guides.rubyonrails.org/active_record_querying.html#running-explain) for more info.
195192

196193
## Versions

test/cases/showplan_test_sqlserver.rb

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ class ShowplanTestSqlserver < ActiveRecord::TestCase
88
context 'Unprepare previously prepared SQL' do
99

1010
should 'from simple statement' do
11-
plan = Car.where(:id => 1).explain
11+
plan = Car.where(id: 1).explain
1212
assert plan.starts_with?("EXPLAIN for: SELECT [cars].* FROM [cars] WHERE [cars].[id] = 1")
1313
assert plan.include?("Clustered Index Seek"), 'make sure we do not showplan the sp_executesql'
1414
end
@@ -19,17 +19,9 @@ class ShowplanTestSqlserver < ActiveRecord::TestCase
1919
assert plan.include?("Clustered Index Seek"), 'make sure we do not showplan the sp_executesql'
2020
end
2121

22-
should 'from prepared statement' do
23-
plan = capture_logger do
24-
with_threshold(0) { Car.find(1) }
25-
end
26-
assert plan.include?('EXPLAIN for: SELECT TOP (1) [cars].* FROM [cars] WHERE [cars].[id] = @0 [["id", 1]]')
27-
assert plan.include?("Clustered Index Seek"), 'make sure we do not showplan the sp_executesql'
28-
end
29-
3022
should 'from prepared statement ...' do
3123
plan = capture_logger do
32-
with_threshold(0) { Car.where(:name => ',').first }
24+
Car.where(:name => ',').limit(1).explain
3325
end
3426
assert plan.include?("SELECT TOP (1) [cars].* FROM [cars] WHERE [cars].[name] = N','")
3527
assert plan.include?("TOP EXPRESSION"), 'make sure we do not showplan the sp_executesql'

0 commit comments

Comments
 (0)