restore performance improvements

@czue @twymer @dannyroberts 
(I'm cool with custom SQL for this level of performance gain)