在mysql中是否有一种方法可以找到某个查询运行时被锁定的行数?例如。对于查询,锁定的行数是多少: -
UPDATE xyz SET ARCHIVE = 1 , LAST_MODIFIED = CURRENT_TIMESTAMP WHERE ID = '123' AND ARCHIVE = 0;
假设在这种情况下,ID上有索引,Archive是主键的一部分。
答案 0 :(得分:1)
BEGIN;
# lock
UPDATE xyz SET ARCHIVE = 1 , LAST_MODIFIED = CURRENT_TIMESTAMP WHERE ID = '123' AND ARCHIVE = 0;
# returns locked rows (X)
SELECT trx_rows_locked FROM information_schema.innodb_trx;
# release
COMMIT;