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

VMware Workstation virtual machine installation operation method

Virtual machines are very convenient testing soft...

Detailed explanation and summary of the URL for database connection

Detailed explanation and summary of the URL for d...

HTML weight loss Streamline HTML tags to create web pages

HTML 4 HTML (not XHTML), MIME type is text/html, ...

How to use native JS to implement touch sliding monitoring events

Preface I wrote a small demo today. There is a pa...

What are the new features of Apache Spark 2.4, which will be released in 2018?

This article is from the Apache Spark Meetup held...

MySQL account password modification method (summary)

Preface: In the daily use of the database, it is ...

Pure CSS to achieve the effect of picture blinds display example

First, let me show you the finished effect Main i...

Perfect solution for vertical centering of form elements

Copy code The code is as follows: <!DOCTYPE ht...

VMware Workstation 14 Pro installs CentOS 7.0

The specific method of installing CentOS 7.0 on V...

Tomcat maxPostSize setting implementation process analysis

1. Why set maxPostSize? The tomcat container has ...

In-depth analysis of MySQL deadlock issues

Preface If our business is at a very early stage ...

Advanced and summary of commonly used sql statements in MySQL database

This article uses examples to describe the common...

Solution to Linux server graphics card crash

When the resolution of the login interface is par...