statistics gathering and optimizer (new version)