Oh boy… - yes I got that out of my query (adjusted it from another query with an unnest) - but overlooked it here!
But that works more like I would expect. Now it is using the index - and the time is down to 0,5-1 sec.
I also tried to create the index as you suggested. It uses the index when a userkey
is specified - but it goes back to the def_type_user_1
again if userkey
is not specified. I have even tried to remove the “… is valued” fields in the WHERE clause - but it does not make any difference. And using this index it now takes 5-8 seconds…
Your suggestion is actually exactly the same as I started out with (don’t recall if I had the “d.” issue in that index though). But as it was slower than expected I then decided to add all the fields that could be used in the resultset AND in the WHERE clause of the queries - and add them with “… is valued” and in the same order as in the index. But I don’t know if this is the best way to do it - although it seems to be faster in this case…