Two separate problems were here:
1. copy_data_between_tables issued an implicit commit, where the assertion
was evaluated.
In INPLACE, on the contrary, the assertion is not triggered,
since the commit is done normally, by issuing trans_commit_stmt in
mysql_execute_command.
2. m_transaction_psi was also wrongly re-created in trans_register_ha,
called when a binlog write is issued. This branch is connected with
IDEMPOTENT switch and side-effects from COPY's early commit.
The exact effects of this early commit
(see mysql_trans_commit_alter_copy_data call) are not studied, so its
removal is opted out. Instead a PSI commit was added there.
MDEV-31631 Adding auto-increment to table with history online misbehaves
Adding an auto_increment column online leads to an undefined behavior.
Basically any DEFAULTs that depend on a row order in the table, or on
the non-deterministic (in scope of the ALTER TABLE statement) function
is UB.
For example, NOW() is considered generally non-deterministic
(Item_func_now_utc is marked with VCOL_NON_DETERMINISTIC), but it's fixed
in scope of a single statement.
Same for any other function that depends only on the session/status vars
apart from its arguments.
Only two UB cases are known:
* adding new AUTO_INCREMENT column. Modifying the existing column may be
fine under certain circumstances, see MDEV-31058.
* adding new column with DEFAULT(nextval(...)). Modifying the existing
column is possible, since its value will be always present in the online
event, except for the NULL -> NOT NULL modification