如何提高db4o中的查询速度? [英] How to increase query speed in db4o?

查看:118
本文介绍了如何提高db4o中的查询速度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于db4o databse具有15000+个对象而导致的OutOfMemoryError

我的问题参考的是我之前的问题(上文).对于相同的PostMessage模型和相同的查询.

My question is in reference to my previous question (above). For the same PostedMessage model and same query.

使用100,000个PostMessage对象,查询大约需要1243毫秒才能返回前20条PostMessage.

With 100,000 PostedMessage objects, the query takes about 1243 ms to return first 20 PostedMessages.

现在,我已经在db4o中保存了1,000,000个PostMessage对象.相同的查询花费了342,132毫秒.非线性高.

Now, I have saved 1,000,000 PostedMessage objects in db4o. The same query took 342,132 ms. Which is non-linearly high.

如何优化查询速度?

财政年度: timeSent和timeReceived是索引字段. 我正在使用SNAPSHOT查询​​模式. 我没有使用TA/TP.

FYR: The timeSent and timeReceived are Indexed fields. I am using SNAPSHOT query mode. I am not using TA/TP.

推荐答案

@Gamlor不,我根本没有排序.代码如下:

@Gamlor No, I am not sorting at all. The code is as follows:

public static ObjectSet<PostedMessage> getMessagesBetweenDates(
        Calendar after,
        Calendar before,
        ObjectContainer db) {

    if (after == null || before == null || db == null) {
        return null;
    }
    Query q = db.query(); //db is pre-configured to use SNAPSHOT mode.
    q.constrain(PostedMessage.class);
    Constraint from = q.descend("timeRecieved").constrain(new Long(after.getTimeInMillis())).greater().equal();
    q.descend("timeRecieved").constrain(new Long(before.getTimeInMillis())).smaller().equal().and(from);
    ObjectSet<EmailMessage> results = q.execute();
    return results;
}

此方法的参数如下:

之后= 13-09-2011 10:55:55

after = 13-09-2011 10:55:55

之前= 13-09-2011 10:56:10

before = 13-09-2011 10:56:10

我希望在之后"和之前"之间仅返回10条发布消息. (我正在生成一个虚拟的PostMessage,其中的timeReceived每增加1秒.)

And I expect only 10 PostedMessages to be returned between "after" and "before". (I am generating dummy PostedMessage with timeReceived incremented by 1 sec each.)

这篇关于如何提高db4o中的查询速度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆