Recompute the name_template field if the template changes. backport of 41628fc7 + f25c5d85 to 7.0 plus some optimisations in triggers Fixes #3277