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

Flex layout achieves fixed number of rows per line + adaptive layout

This article introduces the flex layout to achiev...

How to write configuration files and use MyBatis simply

How to write configuration files and use MyBatis ...

Vue uses Canvas to generate random sized and non-overlapping circles

Table of contents Canvas related documents Effect...

How to use Nginx to realize the coexistence of multiple containers in the server

background There is a Tencent Linux cloud host, o...

JS implements click drop effect

js realizes the special effect of clicking and dr...

How to set up remote access to a server by specifying an IP address in Windows

We have many servers that are often interfered wi...

JavaScript Interview: How to implement array flattening method

Table of contents 1 What is array flattening? 2 A...

How to install MySQL and MariaDB in Docker

Relationship between MySQL and MariaDB MariaDB da...

Example code for text origami effect using CSS3

Preface This article mainly shares with you an ex...

js to achieve a simple magnifying glass effect

This article shares the specific code of js to ac...

Detailed explanation of the difference between flex and inline-flex in CSS

inline-flex is the same as inline-block. It is a ...