Question

I have an original and a premium repository, and I tried to add indices to both as such:

    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();

    }

problem is, this query takes forever, and there should only be a few hundred to a few thousand results. None of the object stores should contain more than 40K items. What am I doing wrong?

        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 };
Was it helpful?

Solution

Some questions / issues regarding your code that could explain the slowness:

  1. It looks like you are trying to configure indexes on an open database. This does not work (check this page).

  2. In your query you call original.Query() which causes db4o to return ALL OBJECTS of type X (and sub types as well) and then LINQ for Objects quick in. You should not use the query method this way db4o LINQ implementation will be used instead (and this should be much faster).

My guess about 2 is that you are doing that to be able to use joins (since db4o LINQ implementation does not support it). In order to use db4o LINQ implementation I am afraid you'll need to try to split your query in multiple simple queries and join the results of each query.

Hope this helps.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top