Why with_lockmode will lock whole table for no record found?

25 views
Skip to first unread message

Jimmy

unread,
Oct 23, 2012, 9:38:13 AM10/23/12
to sqlal...@googlegroups.com
I'm using sqlalchemy to access MySQL (through Innodb). The query I use for lock is:

create_engine('mysql+mysqldb://root:root@localhost/tmp_db')
db_session = scoped_session(sessionmaker(bind=engine))
db_session.query(Transaction).filter_by(key='abc').with_lockmode('update').first()

There is no key = 'abc' found in table. However, the whole transaction table is locked by this (I checked from show engine innodb status). Other db session can't access any row in the table, and get timeout error. 

Why the whole table is locked for no record found when using with_lockmode?




Reply all
Reply to author
Forward
0 new messages