![]() ![]() Id INT(10) unsigned PRIMARY KEY NOT NULL AUTO_INCREMENT,Ĭreated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL, >update() ĭDL for the tables: CREATE TABLE user_chat_messages TODO results in lock error if many messages are sent same time 'from_user_id' => $message->getFromUserId(), 'user_chat_id' => $message->getUserChatId(), $id = $this->db->table('user_chat_messages')->insertGetId([ Public function insertChatMessage(UserChatMessageEntity $message) : int Set `updated_at` = ' 08:33:14' where `id` = 1 Ībove is the raw query, but I do it in PHP Laravel Query Builder as follows: /** ![]() Insert into `user_chat_messages` (`user_chat_id`, `from_user_id`, `content`) I know that a lock is acquired for inserting/updating/deleting tables in MySql with InnoDB but still do not understand why the deadlock happens here and how to solve it in the most efficient way. ![]() Is there any way to solve this without locking the entire table ? (Want to try avoid table level locks) Why ? (The transaction aquires lock, right ?) If I execute the same query but without transaction block around it will work without error with many concurrent calls. SQLSTATE: Serialization failure: 1213 Deadlock found when trying to get lock try restarting transaction (SQL: update user_chats set updated_at = 10:07:13 where id = 1) If two requests are being done at the same time results in the following error pattern: I provide below the raw MySQL query and also the code in which I do that programatically. ![]()
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |