Fix NPE when subquery returns empty result