0

I have a table like:

CREATE TABLE IF NOT EXISTS my_table (
    id uuid NOT NULL PRIMARY KEY,
    duplicate_ids uuid[] DEFAULT NULL,
);

And my query is:

SELECT * FROM my_table WHERE 'some-uuid'=ANY(duplicate_ids)

Using EXPLAIN ANALYZE and trying lots of different indexes, I am unable to get the above to use an index.

Here's what I've tried (Postgres 12):

CREATE INDEX duplicate_ids_idx ON my_table USING GIN (duplicate_ids);
CREATE INDEX duplicate_ids_idx ON my_table USING GIN (duplicate_ids array_ops);
CREATE INDEX duplicate_ids_idx ON my_table USING BTREE (duplicate_ids);
CREATE INDEX duplicate_ids_idx ON my_table USING BTREE (duplicate_ids array_ops);

I've also ran SET enable_seqscan TO off; before these tests to enforce index usage.

Questions I've read:

Thank you very much for your time.

Laurenz Albe
  • 209,280
  • 17
  • 206
  • 263
Aaron Meier
  • 929
  • 9
  • 21

1 Answers1

2

Question was answered by @a_horse_with_no_name

The solution appears to be to use something like:

SELECT * FROM my_table WHERE duplicate_ids && array['some_uuid']::uuid[]
Aaron Meier
  • 929
  • 9
  • 21