postgresql - Postgres array fields: find where array contains value -
currently have table schema looks this:
| id | visitor_ids | name | |----|-------------|----------------| | 1 | {abc,def} | chris houghton | | 2 | {ghi} | matt quinn |
the visitor_ids
guids, i've shortened them simplicity.
a user can have multiple visitor ids, hence array type.
i have gin index created on visitor_ids
field.
i want able lookup users visitor id. we're doing this:
select * users visitor_ids && array['abc'];
the above works, it's really slow @ scale - takes around 45ms ~700x slower lookup primary key. (even gin index)
surely there's got more efficient way of doing this? i've looked around , wasn't able find anything.
possible solutions can think of be:
- the current query bad , needs improving
- using separate user_visitor_ids table
- something smart special indexes
help appreciated :)
i tried second solution - 700x faster. bingo.
i feel unsolved problem however, what's point in adding arrays postgres when performance bad, indexes?
Comments
Post a Comment