BDB,如何按指定顺序获取主键?

发布于 2024-10-14 10:59:51 字数 1238 浏览 10 评论 0原文

我在oracle论坛上问了同样的问题好几天了,但没有答案:( 链接是:http://forums.oracle.com/forums/thread.jspa?threadID=2162345&tstart=0

大家好,我搭建BBS使用BDB作为后端数据库,论坛数据库、主题数据库和帖子数据库共享一个环境。这个BBS Web应用程序是多线程程序。如果用户选择一个论坛,则其主题将按照最后回复时间的顺序列出;选择一个主题,帖子也会按照回复时间的顺序列出。

struct forum {
UInt16 forumID;
string forumName;
string _lastPoster; // who is the last one replied in this forum
};

struct topic {
UInt32 topicID;
UInt16 forumID; // topic comes from this forum
string title; // topic title
UInt64 dateOfLastReply; // when last reply to this topic happen
};

struct post {
UInt64 postID;
UInt32 topicID; // post comes from this topic
string title; // post title as of topic
UInt64 dateOfPost; // when this post is created
};

我为主题创建一个主数据库和两个辅助数据库,主键是topicID,辅助键分别是forumID和dateOfLastReply,我想在第一个浏览器页面上按最新回复时间顺序显示第1个25个主题,在第2个浏览器页面上显示第2个25个主题浏览器页面等,

如果使用 SQL,则为: SELECT topicID FROM topic WHERE forumID=xx ORDER BY dateOfLastReply DESC

从性能角度来看,我想获取同一个论坛的所有主题id,并且需要它们按照回复时间顺序出现,然后根据返回的topicID逐一检索主题,我该怎么做这?我想我必须使用连接。 另外,考虑到每次浏览器想要请求下一页(即该论坛的第 2 个 25 个主题)时都会进行主题检索,您对检索性能有什么建议吗? DB_DBT_MULTIPLE 对我有帮助吗?

谢谢。

I have asked the same question for some days on oracle forums, but no answer came:(
link is:http://forums.oracle.com/forums/thread.jspa?threadID=2162345&tstart=0

Hi, I build BBS using BDB as backend database, forum database, topic database and post database share one environment. This BBS web application is multi-thread program. If user selects one forum, its topics will be listed in order of last reply time;selecting one topic, posts are listed in order of reply time as well.

struct forum {
UInt16 forumID;
string forumName;
string _lastPoster; // who is the last one replied in this forum
};

struct topic {
UInt32 topicID;
UInt16 forumID; // topic comes from this forum
string title; // topic title
UInt64 dateOfLastReply; // when last reply to this topic happen
};

struct post {
UInt64 postID;
UInt32 topicID; // post comes from this topic
string title; // post title as of topic
UInt64 dateOfPost; // when this post is created
};

I create one primary database and two secondary databases for topic, primary key is topicID, secondary keys are forumID and dateOfLastReply respectively, and I want to show 1st 25 topics in latest reply time order on the 1st browser page, 2nd 25 topics on the 2nd browser page, and etc.

if using SQL, it will be: SELECT topicID FROM topic WHERE forumID=xx ORDER BY dateOfLastReply DESC

From performance perspective, I want get all topics id of one same forum, and need them come in reply time order, then retrieve topic one by one based on returned topicID, how can I do this? guess I have to use joins.
Plus, do you have any suggestion about retrieval performance given the fact that topics retrieval will happen each time browser want to request the next page, that is, 2nd 25 topics of this forum?
Is DB_DBT_MULTIPLE helpful to me?

thanks.

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

〗斷ホ乔殘χμё〖 2024-10-21 10:59:51

您需要创建一个具有复合键的辅助数据库,该复合键由 (forum_id, dateoflastreply) 组成。然后,您想要的所有结果都将位于连续的行范围内,您可以通过执行范围扫描来查询它们(例如,以 (1, 2010-01-01) 开头的 20 行)。

You need to create a secondary database with a composite key, consisting of (forum_id, dateoflastreply). Then, all the results you want will be in a contiguous range of rows, and you can query on them by doing a range scan (eg, 20 rows starting with (1, 2010-01-01)).

情话已封尘 2024-10-21 10:59:51

您是否使用 BDB 的新 SQL 访问层?如果是这样,只需使用 SQL。

如果不是,BDB(大部分)只是一个键值数据存储。它有多种访问方法(哈希、B+树等),但其核心仅此而已。如果您想按非主键排序/搜索,则必须在这些值上创建索引,并在自己的代码中进行搜索/连接。

Are you using BDB's new SQL access layers? If so, just use SQL.

If not, BDB is (mostly) just a key-value datastore. It has several access methods (hash, B+tree, etc), but at its core thats all it is. If you want to sort/search by non-primary keys, you'll have to create indexes on those values, and do the searching/joining in your own code.

疧_╮線 2024-10-21 10:59:51

假设 topic_Secondary 数据库(包含辅助键)是通过 DB_ASSOCIATE 定义的,那么您将在 topic_Secondary 数据库上打开一个游标,并使用 DBC->get() 和 DB_SET_RANGE 将游标定位在所需的 forumID 上并移动光标从那里向前。

通过在辅助数据库上使用光标,您可以按所需的顺序获取从主数据库返回的数据。通过在初始 DBC->get() 中使用 DB_SET_RANGE 指定 forumID,您可以将光标定位在适当的位置以开始扫描。

请参阅有关光标二级索引

如果这能回答您的问题,请告诉我。

问候,

戴夫

Assuming that the topic_secondary database (which contains the secondary keys) is defined via DB_ASSOCIATE, then you would open a cursor on the topic_secondary database and using DBC->get() with DB_SET_RANGE you would position the cursor on the desired forumID and move the cursor forward from there.

By using a cursor over the secondary database, you get the data returned from the primary database in the desired order. And by specifying the forumID in the initial DBC->get() with DB_SET_RANGE, you can position the cursor at the proper place to begin your scan.

Please see the documentation on Cursors and Secondary indexes.

Please let me know if this answers your question.

Regards,

Dave

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文