deleting an object with many references
 
CapableObjects Forums
Home       Members    Calendar    Who's On
Welcome Guest ( Login | Register )
        



deleting an object with many references Expand / Collapse
Author
Message
Posted 2008-11-28 06:22:15
Forum Member

Forum MemberForum MemberForum MemberForum MemberForum MemberForum MemberForum MemberForum Member

Group: Forum Members
Last Login: Today @ 11:59:26
Posts: 34, Visits: 919
Hello!

I have a class which references many other classes as 1:n and n:m. When I execute anObject.AsIObject().Delete(), it may take up to a second (!) to delete a single instance. But, if I go over all its associations and do something like this:
if (anObject.AssociationX.Count==0) anObject.AssociationX.Clear();
it gets deleted blazing fast.

Does anyone have an idea why clearing empty associations makes deletion to execute with a normal speed, while without it it is very slow? The database presently has about 800'000 records in all tables.

Take care,
Dmitry
Post #1203
Posted 2008-11-28 11:32:02
Supreme Being

Supreme BeingSupreme BeingSupreme BeingSupreme BeingSupreme BeingSupreme BeingSupreme BeingSupreme Being

Group: Administrators
Last Login: 2010-07-21 00:21:24
Posts: 1 228, Visits: 1 373
No, I can't tell why this improves the speed. but it sounds like there is either a bug, or room for optimizations here... Could you check with the EcoSpaceDebugger if there is any difference in which SQL statements are executed when you clear before or not?

/Jonas Hogstrom [CapableObjects]
Post #1212
Posted 2008-11-28 14:57:26
Supreme Being

Supreme BeingSupreme BeingSupreme BeingSupreme BeingSupreme BeingSupreme BeingSupreme BeingSupreme Being

Group: Forum Members
Last Login: Today @ 11:08:06
Posts: 256, Visits: 2 317
Clearing the associations will merely unlink the objects. If the association is 1..* then it will load in the child objects anyway, but if it is *..* it will only load in the link objects.

I think the difference however comes in that when you delete with links ECO has to check each of the child objects to see if those are permitted to be deleted too (if you have cascade delete, or they are composite). Which in turn could mean that each of those objects then load up their composite objects to see if they are permitted to be deleted, and so on.

Is your association composite. Do the child objects also have composite associations of their own?


Pete


====
Pete
Post #1218
Posted 2008-11-28 15:43:27
Supreme Being

Supreme BeingSupreme BeingSupreme BeingSupreme BeingSupreme BeingSupreme BeingSupreme BeingSupreme Being

Group: Forum Members
Last Login: 2010-05-15 22:36:10
Posts: 188, Visits: 451
> if (anObject.AssociationX.Count==0) anObject.AssociationX.Clear();


I'm sure it is nothing to do at all in this case

/Efim

Post #1221
Posted 2008-11-28 16:11:41
Forum Member

Forum MemberForum MemberForum MemberForum MemberForum MemberForum MemberForum MemberForum Member

Group: Forum Members
Last Login: Today @ 11:59:26
Posts: 34, Visits: 919
Many of the associations are composite and link to other classes. Indeed, if there WERE objects in those associations it could take longer time to delete. But the associations are empty, and deletion takes long time anyway, while clearing EMPTY associations speeds it up a lot. I know very well that this is strange and looks like a shaman thing, though it does behave this way.

Best regards,
Dmitry
Post #1224
Posted 2008-11-29 17:18:39
Supreme Being

Supreme BeingSupreme BeingSupreme BeingSupreme BeingSupreme BeingSupreme BeingSupreme BeingSupreme Being

Group: Forum Members
Last Login: Today @ 11:08:06
Posts: 256, Visits: 2 317
A----B----C

If you delete A then all B must be loaded so that ECO can also load all C relating to all B.

The fact that you are clearing the association is irrelevant, the important part of your code is SomeObject.SomeAssociation.Count, which loads in the objects in order to tell you how many are in the collection. I suspect all you are doing is loading the objects elsewhere and then noticing how much faster the delete is, or are you timing all of this code?


====
Pete
Post #1239
« Prev Topic | Next Topic »


Reading This Topic Expand / Collapse
Active Users: 0 (0 guests, 0 members, 0 anonymous members)
No members currently viewing this topic.
Forum Moderators: HansKarlsen, Jonas Hogstrom

Permissions Expand / Collapse

All times are GMT +1:00, Time now is 4:12

Powered By InstantForum.NET v4.1.4 © 2010
Execution: 0,141. 6 queries. Compression Disabled.