Convertir des tables MyISAM vers InnoDB
<<<
Comment les colonnes AUTO_INCREMENT fonctionnent avec InnoDB Contraintes de clés étrangères FOREIGN KEY
>>>

16.7 Créer des tables InnoDB
16 Tables InnoDB
 Manuel de Référence MySQL 4.1 : Version Française

Comment utiliser les transactions de InnoDB avec différentes API
Convertir des tables MyISAM vers InnoDB
->Comment les colonnes AUTO_INCREMENT fonctionnent avec InnoDB
Contraintes de clés étrangères FOREIGN KEY
InnoDB et la réplication MySQL
Espaces de tables multiples : chaque table InnoDB a son fichier @filename{.ibd}

16.7.3 Comment les colonnes AUTO_INCREMENT fonctionnent avec InnoDB

Si vous spécifiez une colonne AUTO_INCREMENT dans une table, la table InnoDB va ajouter dans le dictionnaire de données un compteur spécial appelé le compteur auto-incrément, qui est utilisé pour assigner les nouvelles valeurs de la colonne. Le compteur est stocké uniquement en mémoire, et non pas sur le disque.

InnoDB utilise l'algorithme suivant pour initialiser le compteur auto-incrément pour la table T qui contient la colonne de type AUTO_INCREMENT appelée ai_col : après le démarrage du serveur, lorsqu'un utilisateur fait une insertion dans la table T , InnoDB exécute la commande suivante :

SELECT MAX(ai_col) FROM T FOR UPDATE;
La valeur lue par la commande est incrémenté d'une unité, et assignée à la colonne auto-incrément et au compteur de table. Si la table est vide, la valeur de 1 est assignée. Si le compteur n'est pas initialisé et que l'utilisateur appelle la commande SHOW TABLE STATUS qui affiche les informations de la table T , le compteur est initialisé mais pas incrémenté, et stocké pour être utilisé ultérieurement. Notez que dant cette initialisation, nous posons un verrou exclusif en lecture sur la table, et le verrou durera jusqu'à la fin de la transaction. InnoDB follows the same procedure for initializing the auto-increment counter for a freshly created table.

Note that if the user specifies NULL or 0 for the AUTO_INCREMENT column in an INSERT , InnoDB treats the row as if the value had not been specified and generates a new value for it.

After the auto-increment counter has been initialized, if a user inserts a row that explicitly specifies the column value, and the value is bigger than the current counter value, the counter is set to the specified column value. If the user does not explicitly specify a value, InnoDB increments the counter by one and assigns the new value to the column.

When accessing the auto-increment counter, InnoDB uses a special table level AUTO-INC lock that it keeps to the end of the current SQL statement, not to the end of the transaction. The special lock release strategy was introduced to improve concurrency for inserts into a table containing an AUTO_INCREMENT column. Two transactions cannot have the AUTO-INC lock on the same table simultaneously.

Note that you may see gaps in the sequence of values assigned to the AUTO_INCREMENT column if you roll back transactions that have gotten numbers from the counter.

The behavior of the auto-increment mechanism is not defined if a user assigns a negative value to the column or if the value becomes bigger than the maximum integer that can be stored in the specified integer type.

<< Comment les colonnes AUTO_INCREMENT fonctionnent avec InnoDB >>
Convertir des tables MyISAM vers InnoDB Créer des tables InnoDB Contraintes de clés étrangères FOREIGN KEY