Question

We are running Percona XtraDB Cluster with 4 machines in the cluster. I have noticed that our primary key column, which is an AUTO_INCREMENT column, has random number gaps in it. For example:

id  created_at  title   artist  album
1   1375074427  Night Train Jason Aldean    NULL
5   1375074429  Open Arms   JOURNEY NULL
9   1375074429  LIFT ME UP  FIVE FINGER DEATH PUNCH NULL
12  1375074430  Into the Mystic Van Morrison    NULL
16  1375074430  MARY JANES LAST DANCE   TOM PETTY   NULL
20  1375074430  EVERLONG    FOO FIGHTERS    NULL
21  1375074433  THE ZOO SCORPIONS   NULL
25  1375074433  (Don't Fear) The Reaper Blue Oyster Cult    NULL
28  1375074437  Mambo Italiano  Rosemary Clooney    The Big Night
32  1375074437  HOLY GRAIL  JAY Z / JUSTIN TIMBERLAKE   NULL
36  1375074437  REAL WORLD  MATCHBOX 20 NULL
37  1375074438  Smile   Uncle Kracker   NULL
41  1375074443  SOMEONE LIKE YOU    ADELE   NULL
45  1375074444  STAY    RIHANNA FT MIKKY EKKO   NULL
49  1375074444  Turn Your Radio On  The Statler Brothers    Today's Gospel Favorites
52  1375074444  Hold The Line   Toto    NULL
56  1375074444  Reach For The Sky   Firehouse   NULL
57  1375074448  Through Glass   Stone Sour  NULL
61  1375074448  Through Glass   Stone Sour  NULL
65  1375074448  Love%20On%20Top Beyonc%E9   4%20(Deluxe%20Edition)

I'm curious as to why this is happening. I'm reading about the innodb_locks_unsafe_for_binlog option, which is enabled on our machines, and I have a feeling it has something to do with that. But I want to be sure this is okay.

We are experiencing random deadlocks and I want to eliminate this configuration item as the cause as it is supposed to help prevent deadlocks from what I've read.

Is it bad to have gaps in the PK like this? I feel like that shouldn't be happening.

Was it helpful?

Solution

This behavior of InnoDB is absolutely fine and nothing to worry about. As a fork of InnoDB xtradb uses most likely the auto_increment handling algorithm than InnoDB. Its designed up from (not exactly sure) 5.1.x to allow higher concurrency while doing certain operations like INSERT ON DUPLICATE KEY UPDATE operations in InnoDB.

You will find more information on this topic in the docs: AUTO_INCREMENT Handling in InnoDB

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top