Port of latest tablesetup.sql patch