Indexes and Keys:
*
AUTO INCREMENT key
CREATE TABLE (
id INT UNSIGNED NOT NULL AUTO_INCREMENT,
...
PRIMARY KEY(id),
... );
Main notes:
INSERT, or specify it as NULL.
Subtle notes:
MAX(id)+1.
auto_increment_offset and auto_increment_increment.
PRIMARY KEY and simply do INDEX(id). (This is an optimization in some situations.)
AUTO_INCREMENT as the “PARTITION key” is rarely beneficial; do something different.
INSERT IGNORE (with dup key), REPLACE (which is DELETE plus INSERT) and others. ROLLBACK is another cause for gaps in ids.
COMMIT order.