MariaDB - INNODB skipping the number sequence while creating incremental records - why? The 2019 Stack Overflow Developer Survey Results Are In Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern) The Ask Question Wizard is Live! Data science time! April 2019 and salary with experienceHow to update all values of a column by all values of another column in mysqlConverting my MyISAM to InnoDBusing limit and where clause to make paginationMySQL Limit LEFT JOIN Subquery after joiningwhether it is possible to use a foreign key to the table enum?mysql relation slowError importing database in phpmyadminJOIN Query In MYSQL and PHPMYSQL Error Installing BuildEngineMySQL match against 0 result in MyISAM but works on InnoDBHow to migrate relational database in symfony 4?
Why can't wing-mounted spoilers be used to steepen approaches?
Can a novice safely splice in wire to lengthen 5V charging cable?
Did God make two great lights or did He make the great light two?
University's motivation for having tenure-track positions
High Q peak in frequency response means what in time domain?
Is there a writing software that you can sort scenes like slides in PowerPoint?
Finding the path in a graph from A to B then back to A with a minimum of shared edges
Scientific Reports - Significant Figures
What do you call a plan that's an alternative plan in case your initial plan fails?
How to stretch delimiters to envolve matrices inside of a kbordermatrix?
ELI5: Why do they say that Israel would have been the fourth country to land a spacecraft on the Moon and why do they call it low cost?
When did F become S in typeography, and why?
How did passengers keep warm on sail ships?
Make it rain characters
Does Parliament hold absolute power in the UK?
Sort a list of pairs representing an acyclic, partial automorphism
Would an alien lifeform be able to achieve space travel if lacking in vision?
Road tyres vs "Street" tyres for charity ride on MTB Tandem
Can withdrawing asylum be illegal?
Relations between two reciprocal partial derivatives?
The following signatures were invalid: EXPKEYSIG 1397BC53640DB551
Segmentation fault output is suppressed when piping stdin into a function. Why?
What was the last x86 CPU that did not have the x87 floating-point unit built in?
Is it ethical to upload a automatically generated paper to a non peer-reviewed site as part of a larger research?
MariaDB - INNODB skipping the number sequence while creating incremental records - why?
The 2019 Stack Overflow Developer Survey Results Are In
Announcing the arrival of Valued Associate #679: Cesar Manara
Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern)
The Ask Question Wizard is Live!
Data science time! April 2019 and salary with experienceHow to update all values of a column by all values of another column in mysqlConverting my MyISAM to InnoDBusing limit and where clause to make paginationMySQL Limit LEFT JOIN Subquery after joiningwhether it is possible to use a foreign key to the table enum?mysql relation slowError importing database in phpmyadminJOIN Query In MYSQL and PHPMYSQL Error Installing BuildEngineMySQL match against 0 result in MyISAM but works on InnoDBHow to migrate relational database in symfony 4?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
I do not know if this is expected behavior with INNODB
, but I really think it's totally weird.
If I use the same SQL statement using MYISAM
, the behavior occurs as expected.
MYISAM
CREATE TABLE main_database.numero (
id INT NOT NULL AUTO_INCREMENT,
PRIMARY KEY(id)
) ENGINE = MYISAM DEFAULT CHARSET = utf8mb4 COLLATE = utf8mb4_unicode_ci;
INSERT INTO main_database.numero VALUES(NULL); -- First, run once time ...
INSERT INTO main_database.numero SELECT NULL FROM main_database.numero; -- After, more 12 times = 4096 records
Result (expected behavior):
Now if I use exactly the same statement, however, informing that the engine is INNODB
.
INNODB
CREATE TABLE main_database.numero (
id INT NOT NULL AUTO_INCREMENT,
PRIMARY KEY(id)
) ENGINE = INNODB DEFAULT CHARSET = utf8mb4 COLLATE = utf8mb4_unicode_ci;
INSERT INTO main_database.numero VALUES(NULL); -- First, run once time ...
INSERT INTO main_database.numero SELECT NULL FROM main_database.numero; -- After, more 12 times = 4096 records
Result (weird result - Skipping the number sequence):
In fact, both engines are creating the expected 4096 records, but I got worried with behavior of INNO
, because I'm migrating my databases from MYISAM
to INNODB
and I do not know how much that can impact my applications.
mysql mariadb innodb myisam
|
show 4 more comments
I do not know if this is expected behavior with INNODB
, but I really think it's totally weird.
If I use the same SQL statement using MYISAM
, the behavior occurs as expected.
MYISAM
CREATE TABLE main_database.numero (
id INT NOT NULL AUTO_INCREMENT,
PRIMARY KEY(id)
) ENGINE = MYISAM DEFAULT CHARSET = utf8mb4 COLLATE = utf8mb4_unicode_ci;
INSERT INTO main_database.numero VALUES(NULL); -- First, run once time ...
INSERT INTO main_database.numero SELECT NULL FROM main_database.numero; -- After, more 12 times = 4096 records
Result (expected behavior):
Now if I use exactly the same statement, however, informing that the engine is INNODB
.
INNODB
CREATE TABLE main_database.numero (
id INT NOT NULL AUTO_INCREMENT,
PRIMARY KEY(id)
) ENGINE = INNODB DEFAULT CHARSET = utf8mb4 COLLATE = utf8mb4_unicode_ci;
INSERT INTO main_database.numero VALUES(NULL); -- First, run once time ...
INSERT INTO main_database.numero SELECT NULL FROM main_database.numero; -- After, more 12 times = 4096 records
Result (weird result - Skipping the number sequence):
In fact, both engines are creating the expected 4096 records, but I got worried with behavior of INNO
, because I'm migrating my databases from MYISAM
to INNODB
and I do not know how much that can impact my applications.
mysql mariadb innodb myisam
Could be an insert that was rolled back?
– Lasse Vågsæther Karlsen
Mar 8 at 12:38
This scheme is totally clean/new, nothing is accessing or writing on it. By your question, I do not know for some reason MariaDB itself is performing the rollback.
– Magno Alberto
Mar 8 at 12:42
This does not make sense. Have you tried to place all 34 INSERTs inside a single transaction ?
– IVO GELOV
Mar 8 at 12:45
Sorry, but I think that it is not relevant if it makes sense or not, since the statement works perfectly with MYISAM. But yes, I use this statement to create a loop in a single statement.
– Magno Alberto
Mar 8 at 12:47
Sometimes MySQL trips up. Don't worry about the missing numbers.
– Strawberry
Mar 8 at 12:50
|
show 4 more comments
I do not know if this is expected behavior with INNODB
, but I really think it's totally weird.
If I use the same SQL statement using MYISAM
, the behavior occurs as expected.
MYISAM
CREATE TABLE main_database.numero (
id INT NOT NULL AUTO_INCREMENT,
PRIMARY KEY(id)
) ENGINE = MYISAM DEFAULT CHARSET = utf8mb4 COLLATE = utf8mb4_unicode_ci;
INSERT INTO main_database.numero VALUES(NULL); -- First, run once time ...
INSERT INTO main_database.numero SELECT NULL FROM main_database.numero; -- After, more 12 times = 4096 records
Result (expected behavior):
Now if I use exactly the same statement, however, informing that the engine is INNODB
.
INNODB
CREATE TABLE main_database.numero (
id INT NOT NULL AUTO_INCREMENT,
PRIMARY KEY(id)
) ENGINE = INNODB DEFAULT CHARSET = utf8mb4 COLLATE = utf8mb4_unicode_ci;
INSERT INTO main_database.numero VALUES(NULL); -- First, run once time ...
INSERT INTO main_database.numero SELECT NULL FROM main_database.numero; -- After, more 12 times = 4096 records
Result (weird result - Skipping the number sequence):
In fact, both engines are creating the expected 4096 records, but I got worried with behavior of INNO
, because I'm migrating my databases from MYISAM
to INNODB
and I do not know how much that can impact my applications.
mysql mariadb innodb myisam
I do not know if this is expected behavior with INNODB
, but I really think it's totally weird.
If I use the same SQL statement using MYISAM
, the behavior occurs as expected.
MYISAM
CREATE TABLE main_database.numero (
id INT NOT NULL AUTO_INCREMENT,
PRIMARY KEY(id)
) ENGINE = MYISAM DEFAULT CHARSET = utf8mb4 COLLATE = utf8mb4_unicode_ci;
INSERT INTO main_database.numero VALUES(NULL); -- First, run once time ...
INSERT INTO main_database.numero SELECT NULL FROM main_database.numero; -- After, more 12 times = 4096 records
Result (expected behavior):
Now if I use exactly the same statement, however, informing that the engine is INNODB
.
INNODB
CREATE TABLE main_database.numero (
id INT NOT NULL AUTO_INCREMENT,
PRIMARY KEY(id)
) ENGINE = INNODB DEFAULT CHARSET = utf8mb4 COLLATE = utf8mb4_unicode_ci;
INSERT INTO main_database.numero VALUES(NULL); -- First, run once time ...
INSERT INTO main_database.numero SELECT NULL FROM main_database.numero; -- After, more 12 times = 4096 records
Result (weird result - Skipping the number sequence):
In fact, both engines are creating the expected 4096 records, but I got worried with behavior of INNO
, because I'm migrating my databases from MYISAM
to INNODB
and I do not know how much that can impact my applications.
mysql mariadb innodb myisam
mysql mariadb innodb myisam
asked Mar 8 at 12:37
Magno AlbertoMagno Alberto
100110
100110
Could be an insert that was rolled back?
– Lasse Vågsæther Karlsen
Mar 8 at 12:38
This scheme is totally clean/new, nothing is accessing or writing on it. By your question, I do not know for some reason MariaDB itself is performing the rollback.
– Magno Alberto
Mar 8 at 12:42
This does not make sense. Have you tried to place all 34 INSERTs inside a single transaction ?
– IVO GELOV
Mar 8 at 12:45
Sorry, but I think that it is not relevant if it makes sense or not, since the statement works perfectly with MYISAM. But yes, I use this statement to create a loop in a single statement.
– Magno Alberto
Mar 8 at 12:47
Sometimes MySQL trips up. Don't worry about the missing numbers.
– Strawberry
Mar 8 at 12:50
|
show 4 more comments
Could be an insert that was rolled back?
– Lasse Vågsæther Karlsen
Mar 8 at 12:38
This scheme is totally clean/new, nothing is accessing or writing on it. By your question, I do not know for some reason MariaDB itself is performing the rollback.
– Magno Alberto
Mar 8 at 12:42
This does not make sense. Have you tried to place all 34 INSERTs inside a single transaction ?
– IVO GELOV
Mar 8 at 12:45
Sorry, but I think that it is not relevant if it makes sense or not, since the statement works perfectly with MYISAM. But yes, I use this statement to create a loop in a single statement.
– Magno Alberto
Mar 8 at 12:47
Sometimes MySQL trips up. Don't worry about the missing numbers.
– Strawberry
Mar 8 at 12:50
Could be an insert that was rolled back?
– Lasse Vågsæther Karlsen
Mar 8 at 12:38
Could be an insert that was rolled back?
– Lasse Vågsæther Karlsen
Mar 8 at 12:38
This scheme is totally clean/new, nothing is accessing or writing on it. By your question, I do not know for some reason MariaDB itself is performing the rollback.
– Magno Alberto
Mar 8 at 12:42
This scheme is totally clean/new, nothing is accessing or writing on it. By your question, I do not know for some reason MariaDB itself is performing the rollback.
– Magno Alberto
Mar 8 at 12:42
This does not make sense. Have you tried to place all 34 INSERTs inside a single transaction ?
– IVO GELOV
Mar 8 at 12:45
This does not make sense. Have you tried to place all 34 INSERTs inside a single transaction ?
– IVO GELOV
Mar 8 at 12:45
Sorry, but I think that it is not relevant if it makes sense or not, since the statement works perfectly with MYISAM. But yes, I use this statement to create a loop in a single statement.
– Magno Alberto
Mar 8 at 12:47
Sorry, but I think that it is not relevant if it makes sense or not, since the statement works perfectly with MYISAM. But yes, I use this statement to create a loop in a single statement.
– Magno Alberto
Mar 8 at 12:47
Sometimes MySQL trips up. Don't worry about the missing numbers.
– Strawberry
Mar 8 at 12:50
Sometimes MySQL trips up. Don't worry about the missing numbers.
– Strawberry
Mar 8 at 12:50
|
show 4 more comments
2 Answers
2
active
oldest
votes
The auto_increment mechanism is required to generate unique values, that are greater than any value it has generated previously. It does not guarantee to generate consecutive values.
There's some discussion about it here: https://bugs.mysql.com/bug.php?id=57643
There is little importance in generating consecutive values faithfully, because any value could be "lost" for other reasons:
- Your INSERT fails, for example because of violating a constraint like UNIQUE KEY or FOREIGN KEY.
- You roll back the transaction for your INSERT.
- You succeed and commit, but later the row is DELETEd by you or another session.
Auto-inc values are not returned to any kind of queue, because other concurrent sessions might have generated further id values in the meantime. It's not worth InnoDB maintaining a pool of unallocated id values, because that pool could become huge and wasteful.
Also, it might be appropriate to "lose" an ID value, or else someone would think the row they meant to DELETE somehow came back.
Thanks.... with your explanation, I was able to know what to search for and I found a Percona´s article mentioning this type of behavior and presenting a suggestion of how to workaround -- percona.com/blog/2011/11/29/…
– Magno Alberto
Mar 8 at 13:19
Thanks, Raymond. You are very sure. When I read this article for the first time, I had read very quickly and, in fact, the idea of the article is precisely not to generate a "hole" during the auto-increment using INSERT IGNORE, but even so, it helped to understand the InnoDB, but with the help of the article, I would not start creating crazy stuff.
– Magno Alberto
Mar 10 at 10:28
@MagnoAlberto - Please provide link to the article; it is wrong in some, perhaps all, situations.INSERT IGNORE
allocates the id before discovering whether theINSERT
will succeed. Ditto for IODKU.REPLACE
simplyDELETEs
, thenINSERTs
, so it will normally always burn an id.
– Rick James
Mar 16 at 19:14
add a comment |
To summarize the reason for this statement, it is a scheduling system
that I have that uses this statement to create the calendar table.
Not totally in the scope of your question which was about missing id's.
But there are better ways to generate numbers and or calendar tables then repeating a INSERT ... SELECT
multiple times.
All approaches can be used directly JOINed with a other table or used to fill up a (indexed) (temporary) table
For number generating.
If you MariaDB/MySQL version supports windows functions
SET SESSION cte_max_recursion_depth = 5000;
WITH RECURSIVE number_generator(number) AS (
SELECT 0
UNION ALL
SELECT number + 1 FROM number_generator
WHERE number BETWEEN 0 AND 4096
)
SELECT * FROM number_generator
For MariaDB/MySQL which does not support window functions.
SELECT
number_generator.number
FROM (
SELECT
@row := @row + 1 AS number
FROM (
SELECT 0 UNION SELECT 1 UNION SELECT 2 UNION SELECT 3 UNION SELECT 4 UNION SELECT 5 UNION SELECT 6 UNION SELECT 7 UNION SELECT 8 UNION SELECT 9
) row1
CROSS JOIN (
SELECT 0 UNION SELECT 1 UNION SELECT 2 UNION SELECT 3 UNION SELECT 4 UNION SELECT 5 UNION SELECT 6 UNION SELECT 7 UNION SELECT 8 UNION SELECT 9
) row2
CROSS JOIN (
SELECT 0 UNION SELECT 1 UNION SELECT 2 UNION SELECT 3 UNION SELECT 4 UNION SELECT 5 UNION SELECT 6 UNION SELECT 7 UNION SELECT 8 UNION SELECT 9
) row3
CROSS JOIN (
SELECT 0 UNION SELECT 1 UNION SELECT 2 UNION SELECT 3 UNION SELECT 4 UNION SELECT 5 UNION SELECT 6 UNION SELECT 7 UNION SELECT 8 UNION SELECT 9
) row4
CROSS JOIN (
SELECT @row := -1
) init_user_params
) AS number_generator
WHERE
number_generator.number BETWEEN 0 AND 4096
ORDER BY
number_generator.number ASC
For generating a calendar
If you MariaDB/MySQL version supports windows functions
SET SESSION cte_max_recursion_depth = 5000;
WITH RECURSIVE number_generator(number) AS (
SELECT 0
UNION ALL
SELECT number + 1 FROM number_generator
WHERE number BETWEEN 0 AND 4096
)
SELECT CURRENT_DATE + INTERVAL number_generator.number DAY FROM number_generator
For MariaDB/MySQL which does not support window functions.
SELECT
CURRENT_DATE + INTERVAL number_generator.number DAY
FROM (
SELECT
@row := @row + 1 AS number
FROM (
SELECT 0 UNION SELECT 1 UNION SELECT 2 UNION SELECT 3 UNION SELECT 4 UNION SELECT 5 UNION SELECT 6 UNION SELECT 7 UNION SELECT 8 UNION SELECT 9
) row1
CROSS JOIN (
SELECT 0 UNION SELECT 1 UNION SELECT 2 UNION SELECT 3 UNION SELECT 4 UNION SELECT 5 UNION SELECT 6 UNION SELECT 7 UNION SELECT 8 UNION SELECT 9
) row2
CROSS JOIN (
SELECT 0 UNION SELECT 1 UNION SELECT 2 UNION SELECT 3 UNION SELECT 4 UNION SELECT 5 UNION SELECT 6 UNION SELECT 7 UNION SELECT 8 UNION SELECT 9
) row3
CROSS JOIN (
SELECT 0 UNION SELECT 1 UNION SELECT 2 UNION SELECT 3 UNION SELECT 4 UNION SELECT 5 UNION SELECT 6 UNION SELECT 7 UNION SELECT 8 UNION SELECT 9
) row4
CROSS JOIN (
SELECT @row := -1
) init_user_params
) AS number_generator
WHERE
number_generator.number BETWEEN 0 AND 4096
ORDER BY
number_generator.number ASC
The CURRENT_DATE
is just a example you can also use a fixed date in the past or future as example you can use '2019-03-01'
.
Also the + INTERVAL number_generator.number DAY
can also use a negative to generate a list into the past from that date and other values then DAY
if you want monthes you can use MONTH
, want years you use YEAR
1
If you are using MariaDB, simply use a "sequence" table, such asseq_0_to_4096
.
– Rick James
Mar 16 at 19:15
"If you are using MariaDB, simply use a "sequence" table, such as seq_0_to_4096." Can be a option @RickJames But the sequence engine is not enabled by defualt on all MariaDB versions which i think you meant with "sequence" table, such as seq_0_to_4096, it is enabled from MariaDB 10.1..
– Raymond Nijland
Mar 16 at 21:16
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55063401%2fmariadb-innodb-skipping-the-number-sequence-while-creating-incremental-records%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
The auto_increment mechanism is required to generate unique values, that are greater than any value it has generated previously. It does not guarantee to generate consecutive values.
There's some discussion about it here: https://bugs.mysql.com/bug.php?id=57643
There is little importance in generating consecutive values faithfully, because any value could be "lost" for other reasons:
- Your INSERT fails, for example because of violating a constraint like UNIQUE KEY or FOREIGN KEY.
- You roll back the transaction for your INSERT.
- You succeed and commit, but later the row is DELETEd by you or another session.
Auto-inc values are not returned to any kind of queue, because other concurrent sessions might have generated further id values in the meantime. It's not worth InnoDB maintaining a pool of unallocated id values, because that pool could become huge and wasteful.
Also, it might be appropriate to "lose" an ID value, or else someone would think the row they meant to DELETE somehow came back.
Thanks.... with your explanation, I was able to know what to search for and I found a Percona´s article mentioning this type of behavior and presenting a suggestion of how to workaround -- percona.com/blog/2011/11/29/…
– Magno Alberto
Mar 8 at 13:19
Thanks, Raymond. You are very sure. When I read this article for the first time, I had read very quickly and, in fact, the idea of the article is precisely not to generate a "hole" during the auto-increment using INSERT IGNORE, but even so, it helped to understand the InnoDB, but with the help of the article, I would not start creating crazy stuff.
– Magno Alberto
Mar 10 at 10:28
@MagnoAlberto - Please provide link to the article; it is wrong in some, perhaps all, situations.INSERT IGNORE
allocates the id before discovering whether theINSERT
will succeed. Ditto for IODKU.REPLACE
simplyDELETEs
, thenINSERTs
, so it will normally always burn an id.
– Rick James
Mar 16 at 19:14
add a comment |
The auto_increment mechanism is required to generate unique values, that are greater than any value it has generated previously. It does not guarantee to generate consecutive values.
There's some discussion about it here: https://bugs.mysql.com/bug.php?id=57643
There is little importance in generating consecutive values faithfully, because any value could be "lost" for other reasons:
- Your INSERT fails, for example because of violating a constraint like UNIQUE KEY or FOREIGN KEY.
- You roll back the transaction for your INSERT.
- You succeed and commit, but later the row is DELETEd by you or another session.
Auto-inc values are not returned to any kind of queue, because other concurrent sessions might have generated further id values in the meantime. It's not worth InnoDB maintaining a pool of unallocated id values, because that pool could become huge and wasteful.
Also, it might be appropriate to "lose" an ID value, or else someone would think the row they meant to DELETE somehow came back.
Thanks.... with your explanation, I was able to know what to search for and I found a Percona´s article mentioning this type of behavior and presenting a suggestion of how to workaround -- percona.com/blog/2011/11/29/…
– Magno Alberto
Mar 8 at 13:19
Thanks, Raymond. You are very sure. When I read this article for the first time, I had read very quickly and, in fact, the idea of the article is precisely not to generate a "hole" during the auto-increment using INSERT IGNORE, but even so, it helped to understand the InnoDB, but with the help of the article, I would not start creating crazy stuff.
– Magno Alberto
Mar 10 at 10:28
@MagnoAlberto - Please provide link to the article; it is wrong in some, perhaps all, situations.INSERT IGNORE
allocates the id before discovering whether theINSERT
will succeed. Ditto for IODKU.REPLACE
simplyDELETEs
, thenINSERTs
, so it will normally always burn an id.
– Rick James
Mar 16 at 19:14
add a comment |
The auto_increment mechanism is required to generate unique values, that are greater than any value it has generated previously. It does not guarantee to generate consecutive values.
There's some discussion about it here: https://bugs.mysql.com/bug.php?id=57643
There is little importance in generating consecutive values faithfully, because any value could be "lost" for other reasons:
- Your INSERT fails, for example because of violating a constraint like UNIQUE KEY or FOREIGN KEY.
- You roll back the transaction for your INSERT.
- You succeed and commit, but later the row is DELETEd by you or another session.
Auto-inc values are not returned to any kind of queue, because other concurrent sessions might have generated further id values in the meantime. It's not worth InnoDB maintaining a pool of unallocated id values, because that pool could become huge and wasteful.
Also, it might be appropriate to "lose" an ID value, or else someone would think the row they meant to DELETE somehow came back.
The auto_increment mechanism is required to generate unique values, that are greater than any value it has generated previously. It does not guarantee to generate consecutive values.
There's some discussion about it here: https://bugs.mysql.com/bug.php?id=57643
There is little importance in generating consecutive values faithfully, because any value could be "lost" for other reasons:
- Your INSERT fails, for example because of violating a constraint like UNIQUE KEY or FOREIGN KEY.
- You roll back the transaction for your INSERT.
- You succeed and commit, but later the row is DELETEd by you or another session.
Auto-inc values are not returned to any kind of queue, because other concurrent sessions might have generated further id values in the meantime. It's not worth InnoDB maintaining a pool of unallocated id values, because that pool could become huge and wasteful.
Also, it might be appropriate to "lose" an ID value, or else someone would think the row they meant to DELETE somehow came back.
answered Mar 8 at 12:58
Bill KarwinBill Karwin
386k64521680
386k64521680
Thanks.... with your explanation, I was able to know what to search for and I found a Percona´s article mentioning this type of behavior and presenting a suggestion of how to workaround -- percona.com/blog/2011/11/29/…
– Magno Alberto
Mar 8 at 13:19
Thanks, Raymond. You are very sure. When I read this article for the first time, I had read very quickly and, in fact, the idea of the article is precisely not to generate a "hole" during the auto-increment using INSERT IGNORE, but even so, it helped to understand the InnoDB, but with the help of the article, I would not start creating crazy stuff.
– Magno Alberto
Mar 10 at 10:28
@MagnoAlberto - Please provide link to the article; it is wrong in some, perhaps all, situations.INSERT IGNORE
allocates the id before discovering whether theINSERT
will succeed. Ditto for IODKU.REPLACE
simplyDELETEs
, thenINSERTs
, so it will normally always burn an id.
– Rick James
Mar 16 at 19:14
add a comment |
Thanks.... with your explanation, I was able to know what to search for and I found a Percona´s article mentioning this type of behavior and presenting a suggestion of how to workaround -- percona.com/blog/2011/11/29/…
– Magno Alberto
Mar 8 at 13:19
Thanks, Raymond. You are very sure. When I read this article for the first time, I had read very quickly and, in fact, the idea of the article is precisely not to generate a "hole" during the auto-increment using INSERT IGNORE, but even so, it helped to understand the InnoDB, but with the help of the article, I would not start creating crazy stuff.
– Magno Alberto
Mar 10 at 10:28
@MagnoAlberto - Please provide link to the article; it is wrong in some, perhaps all, situations.INSERT IGNORE
allocates the id before discovering whether theINSERT
will succeed. Ditto for IODKU.REPLACE
simplyDELETEs
, thenINSERTs
, so it will normally always burn an id.
– Rick James
Mar 16 at 19:14
Thanks.... with your explanation, I was able to know what to search for and I found a Percona´s article mentioning this type of behavior and presenting a suggestion of how to workaround -- percona.com/blog/2011/11/29/…
– Magno Alberto
Mar 8 at 13:19
Thanks.... with your explanation, I was able to know what to search for and I found a Percona´s article mentioning this type of behavior and presenting a suggestion of how to workaround -- percona.com/blog/2011/11/29/…
– Magno Alberto
Mar 8 at 13:19
Thanks, Raymond. You are very sure. When I read this article for the first time, I had read very quickly and, in fact, the idea of the article is precisely not to generate a "hole" during the auto-increment using INSERT IGNORE, but even so, it helped to understand the InnoDB, but with the help of the article, I would not start creating crazy stuff.
– Magno Alberto
Mar 10 at 10:28
Thanks, Raymond. You are very sure. When I read this article for the first time, I had read very quickly and, in fact, the idea of the article is precisely not to generate a "hole" during the auto-increment using INSERT IGNORE, but even so, it helped to understand the InnoDB, but with the help of the article, I would not start creating crazy stuff.
– Magno Alberto
Mar 10 at 10:28
@MagnoAlberto - Please provide link to the article; it is wrong in some, perhaps all, situations.
INSERT IGNORE
allocates the id before discovering whether the INSERT
will succeed. Ditto for IODKU. REPLACE
simply DELETEs
, then INSERTs
, so it will normally always burn an id.– Rick James
Mar 16 at 19:14
@MagnoAlberto - Please provide link to the article; it is wrong in some, perhaps all, situations.
INSERT IGNORE
allocates the id before discovering whether the INSERT
will succeed. Ditto for IODKU. REPLACE
simply DELETEs
, then INSERTs
, so it will normally always burn an id.– Rick James
Mar 16 at 19:14
add a comment |
To summarize the reason for this statement, it is a scheduling system
that I have that uses this statement to create the calendar table.
Not totally in the scope of your question which was about missing id's.
But there are better ways to generate numbers and or calendar tables then repeating a INSERT ... SELECT
multiple times.
All approaches can be used directly JOINed with a other table or used to fill up a (indexed) (temporary) table
For number generating.
If you MariaDB/MySQL version supports windows functions
SET SESSION cte_max_recursion_depth = 5000;
WITH RECURSIVE number_generator(number) AS (
SELECT 0
UNION ALL
SELECT number + 1 FROM number_generator
WHERE number BETWEEN 0 AND 4096
)
SELECT * FROM number_generator
For MariaDB/MySQL which does not support window functions.
SELECT
number_generator.number
FROM (
SELECT
@row := @row + 1 AS number
FROM (
SELECT 0 UNION SELECT 1 UNION SELECT 2 UNION SELECT 3 UNION SELECT 4 UNION SELECT 5 UNION SELECT 6 UNION SELECT 7 UNION SELECT 8 UNION SELECT 9
) row1
CROSS JOIN (
SELECT 0 UNION SELECT 1 UNION SELECT 2 UNION SELECT 3 UNION SELECT 4 UNION SELECT 5 UNION SELECT 6 UNION SELECT 7 UNION SELECT 8 UNION SELECT 9
) row2
CROSS JOIN (
SELECT 0 UNION SELECT 1 UNION SELECT 2 UNION SELECT 3 UNION SELECT 4 UNION SELECT 5 UNION SELECT 6 UNION SELECT 7 UNION SELECT 8 UNION SELECT 9
) row3
CROSS JOIN (
SELECT 0 UNION SELECT 1 UNION SELECT 2 UNION SELECT 3 UNION SELECT 4 UNION SELECT 5 UNION SELECT 6 UNION SELECT 7 UNION SELECT 8 UNION SELECT 9
) row4
CROSS JOIN (
SELECT @row := -1
) init_user_params
) AS number_generator
WHERE
number_generator.number BETWEEN 0 AND 4096
ORDER BY
number_generator.number ASC
For generating a calendar
If you MariaDB/MySQL version supports windows functions
SET SESSION cte_max_recursion_depth = 5000;
WITH RECURSIVE number_generator(number) AS (
SELECT 0
UNION ALL
SELECT number + 1 FROM number_generator
WHERE number BETWEEN 0 AND 4096
)
SELECT CURRENT_DATE + INTERVAL number_generator.number DAY FROM number_generator
For MariaDB/MySQL which does not support window functions.
SELECT
CURRENT_DATE + INTERVAL number_generator.number DAY
FROM (
SELECT
@row := @row + 1 AS number
FROM (
SELECT 0 UNION SELECT 1 UNION SELECT 2 UNION SELECT 3 UNION SELECT 4 UNION SELECT 5 UNION SELECT 6 UNION SELECT 7 UNION SELECT 8 UNION SELECT 9
) row1
CROSS JOIN (
SELECT 0 UNION SELECT 1 UNION SELECT 2 UNION SELECT 3 UNION SELECT 4 UNION SELECT 5 UNION SELECT 6 UNION SELECT 7 UNION SELECT 8 UNION SELECT 9
) row2
CROSS JOIN (
SELECT 0 UNION SELECT 1 UNION SELECT 2 UNION SELECT 3 UNION SELECT 4 UNION SELECT 5 UNION SELECT 6 UNION SELECT 7 UNION SELECT 8 UNION SELECT 9
) row3
CROSS JOIN (
SELECT 0 UNION SELECT 1 UNION SELECT 2 UNION SELECT 3 UNION SELECT 4 UNION SELECT 5 UNION SELECT 6 UNION SELECT 7 UNION SELECT 8 UNION SELECT 9
) row4
CROSS JOIN (
SELECT @row := -1
) init_user_params
) AS number_generator
WHERE
number_generator.number BETWEEN 0 AND 4096
ORDER BY
number_generator.number ASC
The CURRENT_DATE
is just a example you can also use a fixed date in the past or future as example you can use '2019-03-01'
.
Also the + INTERVAL number_generator.number DAY
can also use a negative to generate a list into the past from that date and other values then DAY
if you want monthes you can use MONTH
, want years you use YEAR
1
If you are using MariaDB, simply use a "sequence" table, such asseq_0_to_4096
.
– Rick James
Mar 16 at 19:15
"If you are using MariaDB, simply use a "sequence" table, such as seq_0_to_4096." Can be a option @RickJames But the sequence engine is not enabled by defualt on all MariaDB versions which i think you meant with "sequence" table, such as seq_0_to_4096, it is enabled from MariaDB 10.1..
– Raymond Nijland
Mar 16 at 21:16
add a comment |
To summarize the reason for this statement, it is a scheduling system
that I have that uses this statement to create the calendar table.
Not totally in the scope of your question which was about missing id's.
But there are better ways to generate numbers and or calendar tables then repeating a INSERT ... SELECT
multiple times.
All approaches can be used directly JOINed with a other table or used to fill up a (indexed) (temporary) table
For number generating.
If you MariaDB/MySQL version supports windows functions
SET SESSION cte_max_recursion_depth = 5000;
WITH RECURSIVE number_generator(number) AS (
SELECT 0
UNION ALL
SELECT number + 1 FROM number_generator
WHERE number BETWEEN 0 AND 4096
)
SELECT * FROM number_generator
For MariaDB/MySQL which does not support window functions.
SELECT
number_generator.number
FROM (
SELECT
@row := @row + 1 AS number
FROM (
SELECT 0 UNION SELECT 1 UNION SELECT 2 UNION SELECT 3 UNION SELECT 4 UNION SELECT 5 UNION SELECT 6 UNION SELECT 7 UNION SELECT 8 UNION SELECT 9
) row1
CROSS JOIN (
SELECT 0 UNION SELECT 1 UNION SELECT 2 UNION SELECT 3 UNION SELECT 4 UNION SELECT 5 UNION SELECT 6 UNION SELECT 7 UNION SELECT 8 UNION SELECT 9
) row2
CROSS JOIN (
SELECT 0 UNION SELECT 1 UNION SELECT 2 UNION SELECT 3 UNION SELECT 4 UNION SELECT 5 UNION SELECT 6 UNION SELECT 7 UNION SELECT 8 UNION SELECT 9
) row3
CROSS JOIN (
SELECT 0 UNION SELECT 1 UNION SELECT 2 UNION SELECT 3 UNION SELECT 4 UNION SELECT 5 UNION SELECT 6 UNION SELECT 7 UNION SELECT 8 UNION SELECT 9
) row4
CROSS JOIN (
SELECT @row := -1
) init_user_params
) AS number_generator
WHERE
number_generator.number BETWEEN 0 AND 4096
ORDER BY
number_generator.number ASC
For generating a calendar
If you MariaDB/MySQL version supports windows functions
SET SESSION cte_max_recursion_depth = 5000;
WITH RECURSIVE number_generator(number) AS (
SELECT 0
UNION ALL
SELECT number + 1 FROM number_generator
WHERE number BETWEEN 0 AND 4096
)
SELECT CURRENT_DATE + INTERVAL number_generator.number DAY FROM number_generator
For MariaDB/MySQL which does not support window functions.
SELECT
CURRENT_DATE + INTERVAL number_generator.number DAY
FROM (
SELECT
@row := @row + 1 AS number
FROM (
SELECT 0 UNION SELECT 1 UNION SELECT 2 UNION SELECT 3 UNION SELECT 4 UNION SELECT 5 UNION SELECT 6 UNION SELECT 7 UNION SELECT 8 UNION SELECT 9
) row1
CROSS JOIN (
SELECT 0 UNION SELECT 1 UNION SELECT 2 UNION SELECT 3 UNION SELECT 4 UNION SELECT 5 UNION SELECT 6 UNION SELECT 7 UNION SELECT 8 UNION SELECT 9
) row2
CROSS JOIN (
SELECT 0 UNION SELECT 1 UNION SELECT 2 UNION SELECT 3 UNION SELECT 4 UNION SELECT 5 UNION SELECT 6 UNION SELECT 7 UNION SELECT 8 UNION SELECT 9
) row3
CROSS JOIN (
SELECT 0 UNION SELECT 1 UNION SELECT 2 UNION SELECT 3 UNION SELECT 4 UNION SELECT 5 UNION SELECT 6 UNION SELECT 7 UNION SELECT 8 UNION SELECT 9
) row4
CROSS JOIN (
SELECT @row := -1
) init_user_params
) AS number_generator
WHERE
number_generator.number BETWEEN 0 AND 4096
ORDER BY
number_generator.number ASC
The CURRENT_DATE
is just a example you can also use a fixed date in the past or future as example you can use '2019-03-01'
.
Also the + INTERVAL number_generator.number DAY
can also use a negative to generate a list into the past from that date and other values then DAY
if you want monthes you can use MONTH
, want years you use YEAR
1
If you are using MariaDB, simply use a "sequence" table, such asseq_0_to_4096
.
– Rick James
Mar 16 at 19:15
"If you are using MariaDB, simply use a "sequence" table, such as seq_0_to_4096." Can be a option @RickJames But the sequence engine is not enabled by defualt on all MariaDB versions which i think you meant with "sequence" table, such as seq_0_to_4096, it is enabled from MariaDB 10.1..
– Raymond Nijland
Mar 16 at 21:16
add a comment |
To summarize the reason for this statement, it is a scheduling system
that I have that uses this statement to create the calendar table.
Not totally in the scope of your question which was about missing id's.
But there are better ways to generate numbers and or calendar tables then repeating a INSERT ... SELECT
multiple times.
All approaches can be used directly JOINed with a other table or used to fill up a (indexed) (temporary) table
For number generating.
If you MariaDB/MySQL version supports windows functions
SET SESSION cte_max_recursion_depth = 5000;
WITH RECURSIVE number_generator(number) AS (
SELECT 0
UNION ALL
SELECT number + 1 FROM number_generator
WHERE number BETWEEN 0 AND 4096
)
SELECT * FROM number_generator
For MariaDB/MySQL which does not support window functions.
SELECT
number_generator.number
FROM (
SELECT
@row := @row + 1 AS number
FROM (
SELECT 0 UNION SELECT 1 UNION SELECT 2 UNION SELECT 3 UNION SELECT 4 UNION SELECT 5 UNION SELECT 6 UNION SELECT 7 UNION SELECT 8 UNION SELECT 9
) row1
CROSS JOIN (
SELECT 0 UNION SELECT 1 UNION SELECT 2 UNION SELECT 3 UNION SELECT 4 UNION SELECT 5 UNION SELECT 6 UNION SELECT 7 UNION SELECT 8 UNION SELECT 9
) row2
CROSS JOIN (
SELECT 0 UNION SELECT 1 UNION SELECT 2 UNION SELECT 3 UNION SELECT 4 UNION SELECT 5 UNION SELECT 6 UNION SELECT 7 UNION SELECT 8 UNION SELECT 9
) row3
CROSS JOIN (
SELECT 0 UNION SELECT 1 UNION SELECT 2 UNION SELECT 3 UNION SELECT 4 UNION SELECT 5 UNION SELECT 6 UNION SELECT 7 UNION SELECT 8 UNION SELECT 9
) row4
CROSS JOIN (
SELECT @row := -1
) init_user_params
) AS number_generator
WHERE
number_generator.number BETWEEN 0 AND 4096
ORDER BY
number_generator.number ASC
For generating a calendar
If you MariaDB/MySQL version supports windows functions
SET SESSION cte_max_recursion_depth = 5000;
WITH RECURSIVE number_generator(number) AS (
SELECT 0
UNION ALL
SELECT number + 1 FROM number_generator
WHERE number BETWEEN 0 AND 4096
)
SELECT CURRENT_DATE + INTERVAL number_generator.number DAY FROM number_generator
For MariaDB/MySQL which does not support window functions.
SELECT
CURRENT_DATE + INTERVAL number_generator.number DAY
FROM (
SELECT
@row := @row + 1 AS number
FROM (
SELECT 0 UNION SELECT 1 UNION SELECT 2 UNION SELECT 3 UNION SELECT 4 UNION SELECT 5 UNION SELECT 6 UNION SELECT 7 UNION SELECT 8 UNION SELECT 9
) row1
CROSS JOIN (
SELECT 0 UNION SELECT 1 UNION SELECT 2 UNION SELECT 3 UNION SELECT 4 UNION SELECT 5 UNION SELECT 6 UNION SELECT 7 UNION SELECT 8 UNION SELECT 9
) row2
CROSS JOIN (
SELECT 0 UNION SELECT 1 UNION SELECT 2 UNION SELECT 3 UNION SELECT 4 UNION SELECT 5 UNION SELECT 6 UNION SELECT 7 UNION SELECT 8 UNION SELECT 9
) row3
CROSS JOIN (
SELECT 0 UNION SELECT 1 UNION SELECT 2 UNION SELECT 3 UNION SELECT 4 UNION SELECT 5 UNION SELECT 6 UNION SELECT 7 UNION SELECT 8 UNION SELECT 9
) row4
CROSS JOIN (
SELECT @row := -1
) init_user_params
) AS number_generator
WHERE
number_generator.number BETWEEN 0 AND 4096
ORDER BY
number_generator.number ASC
The CURRENT_DATE
is just a example you can also use a fixed date in the past or future as example you can use '2019-03-01'
.
Also the + INTERVAL number_generator.number DAY
can also use a negative to generate a list into the past from that date and other values then DAY
if you want monthes you can use MONTH
, want years you use YEAR
To summarize the reason for this statement, it is a scheduling system
that I have that uses this statement to create the calendar table.
Not totally in the scope of your question which was about missing id's.
But there are better ways to generate numbers and or calendar tables then repeating a INSERT ... SELECT
multiple times.
All approaches can be used directly JOINed with a other table or used to fill up a (indexed) (temporary) table
For number generating.
If you MariaDB/MySQL version supports windows functions
SET SESSION cte_max_recursion_depth = 5000;
WITH RECURSIVE number_generator(number) AS (
SELECT 0
UNION ALL
SELECT number + 1 FROM number_generator
WHERE number BETWEEN 0 AND 4096
)
SELECT * FROM number_generator
For MariaDB/MySQL which does not support window functions.
SELECT
number_generator.number
FROM (
SELECT
@row := @row + 1 AS number
FROM (
SELECT 0 UNION SELECT 1 UNION SELECT 2 UNION SELECT 3 UNION SELECT 4 UNION SELECT 5 UNION SELECT 6 UNION SELECT 7 UNION SELECT 8 UNION SELECT 9
) row1
CROSS JOIN (
SELECT 0 UNION SELECT 1 UNION SELECT 2 UNION SELECT 3 UNION SELECT 4 UNION SELECT 5 UNION SELECT 6 UNION SELECT 7 UNION SELECT 8 UNION SELECT 9
) row2
CROSS JOIN (
SELECT 0 UNION SELECT 1 UNION SELECT 2 UNION SELECT 3 UNION SELECT 4 UNION SELECT 5 UNION SELECT 6 UNION SELECT 7 UNION SELECT 8 UNION SELECT 9
) row3
CROSS JOIN (
SELECT 0 UNION SELECT 1 UNION SELECT 2 UNION SELECT 3 UNION SELECT 4 UNION SELECT 5 UNION SELECT 6 UNION SELECT 7 UNION SELECT 8 UNION SELECT 9
) row4
CROSS JOIN (
SELECT @row := -1
) init_user_params
) AS number_generator
WHERE
number_generator.number BETWEEN 0 AND 4096
ORDER BY
number_generator.number ASC
For generating a calendar
If you MariaDB/MySQL version supports windows functions
SET SESSION cte_max_recursion_depth = 5000;
WITH RECURSIVE number_generator(number) AS (
SELECT 0
UNION ALL
SELECT number + 1 FROM number_generator
WHERE number BETWEEN 0 AND 4096
)
SELECT CURRENT_DATE + INTERVAL number_generator.number DAY FROM number_generator
For MariaDB/MySQL which does not support window functions.
SELECT
CURRENT_DATE + INTERVAL number_generator.number DAY
FROM (
SELECT
@row := @row + 1 AS number
FROM (
SELECT 0 UNION SELECT 1 UNION SELECT 2 UNION SELECT 3 UNION SELECT 4 UNION SELECT 5 UNION SELECT 6 UNION SELECT 7 UNION SELECT 8 UNION SELECT 9
) row1
CROSS JOIN (
SELECT 0 UNION SELECT 1 UNION SELECT 2 UNION SELECT 3 UNION SELECT 4 UNION SELECT 5 UNION SELECT 6 UNION SELECT 7 UNION SELECT 8 UNION SELECT 9
) row2
CROSS JOIN (
SELECT 0 UNION SELECT 1 UNION SELECT 2 UNION SELECT 3 UNION SELECT 4 UNION SELECT 5 UNION SELECT 6 UNION SELECT 7 UNION SELECT 8 UNION SELECT 9
) row3
CROSS JOIN (
SELECT 0 UNION SELECT 1 UNION SELECT 2 UNION SELECT 3 UNION SELECT 4 UNION SELECT 5 UNION SELECT 6 UNION SELECT 7 UNION SELECT 8 UNION SELECT 9
) row4
CROSS JOIN (
SELECT @row := -1
) init_user_params
) AS number_generator
WHERE
number_generator.number BETWEEN 0 AND 4096
ORDER BY
number_generator.number ASC
The CURRENT_DATE
is just a example you can also use a fixed date in the past or future as example you can use '2019-03-01'
.
Also the + INTERVAL number_generator.number DAY
can also use a negative to generate a list into the past from that date and other values then DAY
if you want monthes you can use MONTH
, want years you use YEAR
edited Mar 8 at 13:41
answered Mar 8 at 13:36
Raymond NijlandRaymond Nijland
9,04621330
9,04621330
1
If you are using MariaDB, simply use a "sequence" table, such asseq_0_to_4096
.
– Rick James
Mar 16 at 19:15
"If you are using MariaDB, simply use a "sequence" table, such as seq_0_to_4096." Can be a option @RickJames But the sequence engine is not enabled by defualt on all MariaDB versions which i think you meant with "sequence" table, such as seq_0_to_4096, it is enabled from MariaDB 10.1..
– Raymond Nijland
Mar 16 at 21:16
add a comment |
1
If you are using MariaDB, simply use a "sequence" table, such asseq_0_to_4096
.
– Rick James
Mar 16 at 19:15
"If you are using MariaDB, simply use a "sequence" table, such as seq_0_to_4096." Can be a option @RickJames But the sequence engine is not enabled by defualt on all MariaDB versions which i think you meant with "sequence" table, such as seq_0_to_4096, it is enabled from MariaDB 10.1..
– Raymond Nijland
Mar 16 at 21:16
1
1
If you are using MariaDB, simply use a "sequence" table, such as
seq_0_to_4096
.– Rick James
Mar 16 at 19:15
If you are using MariaDB, simply use a "sequence" table, such as
seq_0_to_4096
.– Rick James
Mar 16 at 19:15
"If you are using MariaDB, simply use a "sequence" table, such as seq_0_to_4096." Can be a option @RickJames But the sequence engine is not enabled by defualt on all MariaDB versions which i think you meant with "sequence" table, such as seq_0_to_4096, it is enabled from MariaDB 10.1..
– Raymond Nijland
Mar 16 at 21:16
"If you are using MariaDB, simply use a "sequence" table, such as seq_0_to_4096." Can be a option @RickJames But the sequence engine is not enabled by defualt on all MariaDB versions which i think you meant with "sequence" table, such as seq_0_to_4096, it is enabled from MariaDB 10.1..
– Raymond Nijland
Mar 16 at 21:16
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55063401%2fmariadb-innodb-skipping-the-number-sequence-while-creating-incremental-records%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Could be an insert that was rolled back?
– Lasse Vågsæther Karlsen
Mar 8 at 12:38
This scheme is totally clean/new, nothing is accessing or writing on it. By your question, I do not know for some reason MariaDB itself is performing the rollback.
– Magno Alberto
Mar 8 at 12:42
This does not make sense. Have you tried to place all 34 INSERTs inside a single transaction ?
– IVO GELOV
Mar 8 at 12:45
Sorry, but I think that it is not relevant if it makes sense or not, since the statement works perfectly with MYISAM. But yes, I use this statement to create a loop in a single statement.
– Magno Alberto
Mar 8 at 12:47
Sometimes MySQL trips up. Don't worry about the missing numbers.
– Strawberry
Mar 8 at 12:50