简体   繁体   中英

Performant Array Element Lookups/Overlap on caracter_varying[] column in Postgres

I have an SQL-Query looking like this:

SELECT *
FROM table
WHERE ARRAY['entry1', 'entry2'] && array_column

Where array_column can have have thousands of entries, while the input usually has just a couple of them. array_column is of type character varying[]

I have a pretty recent version of PostgreSQL (9.2). What would be the right index to use?

You should use a GIN index for that. Also see this part of the manual: http://www.postgresql.org/docs/current/static/indexes-types.html

Do note that it only works when using the array operators (which you are using, && is one of them).

You can find more information about Gin indexes here: http://www.postgresql.org/docs/9.3/static/gin.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM