In MySQL, you can't modify the same table which you use in the
SELECT part (DELETE and UPDATE with subquery):
https://dev.mysql.com/doc/refman/8.0/en/update.html
We need to verify how this affects large photo libraries
as it probably "breaks" the query optimizer. So might lead to
bad performance as well as high CPU and/or memory usage.