Hi, Nikita,

On Jan 09, Nikita Malyavin wrote:
> 
> I don't understand the notion of the "autoincrement index". Why any index
> is important at all for an autoincrement field?

Three examples:

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

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

#####################
  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 |
  +------+---+

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

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

in the third example the auto-inc column takes part in two indexes.
But only one of them - ub - defines how auto-inc values are generated.

The "value generator" is a pair {b, ub} - a column and an index. Looking
at the column declaration alone you cannot predict how values will be
generated.

Regards,
Sergei
Chief Architect, MariaDB Server
and secur...@mariadb.org
_______________________________________________
developers mailing list -- developers@lists.mariadb.org
To unsubscribe send an email to developers-le...@lists.mariadb.org

Reply via email to