Hi,
While investigating http://bugs.mysql.com/bug.php?id=31540, I noticed
that MySQL calls ha_innobase::get_auto_increment() with different
values for nb_desired_values within a multi-row insert.
The first time ha_innobase::get_auto_increment is called with the
following values:
Breakpoint 2, ha_innobase::get_auto_increment (this=0x8b78988, offset=1,
increment=1, nb_desired_values=1, first_value=0x8f1b9260,
nb_reserved_values=0x8f1b9258) at handler/ha_innodb.cc:7314
and so we reserve one value.
Subsequent calls have the following values:
Breakpoint 2, ha_innobase::get_auto_increment (this=0x8b78988, offset=1,
increment=1, nb_desired_values=2, first_value=0x8f1b9260,
nb_reserved_values=0x8f1b9258) at handler/ha_innodb.cc:7314
..
Breakpoint 2, ha_innobase::get_auto_increment (this=0x8b78988, offset=1,
increment=1, nb_desired_values=2, first_value=0x8f1b9260,
nb_reserved_values=0x8f1b9258) at handler/ha_innodb.cc:7314
In InnoDB we trust the value of nb_desired_vales and accordingly reserve
the appropriate "block" of values, which results in gaps. Also, I
noticed that each invocation from within the trigger is treated as a
separate statement. This can be seen from the invocation of
ha_innobase::start_stmt() for each invocation of the trigger.
Why then isn't the value of nb_desired_values 1 for all cases (given
my above claim of separate statements for the trigger invocation), since
they are clearly treated as separate statements ? Or, is there some way
of working around this problem that I've missed ?
Regards,
-sunny