refactor SQL queries in sn-payload to cut queries on 100m+ rows from 8m to 20s