The query can be performed using a prefix query on the ID index. Also backport some enterprise changes to prevent conflicts.