Reputation: 1155
I'm wondering if PostgreSql will use GIN
index for ANY
operator with an integer array. Lets say I have a table tree_nodes
which contains id
with type int
and path
with type int[]
. Simple example:
Will GIN index be used when I wrote a select select * from tree_nodes where :id = any(path)
and, for example :id
= 2.
I know, that in case of @> it will, but I believe, that in my case ANY
operator will be more effective than @>
Upvotes: 0
Views: 963
Reputation: 246403
A GIN index cannot be used with =ANY
.
What you can do is to use the <@
operator with a one-element array:
SELECT * FROM tree_nodes
WHERE ARRAY[$1] <@ path;
Here the GIN index can be used.
Upvotes: 1