More complex queries take longer to execute, as they include more constrains and can impose some additional operations as sorting, aggregate, negation etc.
QueryPerformanceBenchmark.cs: RunQueryStructureTest
private void RunQueryStructureTest()
{
Init();
Clean();
System.Console.WriteLine("Storing objects as a bulk:");
Open(Configure());
Store();
Close();
//
Open(Configure());
System.Console.WriteLine("Simple SODA query:");
StartTimer();
IQuery query = objectContainer.Query();
query.Constrain(typeof(Item));
query.Descend("_name").Constrain("level1/1");
Item item = (Item)query.Execute().Next();
StopTimer("Select 1 object SODA: " + item._name);
Close();
//
Open(Configure());
System.Console.WriteLine("Sorted SODA query:");
StartTimer();
query = objectContainer.Query();
query.Constrain(typeof(Item));
query.Descend("_name").OrderDescending();
item = (Item)query.Execute().Next();
StopTimer("Select 1 object SODA: " + item._name);
Close();
//
Open(Configure());
System.Console.WriteLine("SODA query with joins:");
StartTimer();
query = objectContainer.Query();
query.Constrain(typeof(Item));
IConstraint con = query.Constrain("level2/1");
query.Descend("_name").OrderDescending().Constrain("level1/1").Or(con);
IList result = query.Execute();
StopTimer("Selected " + result.Count + " objects SODA");
Close();
}
QueryPerformanceBenchmark.cs: Init
private void Init()
{
_filePath = "performance.db4o";
// amount of objects
_count = 10000;
// depth of objects
_depth = 3;
_isClientServer = false;
}
QueryPerformanceBenchmark.cs: Configure
private IConfiguration Configure()
{
IConfiguration config = Db4oFactory.NewConfiguration();
return config;
}
Results from the test machine:
Storing objects as a bulk:
Store 30000 objects: 3049ms
Simple SODA query:
Select 1 object SODA: level1/1: 440ms
Sorted SODA query:
Select 1 object SODA: level9999/2: 1509ms
SODA query with joins:
Selected 1 objects SODA: 1735ms
From the test results you can see that sorting makes the query slower, and adding additional constraints slows things down even more.
Download example code: