0

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:

enter image description here

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 @>

1
  • Check the execution plan Commented May 14, 2018 at 9:36

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you. Really, there is no need to use ANY here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.