We can chat about where exactly this optimization should go, possibly parse-dot-query. This work should likely build of https://github.com/puppetlabs/puppetdb/pull/3510