Is there a good reason for $subject, other than that the code is entangled with other ALTER TABLE code?
The new SET DISTINCT might be equally affected.