[Sqlalchemy-tickets] Issue #3270: in the loop of large quantity query result, update operation cost
Brought to you by:
zzzeek
|
From: awanabe <iss...@bi...> - 2014-12-10 13:56:02
|
New issue 3270: in the loop of large quantity query result, update operation costs strange time https://bitbucket.org/zzzeek/sqlalchemy/issue/3270/in-the-loop-of-large-quantity-query-result awanabe: When I query a large quantity records, then loop the result. if I update one record, it will cost a lot time. ``` _users = db.session.query(WxUser).limit(10000).all() for _user in _users: t1 = time() db.session.query(WxUser).filter_by(id=_user.id).update(dict(sex=WxUser.Sex.MALE)) db.session.commit() t2 = time() print t2 - t1 ``` out put: ``` 0.242075920105 15.5323040485 16.6957418919 ... ``` the commit operation cost time is more than normal. when open the 'SQLALCHEMY_ECHO', shows that SQLAlchemy query the every record by id. |