Which one is better for performance?
We take a piece of food. which makes mass update impossible.
products = Product.objects.filter(featured=True).order_by("-modified_on")[3:]
for product in products:
product.featured = False
product.save()
or (invalid)
for product in products.iterator():
product.update(featured=False)
Strike>
I also tried QuerySet in the instructions:
Product.objects.filter(pk__in=products).update(featured=False)
This line works fine on SQLite. But in MySQL, it occurs after an exception. Therefore, I could not use it.
DatabaseError: (1235, "This version of MySQL does not yet support the" LIMIT and IN / ALL / ANY / SOME subquery ")
Edit: Also, the iterator () method causes the request to be reevaluated. Therefore, it is bad for performance.
source
share