[英]Performant Array Element Lookups/Overlap on caracter_varying[] column in Postgres
I have an SQL-Query looking like this: 我有一个SQL查询看起来像这样:
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 可以具有数千个条目,而输入通常只有几个。 array_column is of type
character varying[]
array_column类型为
character varying[]
I have a pretty recent version of PostgreSQL (9.2). 我有一个相当新的PostgreSQL(9.2)版本。 What would be the right index to use?
什么是正确使用的索引?
You should use a GIN
index for that. 您应该为此使用
GIN
索引。 Also see this part of the manual: http://www.postgresql.org/docs/current/static/indexes-types.html 另请参见手册的这一部分: 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 您可以在此处找到有关Gin索引的更多信息: http : //www.postgresql.org/docs/9.3/static/gin.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.