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
  • 167,868
  • 16
  • 137
  • 184
Aaron Meier
  • 890
  • 7
  • 18

1 Answers1

1

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
  • 890
  • 7
  • 18