Say I have a table like this:
create table mytable (
mycol text[]
)
And I want to select all rows where mycol contains "hello". I can think of two ways to do this:
SELECT * FROM mytable WHERE 'hello'=any(mycol);
--or
SELECT * FROM mytable WHERE mycol && '{hello}';
I know for the second option I can use GIN indexes (which allow for array options), and I'm pretty sure for the first I would use a BTREE (or maybe a HASH?).
So my question is this: If I only need to check the membership of a single item, which method with what index is most efficient for a table with millions of rows?
explainand it will tell you.