• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Core Data: different fetch performance when launching app [SOLVED]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Core Data: different fetch performance when launching app [SOLVED]


  • Subject: Re: Core Data: different fetch performance when launching app [SOLVED]
  • From: Diederik Hoogenboom <email@hidden>
  • Date: Sat, 14 Oct 2006 16:48:39 +0200

Jakob,

Fetch request using relationships can be tricky as well. Some time ago I tried to write a predicate for a fetch request to retrieve objects based on the value of attributes of the relationship, like this:

Example Object Model:

Car -> Wheel

A car can have one or more wheels. And a wheel has a property called color (to keep it simple an NSString). The relationship is called wheels. There is no inverse relationship.
What I want is to retrieve all cars that a color that contains the word 'black'.


Code I've tried so far:

NSEntityDescription *entityDescription = [NSEntityDescription entityForName:@"Car" inManagedObjectContext:context];
NSFetchRequest *request = [[[NSFetchRequest alloc] init] autorelease];
[request setEntity:entityDescription];
NSPredicate *predicate = [NSPredicate predicateWithFormat:[NSString stringWithFormat:@"ANY wheels.color like '*black*'] ];
[request setPredicate:predicate];
NSArray *array = [context executeFetchRequest:request error:nil];



Unfortunately the fetch request does result in any objects retrieved.



Diederik

On 14-okt-2006, at 16:25, Jakob Olesen wrote:


On 14/10/2006, at 15.45, Diederik Hoogenboom wrote:

Thanks! Your last remark did the trick. I just added parentItem == nil to the predicate of the arraycontroller and the fetch now take 0.156 seconds the first time.

Lucky guess ;-)

I would have expected that Z_ENT would be indexed. It's one of the primary columns that are always there. Is there a way to add an index to a table in the SQLLite store, other then creating an relationship?

No.

You can go behind Core Data's back and add the index yourself using the sqlite3 command line tool or the SQLite API, but I wouldn't recommend that.

Z_ENT is a low cardinality attribute. It only takes a few distinct values across your 30,000 records. Such attributes normally don't benefit from being indexed, and each index has a performance penalty when inserting records. That is probably why Core Data doesn't index that attribute.

It would be a nice addition to Core Data to be able to add indices. Currently, every fetch that doesn't use a relationship or an object ID causes a full table scan.


_______________________________________________ Do not post admin requests to the list. They will be ignored. Cocoa-dev mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: This email sent to email@hidden
References: 
 >Core Data: different fetch performance when launching app (From: Diederik Hoogenboom <email@hidden>)
 >Re: Core Data: different fetch performance when launching app (From: Jakob Olesen <email@hidden>)
 >Re: Core Data: different fetch performance when launching app (From: Diederik Hoogenboom <email@hidden>)
 >Re: Core Data: different fetch performance when launching app (From: Scott Stevenson <email@hidden>)
 >Re: Core Data: different fetch performance when launching app (From: Diederik Hoogenboom <email@hidden>)
 >Re: Core Data: different fetch performance when launching app (From: Jakob Olesen <email@hidden>)
 >Re: Core Data: different fetch performance when launching app [SOLVED] (From: Diederik Hoogenboom <email@hidden>)
 >Re: Core Data: different fetch performance when launching app [SOLVED] (From: Jakob Olesen <email@hidden>)

  • Prev by Date: Re: Core Data: different fetch performance when launching app [SOLVED]
  • Next by Date: Re: NSScroller customization
  • Previous by thread: Re: Core Data: different fetch performance when launching app [SOLVED]
  • Next by thread: Re: Core Data: different fetch performance when launching app
  • Index(es):
    • Date
    • Thread