origin_visit_get_latest: Materialize subquery on 'origin' table.
postgresql's query planner does not understand the origin is unique, so it performs a partial index scan on origin_visit_pkey, which is inefficient on origins with many visits.
This commit itself is not enough to make it use the proper index, but provides this necessary change that will be used by a future commit.
Migrated from D7338 (view on Phabricator)