Non-optimal postgres queries done 1-6