Engine: MySQL 5.7 ( InnoDB )
Metadata about table:
Steps to reproduce
updatedAt
and createdAt
fields type from DATETIME
to DATETIME(3)
.Observable behaviour After this db restore from dump and applying of migration tests in our solution very frequently face deadlocks for indicies in this table.
We fixed this issue by making db dump with these changes, so migrations are not altering anything anymore.
Question: How indicies updates are executed - as part sql statements, which are finished (application code which awaits for them is finished with waiting and next code statements are executed)?
Our code is synchronous and awaits for places where we execute queries.
I think the answer to your question is that indexes are updated immediately. That is, if you INSERT/UPDATE/DELETE, the index is effectively updated before the query executed returns control to the client.
InnoDB does some other things in the background, but these are transparent to the client. The client's next SQL query can take advantage of the new index entries immediately, even though InnoDB take some time to merge those index entries into place. You can read more details about this here: https://dev.mysql.com/doc/refman/5.7/en/innodb-change-buffer.html
But I have a feeling that this is actually not the solution to the locking problems you describe.