cubicweb #2934557 drop_entity_class yield a MemoryError [open]

The drop_entity_class method yield a MemoryError if the number of entities is too high (in the example case, 1085075).

This is due to the "X eid IN (%s)" part of the DELETE request.

A work around can be the following function:

def fast_delete(session, etype):
 etype_eid = session.find_one_entity('CWEType', name=etype).eid
 print 'deleting from table cw_%s' % etype
 session.system_sql('DELETE FROM cw_%s' % etype.lower())
 print 'deleting from table is_relation'
 session.system_sql('DELETE FROM is_relation WHERE eid_to=%(eid)s', {'eid': etype_eid})
 print 'deleting from table is_instance_of_relation'
 session.system_sql('DELETE FROM is_instance_of_relation WHERE eid_to=%(eid)s', {'eid': etype_eid})

 for table in ('cw_source_relation', 'owned_by_relation', 'created_by_relation'):
     print 'deleting from table %s' % table
     session.system_sql("DELETE FROM %s WHERE eid_from IN "
                       "(SELECT eid FROM entities WHERE type='%s')" % (table, etype))
 print 'deleting from entities'
 session.system_sql("DELETE FROM entities WHERE type='%s'" % etype)
 session.commit()
prioritynormal
typebug
done in<not specified>
load0.500
load left0.500
closed by<not specified>