Covering Index issue in 4.5.1

n1ql
query

#1

If I run the following query:

SELECT meta().id, nickName 
FROM Account AS x 
WHERE x.type='user' 
AND x.email LIKE 'example%' 

UNION ALL SELECT meta().id, nickName
FROM Account AS x 
WHERE x.type='userList'

ORDER BY nickName ASC

With two indexes in the system:

CREATE INDEX UserIndex 
ON Account(type,nickName,email) 
WHERE (type = "user")

CREATE INDEX UserListIndex 
ON Account(type,nickName) 
WHERE (type = "userList")

The second part of the query is not covered by the UserListIndex (the EXPLAIN has a fetch step).
However, If i remove the line starting with “AND”, or change it to use the nickName field, it then is covered.
Or, if I instead only remove the ORDER BY clause, it is also covered in that case.

Something seems a little fishy here…


#2

Noted. Please try this.

EXPLAIN SELECT id, nickName
FROM (
SELECT meta().id, nickName 
FROM Account AS x 
WHERE x.type='user' 
AND x.email LIKE 'example%' 

UNION ALL SELECT meta().id, nickName
FROM Account AS x 
WHERE x.type='userList'
) AS s
ORDER BY nickName ASC;