The schema:
# Table name: foos
#
# id :integer not null, primary key
# bar_ids :integer is an Array
#
# Indexes
#
# index_foos_on_bar_ids (bar_ids) USING gin
The query:
SELECT * FROM foos
WHERE (
bar_ids && '{
28151247,
17295392,
…300 more bar_ids…,
29368568,
45191356
}')
This results in a very slow sequential scan. I tried rewriting as a series of ORs, but that just gave me a parallel sequential scan. Splitting it up into smaller queries works—it can do up to about 70 terms before switching to an inefficient plan–but that requires running many more queries. Is there a way I can write the query to get a more efficient plan?