I've pushed a cleaned up version of the fix. I had to make some adjustments in the backbranches, because the way we store the analyzed statistics evolved, and RemoveStatisticsById() used to do everything. I ended up introducing RemoveStatisticsDataById() in the backbranches too, but only as a static function - that makes the code much cleaner.
regards -- Tomas Vondra EnterpriseDB: http://www.enterprisedb.com The Enterprise PostgreSQL Company