In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)05/31 Report--
This article shows you what the role of LAST_INSERT_ID () in mysql is. The content is concise and easy to understand. It will definitely brighten your eyes. I hope you can get something through the detailed introduction of this article.
First of all, let's take a look at the official saying of LAST_INSERT_ID () in mysql:
LAST_INSERT_ID () automatically returns the value that occurs in the first table set by the AUTO_INCREMENT column in the last INSERT or UPDATE query.
Considerations for MySQL's LAST_INSERT_ID:
First, the Connection object used by the query and the insert must be the same, otherwise the return value is unpredictable.
Second, LAST_INSERT_ID is table-independent. If you insert data into table an and then into table b, LAST_INSERT_ID returns the ID value of table b. Www.2cto.com
Third, if you insert multiple rows using an INSERT statement, LAST_INSERT_ID () returns only the value generated when the first row of data is inserted.
Fourth, if you use INSERT IGNORE and the record is ignored, the AUTO_INCREMENT counter does not increment, while LAST_INSERT_ID () returns 0, which reflects that no record has been inserted.
According to these four principles, the insertion growth value of the highly concurrent website visited by us is mainly related to the first rule and the second rule. That is, to ensure the correctness of the LAST_INSERT_ID, it must be the same connection, and the LAST_INSERT_ID must be executed immediately in the insert. So there may be a problem if the cache pool has a common connection, and multithreaded operations may also have problems when other insert is executed after the insert.
The php database connection itself is page-level, which ensures that there will be no buffer pool, and then the php page execution itself is single-threaded, which ensures that sequentially written LAST_INSERT_ID must be executed immediately after insert, and there will be no other insert execution in the middle. Www.2cto.com
To sum up, php's page-level, single-threaded LAST_INSERT_ID is naturally correct and has nothing to do with high concurrency. That is, in php, the LAST_INSERT_ID of mysql is always correct. If you use it casually, there will be no problem.
The above is what is the function of LAST_INSERT_ID () in mysql. Have you learned any knowledge or skills? If you want to learn more skills or enrich your knowledge reserve, you are welcome to follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.