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?