Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6146137
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T18:54:10+00:00 2026-05-23T18:54:10+00:00

Consider the following 2 predicates filtering through a 5k+ entries store: predicate1 = [NSPredicate

  • 0

Consider the following 2 predicates filtering through a 5k+ entries store:

predicate1 = [NSPredicate predicateWithFormat:@"hidden == NO AND name BEGINSWITH[cd] %@", searchString];
predicate2 = [NSPredicate predicateWithFormat:@"name BEGINSWITH[cd] %@", searchString];

I turned on -com.apple.CoreData.SQLDebug to see the fetch request times:

predicate1: 0.4728s
predicate2: 0.0867s

Am I missing something? Both columns are indexed. How come adding a simple boolean check slows down the fetch request that much?

EDIT: as requested, the output:

CoreData: sql: SELECT 0, t0.Z_PK, t0.Z_OPT, t0.ZHIDDEN, t0.ZID, t0.ZNAME, t0.ZRANK FROM ZARTISTINDEX t0 WHERE ( t0.ZHIDDEN = ? AND ( NSCoreDataStringSearch( t0.ZNAME, ?, 393, 0) OR  NSCoreDataStringSearch( t0.ZNAME, ?, 393, 0))) ORDER BY t0.ZRANK DESC LIMIT 14

That rank column is also indexed. The reason I need this request to be faster than 0.5s is that it’s used for an autocomplete feature. That request is made every time the value of some text field gets changed by the user.

EDIT 2: adding more contextual info:

- (NSArray*)autocompleteSuggestions:(NSString*)searchString {

    NSFetchRequest *request = [[NSFetchRequest alloc] init];
    NSEntityDescription *entity = [NSEntityDescription entityForName:@"ArtistIndex" inManagedObjectContext:self.indexObjectContext];
    [request setEntity:entity];
    [request setFetchLimit:10];

    NSPredicate *predicate = [NSPredicate predicateWithFormat:@"hidden == NO AND (name BEGINSWITH[cd] %@ OR name BEGINSWITH[cd] %@)", searchString, [NSString stringWithFormat:@"the %@", searchString]];
    [request setPredicate:predicate];

    NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"rank" ascending:NO];
    [request setSortDescriptors:[NSArray arrayWithObject:sortDescriptor]];
    [sortDescriptor release];

    NSArray *resultsArray = [self.indexObjectContext executeFetchRequest:request error:nil];
    [request release];

    return resultsArray;
}

The ArtistIndex entity has the following attributes:

  • id (int32)
  • name (string, indexed)
  • rank (int32, indexed)
  • hidden (BOOL, indexed)

Edit 3: here are the full SQL outputs for the slow query (predicate1) and the fast query (predicate2) with com.apple.CoreData.SQLDebug set to 3. More rigorous testing brought me the following test times, which are better, but still have a +2x difference and really make a difference in an autocomplete suggestions context. Or is this a reasonable fetch time difference now?

predicate1: 0.3772s
predicate2: 0.1633s

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T18:54:10+00:00Added an answer on May 23, 2026 at 6:54 pm

    I ended up taking advice on @pothibo and Ivo Jansch’s answer 2nd approach and do the following:

    1. When the user types in the first letter in the field, I fetch all the entries that
      start with that letter (so basically calling that autocompleteSuggestions: method but without setting the fetch request’s
      fetchLimit property)
    2. Every time the user adds or remove a letter, apply an appropriate
      NSPredicate to that initially fetched array using filteredArrayUsingPredicate:.

    This results in a slighly slower initial request (although still < 1s) but lightning-fast subsequent fetches.

    This is a really clever way to do autocomplete suggestions, since the new set of autocomplete suggestions is always going to be a subset of the previous one. Thanks @pothibo!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Consider following tables in MySQL database: entries: creator_id INT entry TEXT is_expired BOOL other:
Consider the following code: [Serializable] public class Human { public string Name { get;
Consider the following code: class Foo(var name: String = bar) Now i try to
Consider the following data Predicate = Pred Name Arity Arguments type Name = String
Consider the following tables; test SQL> desc test; Name Null? Type ----------------------------------------- -------- ----------------------------
Consider following schema: Customers: Col | Type | -------------------| id | INTEGER | name
Consider following code public class City { public string Name { get { return
Consider following example : public class SomeBusinessLayerService : DataService<MyEntityContainer> { [WebInvoke] void DoSomething(string someParam)
Consider following class class test { public: test(int x){ cout<< test \n; } };
Consider following scenario: I have RESTful URL /articles that returns list of articles user

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.