Inefficient query generated on vault queries with custom paging
On postgres, when running vault queries with custom paging this is the generated sql:
select count(vaultschem1_.recorded_timestamp) as col_0_0_
vault_states vaultschem0_ cross join vault_states vaultschem1_
(vaultschem0_.output_index, vaultschem0_.transaction_id)=(vaultschem1_.output_index, vaultschem1_.transaction_id)
and (vaultschem0_.contract_state_class_name in ($2))
The `vault_states` table is joined with itself for no reason. This has a significant performance impact when the `vault_states` is large.