OMG! 😯

So, it's really not what's called *identity field* in the standard, since there's no connection with key, it's just always generated.

And now your approach looks even better.

One more question:

create table t1 (a int, b int not null auto_increment, unique uab (a,b));
  insert t1 (a) values (1),(2),(1),(3);
  select * from t1;

prints:
  +------+---+
  | a    | b |
  +------+---+
  |    1 | 1 |
  |    1 | 2 |
  |    2 | 1 |
  |    3 | 1 |
  +------+---+

Why not 1 2 1 2 in column b?
I understood the behavior as "generate a new value only if we have a conflict with the current value".
And then in the insertion order the values for b would be 1, 1, 2, 2.

--
Yours truly,
Nikita Malyavin