sort and index types by cost
fix and test analyze with optimize