Workaround old sqlite not having 'select count(distinct key)'.