db4o 字段已索引,但未在查询中使用

发布于 2024-09-13 01:19:48 字数 1751 浏览 4 评论 0原文

我有一个简单的对象,其 Guid 作为字段 public Guid _id,该字段已建立索引。

config.Common.ObjectClass(typeof(ConfigurableObject))
      .ObjectField("_id").Indexed(true);

当我在 ObjectManager Enterprise 中打开数据库文件时,它显示该字段已建立索引!

但我的查询速度太慢了。最多需要5个!!秒,数据库中只有大约 50 个对象。

查询如下:

private void FindObject<T>(T toFind) where T : ConfigurableObject {
    var query = HeatingSystem.Instance.GetObjectContainer().Query();
    query.Constrain(typeof(T));
    query.Descend("_id").Constrain(toFind._id);

    IObjectSet result = query.Execute();

    /*IList<T> result = HeatingSystem.Instance.GetObjectContainer().Query<T>(
        delegate(T cobj) {
            return cobj._id == toFind.Guid;
        }
    );*/
}

本机查询和 SODA 查询都很慢。

当我添加一个时,

config.Common.Diagnostic.AddListener(
   new Db4objects.Db4o.Diagnostic.DiagnosticToConsole());

它说“考虑对您查询的字段建立索引。”
并且:“无法从字段索引加载查询候选集”

我正在使用 db4o 7.12.132.14217 进行 Compactframework 2.0

编辑:
带有 die Guid 字段的类:

public abstract class ConfigurableObject {
    private string _description;
    public Guid _id;
}

的完整配置:

public static IEmbeddedConfiguration ConfigDb4O() { 
    IEmbeddedConfiguration config = Db4oEmbedded.NewConfiguration();
    config.Common.OptimizeNativeQueries = true;

    config.Common.ObjectClass(typeof(ConfigurableObject)).ObjectField("_id").Indexed(true);
    config.Common.ObjectClass(typeof(ConfigurableObject)).StoreTransientFields(false);

    return config;
}

这是我使用以下命令创建/打开数据库

IObjectContainer db = Db4oEmbedded.OpenFile(ConfigDb4O(), "foo.db4o");

I have a simple object with a Guid as field public Guid _id, this field is indexed.

config.Common.ObjectClass(typeof(ConfigurableObject))
      .ObjectField("_id").Indexed(true);

When I open the databasefile in the ObjectManager Enterprise, it shows me that the field is indexed!

But my queries are damn slow. It takes up to 5!! seconds, there are only about 50 objects in the database.

Here's the query:

private void FindObject<T>(T toFind) where T : ConfigurableObject {
    var query = HeatingSystem.Instance.GetObjectContainer().Query();
    query.Constrain(typeof(T));
    query.Descend("_id").Constrain(toFind._id);

    IObjectSet result = query.Execute();

    /*IList<T> result = HeatingSystem.Instance.GetObjectContainer().Query<T>(
        delegate(T cobj) {
            return cobj._id == toFind.Guid;
        }
    );*/
}

Both, the native and the SODA query are slow.

When I add an

config.Common.Diagnostic.AddListener(
   new Db4objects.Db4o.Diagnostic.DiagnosticToConsole());

It says "Consider indexing fields that you query for."
and: "Query candidate set could not be loaded from a field index"

I'm using db4o 7.12.132.14217 for Compactframework 2.0

edit:
The Class with die Guid field:

public abstract class ConfigurableObject {
    private string _description;
    public Guid _id;
}

Here is the complete config

public static IEmbeddedConfiguration ConfigDb4O() { 
    IEmbeddedConfiguration config = Db4oEmbedded.NewConfiguration();
    config.Common.OptimizeNativeQueries = true;

    config.Common.ObjectClass(typeof(ConfigurableObject)).ObjectField("_id").Indexed(true);
    config.Common.ObjectClass(typeof(ConfigurableObject)).StoreTransientFields(false);

    return config;
}

I create / open the db with the following:

IObjectContainer db = Db4oEmbedded.OpenFile(ConfigDb4O(), "foo.db4o");

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文