From 248bebb8cdb7f8f2cb104d91a08e529b36224f6d Mon Sep 17 00:00:00 2001 From: Guo Xiang Tan Date: Mon, 17 Aug 2020 13:50:27 +0800 Subject: [PATCH] PERF: Remove extra subquery in search. I also noticed that removing the subquery helps the planner to plan better. --- lib/search.rb | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/lib/search.rb b/lib/search.rb index c2b4a13b52f..9cf0c857a2e 100644 --- a/lib/search.rb +++ b/lib/search.rb @@ -1024,9 +1024,7 @@ class Search def categories_ignored(posts) posts.where(<<~SQL, Searchable::PRIORITIES[:ignore]) - categories.id NOT IN ( - SELECT categories.id WHERE categories.search_priority = ? - ) + (categories.search_priority IS NULL OR categories.search_priority IS NOT NULL AND categories.search_priority <> ?) SQL end