[MDEV-20357] Strange auto_increment counter setting changes on direct upgrade from 10.1 to 10.3 Created: 2019-08-15  Updated: 2020-04-24  Resolved: 2019-09-23

Status: Closed
Project: MariaDB Server
Component/s: Storage Engine - InnoDB
Affects Version/s: 10.3.17
Fix Version/s: N/A

Type: Bug Priority: Major
Reporter: Hartmut Holzgraefe Assignee: Marko Mäkelä
Resolution: Cannot Reproduce Votes: 0
Labels: need_feedback

Issue Links:
PartOf
is part of MDEV-22357 Clearing InnoDB autoincrement counter... Open
Relates
relates to MDEV-6076 Persistent AUTO_INCREMENT for InnoDB Closed
relates to MDEV-22167 auto_increment counters changed weird... Closed

 Description   

After a direct upgrade from 10.1.40 to 10.3.17, SHOW CREATE TABLE output in mysqldump shows correct AUTO_INCREMENT counter values on the first two tables, but then flips to

Before the upgrade:

ENGINE=InnoDB AUTO_INCREMENT=2284
ENGINE=InnoDB AUTO_INCREMENT=4763
ENGINE=InnoDB AUTO_INCREMENT=1621982
ENGINE=InnoDB AUTO_INCREMENT=3
ENGINE=InnoDB AUTO_INCREMENT=1395246
ENGINE=InnoDB AUTO_INCREMENT=927
...

becomes this after upgrade:

ENGINE=InnoDB AUTO_INCREMENT=2284
ENGINE=InnoDB AUTO_INCREMENT=4763
ENGINE=InnoDB AUTO_INCREMENT=4784423209
ENGINE=InnoDB AUTO_INCREMENT=4784423220
ENGINE=InnoDB AUTO_INCREMENT=4784423231
ENGINE=InnoDB AUTO_INCREMENT=4784423242
...

Note how starting with the third auto-inrement table the counter becomes way higher then originally, and then gets incremented by 11 for each following table.



 Comments   
Comment by Marko Mäkelä [ 2019-08-16 ]

hholzgra, I think that this should affect an upgrade to 10.2 already, due to MDEV-6076.

I think that the plausible explanation is that the PAGE_MAX_AUTOINC field in some clustered index root pages was not 0, but garbage, before the upgrade. MDEV-6076 repurposed the field PAGE_MAX_TRX_ID, which was previously only used on secondary index leaf pages. Before a bug fix in MySQL 5.1.48, InnoDB could write garbage to unused data fields; since then, such fields are always written as 0.

It should be possible to reset the AUTO_INCREMENT value by a statement like this:

ALTER TABLE t AUTO_INCREMENT = 1;

This should reset the counter to a value that is not smaller than the current maximum in the table.

I will try to double-check if the PAGE_MAX_TRX_ID was always zero-initialized. I seem to remember that I concluded during MDEV-6076 development that it is the case.

Comment by Marko Mäkelä [ 2019-08-16 ]

As a starting point, I checked out the MySQL 5.1.47 source code. Side note: I had forgotten a glaring bug: changes of the PAGE_MAX_TRX_ID were not being redo-logged in the built-in InnoDB of MySQL 5.1. It was only fixed in the InnoDB Plugin, which became the basis of the InnoDB in the 5.5 release.

In MySQL 5.1.47, page_create() (which is invoked for creating B-tree pages) did always initialize the PAGE_MAX_TRX_ID, so we do know that whenever the field was unused on a B-tree page, it must have been 0:

	page_set_max_trx_id(page, ut_dulint_zero);

This call was present in the very beginning of the InnoDB revision history.

hholzgra, I am afraid that I cannot explain the observed anomaly with a software bug. I would need more information at the very least.

Comment by Sergei Golubchik [ 2019-09-16 ]

hholzgra, any chance you could provide more infore or should we close it?

Generated at Thu Feb 08 08:58:51 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.