tags:

views:

123

answers:

2

Hi,

I have 7000 objects in my Db4o database.

When i retrieve all of the objects it's almost instant.. When i add a where constrain ie Name = "Chris" it takes 6-8 seconds.

What's going on?

Also i've seen a couple of comments about using Lucene for search type of queries does anyone have any good links for this?

+1  A: 

There are two things to check.

  1. Have you added the 'Db4objects.Db4o.NativeQueries'-assembly? Without this assembly, a native query cannot be optimized.
  2. Have set an index on the field which represents the Name? A index should make query a lot faster Index:

    cfg.Common.ObjectClass(typeof(YourObject)).ObjectField("fieldName").Indexed(true);
    
Gamlor
+1  A: 

This question is kinda old, but perhaps this is of any use:

When using native queries, try to set a breakpoint on the lambda expression. If the breakpoint is actually invoked, you're in trouble because the optimization failed. To invoke the lambda, each of the objects will have to be instantiated which is very costly.

If optimization worked, the lambda expression tree will be analyzed and the actual code won't be needed, thus breakpoints won't be triggered.

Also note that settings indexes on fields must be performed before opening the connection.

Last, I have a test case of simple objects. When I started without query optimization and indexing (and worse, using a server that was forced to use the GenericReflector because I failed to provide the model .dlls), it too 600s for a three-criteria query on about 100,000 objects. Now it takes 6s for the same query on 2.5M objects so there is really a HUGE gain.

mnemosyn