MySQL InnoDB row_id boundary overflow verification method steps

MySQL InnoDB row_id boundary overflow verification method steps

background

I talked to my classmates about a boundary problem of row_id, and I will explain it in detail here.

If the InnoDB table does not define a primary key, a system default incrementing row_id (dict_sys->row_id) will be used as the primary key. Each time a row is inserted, add 1 and repeat the process until the maximum value is reached.

It should be noted that although dict_sys->row_id is defined as an unsigned long long, since this primary key value is only 6 bytes, the maximum value is 2^48. If row_id exceeds this value, it will still increase, but only the lower bits will be taken when writing, which can be considered as a modulo operation.

question

This involves a problem. In a long-running MySQL, if rows are frequently inserted and deleted (such as log tables), even if the final table size is not very large, row_id value reuse may still occur. And we know that as a primary key value, it cannot be repeated.

Suppose this happens. In a table, the row_id of a newly inserted row conflicts with the row_id of an older row. What will happen?

verify

In fact, only one conclusion is needed here. The purpose of this article is to discuss a verification method with you. With the above information, we can consider designing the following reproduction steps:

1) Create an empty table without a primary key

2) gdb sets dict_sys->row_id to 1

3) Insert several rows into an empty table

4) gdb sets dict_sys->row_id to 2^48

5) Insert several more rows

6) View the results

in conclusion

As you can see, rows (1) and (2) are overwritten.

A more reasonable solution would be to report a duplicate-key error, just like the auto-increment primary key in the MySQL table.

Summarize

The above is the full content of this article. I hope that the content of this article will have certain reference learning value for your study or work. Thank you for your support of 123WORDPRESS.COM.

You may also be interested in:
  • Analysis of the difference between Mysql InnoDB and MyISAM
  • How to get the height of MySQL innodb B+tree
  • Differences between MySQL MyISAM and InnoDB
  • Briefly describe the MySQL InnoDB storage engine
  • Detailed explanation of MySQL Innodb storage structure and storage of Null values
  • How to ensure transaction characteristics of MySQL InnoDB?
  • MySQL startup error InnoDB: Unable to lock/ibdata1 error
  • In-depth explanation of the locking mechanism in MySQL InnoDB
  • Detailed explanation of how MySQL (InnoDB) handles deadlocks
  • MySQL Learning (VII): Detailed Explanation of the Implementation Principle of Innodb Storage Engine Index
  • MySQL slow_log table cannot be modified to innodb engine detailed explanation
  • Summary of important components of MySQL InnoDB

<<:  Detailed graphic explanation of how to clear the keep-alive cache

>>:  How to clear the cache after using keep-alive in vue

Recommend

JavaScript Advanced Custom Exception

Table of contents 1. Concept 1.1 What are errors ...

Analysis of MySQL lock mechanism and usage

This article uses examples to illustrate the MySQ...

CSS beginner tutorial: background image fills the entire screen

If you want the entire interface to have a backgr...

Vue+element+oss realizes front-end fragment upload and breakpoint resume

Pure front-end implementation:切片上傳斷點續傳.斷點續傳needs ...

Detailed explanation of Vue3's sandbox mechanism

Table of contents Preface Browser compiled versio...

How to open external network access rights for mysql

As shown below: Mainly execute authorization comm...

Example operation MySQL short link

How to set up a MySQL short link 1. Check the mys...

Summary of basic knowledge and operations of MySQL database

This article uses examples to explain the basic k...

Several ways to solve CSS style conflicts (summary)

1. Refine the selector By using combinators, the ...

Web page creation for beginners: Learn to use HTML's hyperlink A tag

The hyperlink a tag represents a link point and i...

uniapp dynamic modification of element node style detailed explanation

Table of contents 1. Modify by binding the style ...

CentOS 7.x docker uses overlay2 storage method

Edit /etc/docker/daemon.json and add the followin...

Implementation of Docker cross-host network (overlay)

1. Docker cross-host communication Docker cross-h...

Docker enables seamless calling of shell commands between container and host

As shown below: nsenter -t 1 -m -u -n -i sh -c &q...