Take the 2-minute tour ×

I have the following triggers on my users table which copies the value to email field from name field.

CREATE TRIGGER copy_name_on_insert BEFORE INSERT ON users
  SET NEW.email = NEW.name;

CREATE TRIGGER copy_name_on_update BEFORE UPDATE ON users
  SET NEW.email = NEW.name;

This trigger is working fine in local env, but in production its going into an infinite loop. Does anyone have any idea about this behaviour?

Local and Production envs are running mysql 5.5.

share|improve this question
how is that possible? the only way is that you have infinite record which I don't think you have, or that the trigger is calling itself (recursive function) and the number of recursive call is in max_sp_recursion_depth that's not infinite. –  jcho360 Jun 1 '12 at 18:56

1 Answer 1

up vote 0 down vote accepted

Got this answer from our DBA.

So, this was not a recursion bug (though the error message was really bad, and looked like one). Rather, it was a memory complexity problem.

Basically, each statement must run in a limited memory space (128K in this case). While most statements fit in far less than this space, it appears that this trigger has considerably greater memory requirements.

The reason that this worked in testing is that the tests attempted were not large enough. (And the testing server likely had more memory allocated to it)

As an example, this worked in testing:

UPDATE users SET name="j@mail.com" WHERE id=1234;

But what really runs in production is:

update users set full_name='Jason H', attr1='abc1', attr2='abc', attr3='adad' .... where id=1917;

Basically, the java/hibernate system is UPDATEing every single field... for some reason. This is pretty silly, and hibernate probably should be doing less.

The considerably greater complexity of the real query pushed it over the memory limits in production.

share|improve this answer

Your Answer


