Reduce the number of queries
Define referential integrity in your database, so that a bag cannot be removed so long an item exists, idem for the accounts and bags.  Then don't do the selects but provide exception handling on the deletes.  Your database will do the selects itself, to enforce the integrity.