我有一个original
和一个premium
存储库,我尝试将索引添加到这两个存储库中:
public void SetupIndices()
{
original.Ext().Configure().ObjectClass(typeof(LineItem)).ObjectField("idField").Indexed(true);
original.Ext().Configure().Add(new UniqueFieldValueConstraint(typeof(LineItem), "idField"));
original.Ext().Configure().ObjectClass(typeof(LineItem)).ObjectField("nameField").Indexed(true);
original.Ext().Configure().Add(new UniqueFieldValueConstraint(typeof(LineItem), "nameField"));
original.Ext().Configure().ObjectClass(typeof(Order)).ObjectField("idField").Indexed(true);
original.Ext().Configure().Add(new UniqueFieldValueConstraint(typeof(Order), "idField"));
original.Ext().Configure().ObjectClass(typeof(Order)).ObjectField("nameField").Indexed(true);
original.Ext().Configure().Add(new UniqueFieldValueConstraint(typeof(Order), "nameField"));
original.Ext().Configure().ObjectClass(typeof(Creative)).ObjectField("idField").Indexed(true);
original.Ext().Configure().Add(new UniqueFieldValueConstraint(typeof(Creative), "idField"));
original.Ext().Configure().ObjectClass(typeof(Creative)).ObjectField("nameField").Indexed(true);
original.Ext().Configure().Add(new UniqueFieldValueConstraint(typeof(Creative), "nameField"));
original.Ext().Configure().ObjectClass(typeof(Company)).ObjectField("idField").Indexed(true);
original.Ext().Configure().Add(new UniqueFieldValueConstraint(typeof(Company), "idField"));
original.Ext().Configure().ObjectClass(typeof(Company)).ObjectField("nameField").Indexed(true);
original.Ext().Configure().Add(new UniqueFieldValueConstraint(typeof(Company), "nameField"));
original.Ext().Configure().ObjectClass(typeof(LineItemCreativeAssociation)).ObjectField("lineItemIdField").Indexed(true);
original.Ext().Configure().ObjectClass(typeof(LineItemCreativeAssociation)).ObjectField("creativeIdField").Indexed(true);
original.Commit();
premium.Ext().Configure().ObjectClass(typeof(LineItem)).ObjectField("idField").Indexed(true);
premium.Ext().Configure().Add(new UniqueFieldValueConstraint(typeof(LineItem), "idField"));
premium.Ext().Configure().ObjectClass(typeof(LineItem)).ObjectField("nameField").Indexed(true);
premium.Ext().Configure().Add(new UniqueFieldValueConstraint(typeof(LineItem), "nameField"));
premium.Ext().Configure().ObjectClass(typeof(Order)).ObjectField("idField").Indexed(true);
premium.Ext().Configure().Add(new UniqueFieldValueConstraint(typeof(Order), "idField"));
premium.Ext().Configure().ObjectClass(typeof(Order)).ObjectField("nameField").Indexed(true);
premium.Ext().Configure().Add(new UniqueFieldValueConstraint(typeof(Order), "nameField"));
premium.Ext().Configure().ObjectClass(typeof(Creative)).ObjectField("idField").Indexed(true);
premium.Ext().Configure().Add(new UniqueFieldValueConstraint(typeof(Creative), "idField"));
premium.Ext().Configure().ObjectClass(typeof(Creative)).ObjectField("nameField").Indexed(true);
premium.Ext().Configure().Add(new UniqueFieldValueConstraint(typeof(Creative), "nameField"));
premium.Ext().Configure().ObjectClass(typeof(Company)).ObjectField("idField").Indexed(true);
premium.Ext().Configure().Add(new UniqueFieldValueConstraint(typeof(Company), "idField"));
premium.Ext().Configure().ObjectClass(typeof(Company)).ObjectField("nameField").Indexed(true);
premium.Ext().Configure().Add(new UniqueFieldValueConstraint(typeof(Company), "nameField"));
premium.Ext().Configure().ObjectClass(typeof(LineItemCreativeAssociation)).ObjectField("lineItemIdField").Indexed(true);
premium.Ext().Configure().ObjectClass(typeof(LineItemCreativeAssociation)).ObjectField("creativeIdField").Indexed(true);
premium.Commit();
}
问题是,这个查询需要永远,并且应该只有几百到几千个结果。所有对象库都不应包含超过40K的项目。我做错了什么?
var creatives = from Creative c in original.Query<Creative>()
join Company co in original.Query<Company>()
on c.advertiserId equals co.id
join LineItemCreativeAssociation lica in original.Query<LineItemCreativeAssociation>()
on c.id equals lica.creativeId
join LineItem li in original.Query<LineItem>()
on lica.lineItemId equals li.id
join LineItem newLI in premium.Query<LineItem>()
on li.name equals newLI.name
join Company newCO in premium.Query<Company>()
on co.name equals newCO.name
from Creative newC in premium.Query<Creative>()
.Where(o=>o.name == c.name).DefaultIfEmpty()
where newC == null
select new { creative = c, newCompany = newCO };
答案 0 :(得分:1)
有关您的代码的一些问题/问题可以解释缓慢:
看起来您正在尝试在打开的数据库上配置索引。这不起作用(check this page)。
在您的查询中,您调用original.Query(),这会导致db4o返回类型X的所有OBJECTS(以及子类型),然后快速返回LINQ for Objects。您不应该以这种方式使用查询方法将使用db4o LINQ实现(这应该更快)。
我对2的猜测是你这样做是为了能够使用连接(因为db4o LINQ实现不支持它)。为了使用db4o LINQ实现,我担心你需要尝试在多个简单查询中拆分查询并加入每个查询的结果。
希望这有帮助。