> The table is huge and it takes a lot of time to add the INDEX and the FOREIGN > KEY although all values are NULL. > Considering that the new DepartmentId column is NULL for all rows at this > point, is there a way to make the INDEX and FOREIGN KEY creation run faster?
In your script to create index add this: set maintenance_work_mem = '1GB' or any other figure you feel comfortable.