Skip to content

Commit

Permalink
Extend relation to switch "enable_seqscan" around query execution
Browse files Browse the repository at this point in the history
  • Loading branch information
yoshuki committed Nov 2, 2016
1 parent 5f53f5d commit 049c8d4
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
1 change: 1 addition & 0 deletions app/models/article.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ class Article < ApplicationRecord
articles = select("#{quoted_table_name}.*, pgroonga.score(#{quoted_table_name}) AS pgroonga_score")
.where("title #{operator} ? OR body #{operator} ?", query, query)
.reorder('pgroonga_score DESC')
.extending(DisableSequentialScan)

return articles unless highlight

Expand Down
8 changes: 8 additions & 0 deletions app/models/concerns/disable_sequential_scan.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module DisableSequentialScan
def exec_queries
@klass.connection.exec_query('SET enable_seqscan TO off')
super
ensure
@klass.connection.exec_query('SET enable_seqscan TO on')
end
end

0 comments on commit 049c8d4

Please sign in to comment.