0

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

1 回答 1

1

有关您的代码的一些问题/问题可以解释速度缓慢:

  1. 看起来您正在尝试在打开的数据库上配置索引。这不起作用(检查此页面)。

  2. 在您的查询中,您调用 original.Query() ,这会导致 db4o 返回 X 类型的所有对象(以及子类型),然后 LINQ for Objects 快速进入。您不应该以这种方式使用查询方法 db4o LINQ 实现将被使用相反(这应该更快)。

我对 2 的猜测是,您这样做是为了能够使用连接(因为 db4o LINQ 实现不支持它)。为了使用 db4o LINQ 实现,恐怕您需要尝试将查询拆分为多个简单查询并加入每个查询的结果。

希望这可以帮助。

于 2012-08-11T20:59:11.580 回答