In order to optimize native queries the bytecode is analyzed and converted into SODA queries. This task isn't easy. If there's any doubt in the correctness of the conversion db4o won't do it. In such cases db4o falls back and instantiates all objects and runs it against the query. This is a order of magnitude slower than optimized queries. Therefore you probably want to monitor the query optimization and be warned when a query isn't optimized. This is possible with the diagnostic listeners.
configuration.common().diagnostic().addListener(new DiagnosticListener() { @Override public void onDiagnostic(Diagnostic diagnostic) { if(diagnostic instanceof NativeQueryNotOptimized){ System.out.println("Query not optimized"+diagnostic); } else if(diagnostic instanceof NativeQueryOptimizerNotLoaded){ System.out.println("Missing native query optimisation jars in classpath "+diagnostic); } } });
You can register a diagnostic listener and check for certain messages. There are two messages related to the native query optimization. The first is the NativeQueryNotOptimized-message. This tells you that a query couldn't be optimized. Consider simplifying the query. The second is the NativeQueryOptimizerNotLoaded-message. This message tells you that db4o couldn't find the libraries needed for the native query optimization. Check that you've included the jars-files you need.