我有一个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 };