db4o Developer Community

db4o open source object database, native to Java and .NET
Welcome to db4o Developer Community Sign in | Join
in Search
More Search Options

insertion and query order

Last post 12-01-2007, 10:45 AM by gpgemini. 4 replies.
Sort Posts: Previous Next
  •  11-16-2007, 05:46 PM 43639

    insertion and query order

    Hi,

    I was wondering if it is possible to force the db to hold the objects in the order they were inserted, so that when I query for them they are returned at the same order.

    My application has around 50,000 Items . I add them to the db in chunks of thousands, where each Item has an increasing id.
    After the first chink, if I query for all Items (IList<Item> = db.Query<Item>()) I get them at the same order they were inserted, but after the second third or fourth insertion, the order is broken at some places.

    I tried sorting the Items but the performance took a turn for the worse (in magnitudes, since all Items had to be activated).
    I want to show the Items in a virtual DataGridView, activating all Items takes too much time and is unnecessary.

    Any ideas ?

    Thanks.
     

  •  11-19-2007, 04:45 PM 43680 in reply to 43639

    Re: insertion and query order

    Hi,

    Have you tried indexing the id field of your item class and using a SODA query with OrderAscending() on your id field?  That should avoid activation and return your Items in insert order if you can guarantee a unique id.

    HTH,

    Brett 

  •  11-19-2007, 06:39 PM 43691 in reply to 43680

    Re: insertion and query order

    Hi Brett,

    I haven't tried that, seems like a good idea.
    Is the indexing of the id field necessary ? It seems that if the query has returned the objects of interest, than the db already has direct access to each object and it's fields, thus sorting should work just as fast without indexing.
     

  •  11-19-2007, 08:23 PM 43697 in reply to 43691

    Re: insertion and query order

    Hi,

    My thought was that the sorting effort would be minimized by the indexing, but I suppose it would require testing to verify the impact.  I suppose the true benefit would be if you queried for a single or subset of IDs, but if you are only querying for all Items then the benefit might be small.

    Brett 

  •  12-01-2007, 10:45 AM 43959 in reply to 43697

    Re: insertion and query order

    Hi, I tried using SODA with OrderAscending() and it works.
    Thanks.

    But I have a problem when using native queries, I try:
    IList<Item> res = db.Query<Item>(new MyCmp);
    Where MyCmp is a IComparer<Item> class that does a void comparison (just for a dry test):
    Compare(Item a, Item b) { return 0; }
    And the performance of this is awful ! I've set activation depth to 0, and testing shows that activation does not occur, I've also added a reference to db4o.Tools to make sure native queries are optimized, and still, this query takes an unimaginable long time to execute on 10,000 - 20,000 items, where SODA with OrderAscending takes a few seconds.

    What am I doing wrong ?
    Is there anything else needed to be done when sorting with NQ ?
     

View as RSS news feed in XML