简体   繁体   English

Peewee:限制删除

[英]Peewee: delete with limit

I have a (very) large table mit >100M rows. 我有一个(非常)大表mit> 100M行。 I want to delete 1M rows with some condition without running in any table lock or timeout issue. 我想删除某些情况下的1M行,而不用运行任何表锁或超时问题。 IMO delete with limit is best choice in this case. 在这种情况下,IMO限制删除是最好的选择。 I'm trying to find a peewee equivalent for a simple sql query 我正在尝试为一个简单的SQL查询找到一个等价的peewee

DELETE FROM users WHERE condition=1 LIMIT 10

My first approach is: 我的第一种方法是:

Users.delete().where(condition=10).limit(10)

but DeleteQuery doesn't have a limit method. 但DeleteQuery没有限制方法。 oops... 糟糕!

So, what is best practice to delete a huge number of rows with peewee? 那么,什么是删除带有peewee的行的最佳实践呢?

If you want delete with limit, then just use a subquery: 如果要删除限制,则只需使用子查询:

users_to_delete = User.select().where(...).limit(10)
Users.delete().where(User.id << users_to_delete)

SQL does not have support for LIMIT. SQL不支持LIMIT。 So NO, is not possible to do this. 因此,不行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM