2

The following query takes a while to return:

db.Query<Person>(x => x.StartsWith("Chr", StringComparison.CurrentCultureIgnoreCase))

is there a way to get this working correctly? ie faster?

skaffman
  • 398,947
  • 96
  • 818
  • 769
Chris Kolenko
  • 1,020
  • 17
  • 32

2 Answers2

2

Maybe you ran into a limitation of db4o’s query-optimization. Normally Native Queries and LINQ-Queries are translated into a low level SODA-query. When this optimization fails, db4o instantiates the objects in the database in order to execute the query. As you can imagine this can be quite slow.

The best current solution is to use a SODA directly for this case. For example a class with one property:

 public class SimpleObject
 {
     private string name;
     public string Name
     {
         get { return name; }
        set { name = value; }
     }
 }

The native query like this:

var result = db.Query<SimpleObject>(x => x.Name.StartsWith ("Chr",StringComparison.CurrentCultureIgnoreCase));

Can be represented by this SODA-Query:

IQuery query = db.Query();
query.Constrain(typeof (SimpleObject)); // restrict to a certain class
query.Descend("name").Constrain("Chr").StartsWith(false); // the field 'name' starts with  'chr', case-insensitive

foreach (var s in query.Execute())
{
    // 
}

I hope future versions of the Query-Optimizer support this case directly.

Gamlor
  • 12,978
  • 7
  • 43
  • 70
  • Where does "funny" come from? – Erik Forbes Feb 08 '10 at 21:35
  • D'oh, copy and past error, I've fixed it. The original example used 'funny' as search-term ;) – Gamlor Feb 08 '10 at 22:29
  • who are you Gamlor.. you've replied to a few Db4o questions i've posted :D thanks very much. before you posted this i actually move my code to a SODA query which made it 10000000x faster.. it was just pain full moving to an IList rather than IList<>.. In the doc it stats Linq queries are translated into SODA queries.. maybe there is a fix for this issue inside the expression translation.. might have a look to see if i can fix it and contribute some how :D thanks for the help guys much appreciated – Chris Kolenko Feb 09 '10 at 12:52
  • 1
    Both LINQ and Native Query are normally into SODA. For the LIQ-implementation of StartWith/EndWith there's a suggested patch available. But it's not (yet) integrated into the regular source: http://developer.db4o.com/Forums/tabid/98/aff/4/aft/9669/afv/topic/Default.aspx – Gamlor Feb 09 '10 at 19:14
  • Thanks for pointing that out Gamlor, I'm learning towards using Lucene to do all my full text searching in the future which should solve a lot of my current searching issues – Chris Kolenko Feb 11 '10 at 12:26
0

adding and index on the column you're comparing would probably help.

http://developer.db4o.com/Documentation/Reference/db4o-7.4/net35/tutorial/docs/Indexes.html#outline219

John Boker
  • 82,559
  • 17
  • 97
  • 130