130514 12:03:43*** (1) TRANSACTION:TRANSACTION 1080BB, ACTIVE 0 sec starting index readmysql tables in use 1, locked 1LOCK WAIT 3 lock struct(s), heap size 1248, 2 row lock(s)MySQL thread id 457519, OS thread handle 0x7f2d41256700, query id 24925233 10.4.12.82 clearwrite Searching rows for updateupdate js_tran_task set settle_time= DATE_ADD(create_time,INTERVAL 0 DAY) , settle_rule_id='CRJY106010113042616592600000004' , version_no=version_no+1 where rule_accpuid='PU010000000010137145' and aspservice_id='1000003' and status=1 and valid_status=1 and create_time>=STR_TO_DATE('2013-05-13 22:38:54','%Y-%m-%d %H:%i:%s') and create_time<STR_TO_DATE('2013-05-14 12:03:43','%Y-%m-%d %H:%i:%s') and settle_time=STR_TO_DATE('2032-01-01 00:00:00','%Y-%m-%d %H:%i:%s')*** (1) WAITING FOR THIS LOCK TO BE GRANTED:RECORD LOCKS space id 36 page no 2635 n bits 88 index `PRIMARY` of table `trade`.`js_tran_task` trx id 1080BB lock_mode X locks rec but not gap waiting*** (2) TRANSACTION:TRANSACTION 1080B8, ACTIVE 0 sec updating or deleting, thread declared inside InnoDB 499mysql tables in use 1, locked 13 lock struct(s), heap size 1248, 2 row lock(s), undo log entries 1MySQL thread id 457530, OS thread handle 0x7f2d40ec8700, query id 24925228 10.4.12.82 clearwrite Updatingupdate js_tran_task setstatus=3 ,tran_count    = tran_count + 1,result_code='0',update_time=now(),version_no    = version_no + 1where distribute_id='CDJY106492300000113051411573300000491'*** (2) HOLDS THE LOCK(S):RECORD LOCKS space id 36 page no 2635 n bits 88 index `PRIMARY` of table `trade`.`js_tran_task` trx id 1080B8 lock_mode X locks rec but not gap*** (2) WAITING FOR THIS LOCK TO BE GRANTED:RECORD LOCKS space id 36 page no 25 n bits 352 index `idx_status_stime_ctime` of table `trade`.`js_tran_task` trx id 1080B8 lock_mode X locks rec but not gap waiting*** WE ROLL BACK TRANSACTION (1)
可以保证这两个sql没有数据重复,sql2是根据主键,sql1结果不包括这条数据,
另外,为啥一个update还需要持有多个锁呢?