Performance improvement to the example SQL