How to get primary keys in some order with joins?

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 key 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.
Edited by: tiplip on 2011-1-22 上午5:43
Edited by: tiplip on 2011-1-22 下午5:52
Edited by: tiplip on 2011-1-23 下午7:42

Hi tiplip,
Bellow I will describe how you can support "SELECT * FROM table WHERE X = key ORDER BY Y" queries using Berkeley DB, which, as you suspected, should be done by using a composite index.
First of all, think of Berkeley DB as the storage engine underneath an RDBMS. In fact, Berkeley DB was the first "generic data storage library" implemented underneath MySQL. As such, Berkeley DB has API calls and access methods that can support any RDBMS query. However, since BDB is just a storage engine, your application has to provide the code that accesses the data store with an appropriate sequence of steps that will implement the behavior that you want.
If you have two indices in SQL, each on a single column (call them X and Y), and you do:
SELECT * FROM table WHERE X = key ORDER BY Y;then there are three plausible query plans:
(1) scan the whole table, ignore both indices, filter by X = key then sort by Y;
(2) use the index on Y to scan all rows in the required order, filter by X = key;
(3) use the index on X, find the matching rows, then sort by Y.
There are cases where (1) would be fastest, because it has all of the columns from one scan (the other query plans will do random lookups on the primary for each row). This assumes that the data can fit into memory and the sort is fast.
Query plan (2) will be fastest if the selectivity is moderate to high, looking up rows in the main table is fast, and sorting the rows is very slow for some reason (e.g., some complex collation).
Query plan (3) will be fastest if the selectivity is small (only a small percentage of the rows in the table matches). This should be the best case for us, making it the best choice in a Berkeley DB key/value application.
The optimal plan would result from having a composite index on (X, Y), which can return just the desired rows in the desired order. Of course, it does cost additional time and space to maintain that index. But note that you could have this index instead of a simple index on X: it can be used in any query the simple index could be used in.
Records in Berkeley DB are (key, value) pairs. Berkeley DB supports only a few logical operations on records. They are:
* Insert a record in a table.
* Delete a record from a table.
* Find a record in a table by looking up its key.
* Update a record that has already been found.
Notice that Berkeley DB never operates on the value part of a record. Values are simply payload, to be stored with keys and reliably delivered back to the application on demand. Both keys and values can be arbitrary byte strings, either fixed-length or variable-length.
So, in case of a "SELECT * FROM X WHERE id=Y ORDER BY Z" query, our suggestion, from Berkeley DB's point of view, would be for you to use a composite index (as it would be in SQL), where a string created as X_Y should do the trick, as explained in the following scenario.
Primary:
    X Y
1 10 abc
2 10 aab
3 20 bbc
4 10 bba
5 20 bac
6 30 cbaSecondary:
10_aab 2
10_abc 1
10_bba 4
20_bac 5
20_bbc 3
30_cba 6If the query looks like this:
'SELECT * FROM primarydb WHERE X = 10 ORDER by Y'the application can run a cursor on the secondary and begin the loop with the DB_SET_RANGE flag on 10. When iterating with DB_NEXT, this will return:
2 10 aab
1 10 abc
4 10 bbcThe application must check for the end of the range inside the loop, in this case it should stop when it hits 20_bac.
As in SQL, retrieving by a secondary key is remarkably similar to retrieving by a primary key and the Berkeley DB call will look similar to its primary equivalent.
tiplip wrote:
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?As you are concerned about the performance, I think this would be the fastest solution. Of course, you can tune the performance at a later time, after you have the functionality in place. What I think you should do first is to increase the cache size and test with a bigger database page size, and maybe to configure the transactional subsystem (in case you use one).
If you are not very familiar with how to implement the above in BDB, please read the Guide to Oracle Berkeley DB for SQL Developers, available at: http://www.oracle.com/technetwork/articles/seltzer-berkeleydb-sql-086752.html
You will also need to be familiar with the following documentation:
Related documentation pages:
Secondary indexes - http://download.oracle.com/docs/cd/E17076_01/html/programmer_reference/am_second.html
Cursor operations - http://download.oracle.com/docs/cd/E17076_01/html/programmer_reference/am_cursor.html#am_curget
DBcursor->get() - http://download.oracle.com/docs/cd/E17076_01/html/api_reference/C/dbcget.html
DB_SET_RANGE - http://download.oracle.com/docs/cd/E17076_01/html/api_reference/C/dbcget.html#dbcget_DB_SET_RANGE
If my answer helps you with your question, please go ahead and rate it as Helpful or Correct, and the forum thread as answered. For each unrelated question, please create a new forum thread.
Good luck with building your forum application,
Bogdan Coman
PS: If you are a BDB licensed customer, you can also use My Oracle Support (https://support.oracle.com) to visit the KM note 1210173.1, that discusses the same topic.

Similar Messages

  • I use iPhoto and want to know how to get the 'key photo' i select on my MacBook Pro to be the one that gets used on my iPhone when i sync them. Any ideas? also, i want the events to appear in the order i choose on my MacBook too

    I use iPhoto and want to know how to get the 'key photo' i select on my McBook Pro to be the same one that gets used on my iPhone 5s when i sync. i also want the events to appear on the iPhone in the same order i have them on my macbook. any ideas there too?

    Killerfinch wrote:
    My new yahoo account nestles comfortably in iCloud on the mine iPad.
    No, your Yahoo account is not in iCloud (which only handles iCloud mail), it is in Yahoo, and the Yahoo mail account is on your iPad.
    But the MacBook Pro will have none of it! I write this question now as I fear that I will be totally demented very soon and unable to formulate my thoughts clearly!
    Get the correct settings for your account from Yahoo and set it up manually.
    By the way, I also find the "password" issue problematical. It seems Apple want my Apple password rather than my eMail password. All very confusing.
    That would depend on what you are trying to do.

  • How to set primary key of the VO.

    I have a problem with the master detail search. The search works fine on the first search, all details can be seen fine, but in the second search I get this error.
    The number of displayed records, 1, exceeds the actual number of records, 0, in view object EgoItemAdvancedSearchAM.MYACCESSOR001_MYLINK001_DetailsOrderLinesVO. Some of the displayed records may have been deleted.
    Somwhere in another thread, someone had the same problem and the soultion was to set primary key of the master VO. I am not sure how to set primary key of a VO. In my case the master VO is dynamic. Is there a way I can set PK of a dynamic VO.
    Any help greatly appreciated.

    Hi
    Thanks for your reply...
    am seting the primary key to VO attribute in my controller(PR)...but its not mapping to the VO attribute..
    OAAttachmentImageBean Ibean = (OAAttachmentImageBean)webBean.findChildRecursive("OpAttachments");
    String[] pkvaule = {"ResAttribute15"};
    Ibean.setPkColumns(pkvaule);
    Regards
    Harrrry

  • How to get the "Key" for Dimension in SSAS.

    Hi
    How to get the "Key" for Dimension in SSAS.
    (Below value is the PPSParameters table XML column value in PPSDatabase in SharePoint.
    Below three key values are belongs to "Dimension". I have tried to find the key but I could net get it.)
    <NewDataSet>
    <UserValues><Key>16A201A9E75128559F947D58E6D187A9</Key></UserValues>
    <UserValues><Key>7FBEA449A6ED5606973306445839619E</Key></UserValues>
    <UserValues><Key>A8F75F9720817BCD2E1DFC1C1CF1E678</Key></UserValues>
    </NewDataSet>
    Thanks & Regards
    Poomani Sankaran

    To Be Honest there is not one straight Cmdlet that atleast I have come across 
    The best way would if you have Lync monitoring server 
    Using the Lync Server 2013 Monitoring Server
    If you have the Monitoring Server role configured in your environment, and for Lync Server 2013 everyone should!, you can use information contained in the LcsCDR database to pull back the last time a user signed in.  You can run the following query* to
    pull back the user's SIP URI and their last login time:
    USE LcsCDR
    SELECT dbo.Users.UserUri, dbo.UserStatistics.LastLogInTime
    FROM dbo.UserStatistics
    JOIN dbo.Users ON dbo.Users.UserId = dbo.UserStatistics.UserId
    ORDER BY UserUri
    Which produces the following output:
    The advantage to using the Monitoring Server to obtain this data is that unlike the information contained in the rtcdyn database, the information from the LcsCDR data will persist even when the user isn't signed into Lync.
    To get approx count of users enable for Lync Server in your organisation 
    Get-CsUser -Filter {Enabled -eq $true} | MeasurE
    Please not the above command let will give you an approx number not exact 
    From the Monitoring report yet the SIP account that signed in and then from count find out how many user havent signed in this is manual task 
    Hope this is helpful 
    Please remember, if you see a post that helped you please click ;Vote As Helpful" and if it answered your question please click "Mark As Answer" Regards Edwin Anthony Joseph

  • How to get Changed fields in Sales order to create a report

    Dear Gurus,
    How to get the log from sales order for the change of particular field.
    In my scenario, If an user remove the delivery block from sales order I want to capture the date on which this delivery block
    is removed and by whom (User)?
    I know that I can get the log of change but can I get in the form of field updates because further I want to use that date and user name to create a report.
    I hope u got my query. Please reply soon that I can create a report.
    Thanks in advance.
    regards,
    Sanjay

    Hi
    You can use the table CDPOS for tracking the changes at the Table level with the Sales order number
    or Else you can also use AUT10 transaction to track the logs/chanages with START DATE, END DATE and the Transaction code in your case it is VA02
    Please check and revert back
    regards,
    santosh

  • How to get change date in Production Order ?

    Dear Friends,
    I want to know it, how to get change date in Production Order "Administration-TAB".
    F1-Help, It is displayed with "Change date for Order Master". and Structure table "CAUFVD".
    But, CAUFVD is not Transp. Table.
    Which table should I read ?
    Thanks in advance
    Yamazaki-H

    Dear Friend
    Thank you for an answer.
    It was settled.
    Best regards.

  • How to get the Key value in the value help?

    Hi All,
            I am using dropdown by key to display the values from the RFC. I am able to get the text by,
    ISimpleValueSet div = wdThis.wdGetContext().getContext().getModifiableTypeOf ("Header.VH_BUnit").getSVServices().getModifiableSimpleValueSet();
    return div.getText(wdContext.currentHeaderElement().getVH_BUnit());
    Please say how to get the key ?
    Thanks & Regards,
        Mugundhan

    Hi,
        Thanks for ur reply. wdContext.currentHeaderElement().getVH_BUnit() is returning the value in the dropdown only.
    Consider this line..
    return div.getText(wdContext.currentHeaderElement().getVH_BUnit() );
    More simillarly return div.gettKey(................); is there. What value should be given inside. if i gave wdContext.currentHeaderElement().getVH_BUnit() means, it sowing "Cannot convert from object to String " error.
    So i created an object like this,
    Object attributevalue = wdContext.currentHeaderElement().getAttributeValue(IPublicReportrtComp.IHeaderElement.VH__B_UNIT);
    But this too not accepting..
    Thanks & Regards,
       Mugundhan

  • How to find Primary Key for a particular SAP Databse Table?

    Hi Guys,
                  How to find Primary Key and foreign key  for Particular SAP Databse table ?for Ex : EKKO , EKPO , EKKN , EKBE , EKBEH  , EKET and EKETH.
    Thanks,
    Srinivas.

    Use transaction SE11 to display the table. Put the cursor on the field you want to display the check table and click 'Foreign key' push button (a key with an bottom point arrow), then it will show the check table of the foreign of a field.
    Or by just simple double click on the field, a pop-up window of all the attribute (including the foreign key and the check table if exists) will show too.
    <i><b>Please reward point for helpful answer.</b></i>
    Minami

  • How will get stoppage hours for PM02 orders

    Hello Guru,
    I want to find out stoppage hours for PM02 orders according to PM Act Type (eg. PM, predictive maint., TPM, etc). Background is that, our PM02 process schedules maint order as per maint plan & it wont triggers Notification in background so users are unable to enter work details ie. work start date/time & End date/time.
    In this situation, how will get stoppage hours for PM02 orders?
    << Moderator message - Everyone's problem is important. But the answers in the forum are provided by volunteers. Please do not ask for help quickly. >>
    Regards,
    Amol
    Edited by: Rob Burbank on Jan 17, 2011 4:25 PM

    Hi PMAmol,
    As Babu suggest,  You can use Act Start and Act End date and time  from Order Header for your requirement , Now how to use those ?
    Once you do Order Confirmation via IW41 , for first operation mention date and time in  Work Starts on date and time when you start your work,
    Then this date and time will reflect in Act Start in Order Header, after that when you finish your work , then in IW41 along with final Confirmtn tick mention the date and time in Work Start on and Ends on field , when CNF status set on order you can check in order header , this date and time will reflect in Actual End date and time.
    For report you can use Iw39.
    Riyaj

  • How to get all images in indesign CS5 with javascript?

    Hi,everybody,
    How to get all images in indesign CS5 with javascript?I want to delete them.
    Anyone can give me some example codes?
    Thanks,
    Bridge

    Hey!
    This will remove all images from your InDesign document:
    var myLinks = app.activeDocument.links.everyItem().parent;
    for(var i = 0; i < myLinks.length; i++)
        myLinks[i].remove();
    Hope that helps.
    tomaxxi
    http://indisnip.wordpress.com/
    http://inditip.wordpress.com/

  • How to get imac 27 inch to work with asus triple mionitors to work through matro triple head 2 go

    how to get imac 27 inch to work with asus triple mionitors to work through matro triple head 2 go

    I think I got a little ahead of myself explaining my problem, so let me clarify...
    Only the one iMac is having the network file deletion problem, but it is included in the network user logon problem.  So 4 out of 5 of the iMacs have had or are having logon problems with network users accounts using mobile accounts on the systems.  2 of the 4 I have wiped and started over on and the other 2 have different network accounts being used by the primary system users.  The 5th iMac has not caused any problems except I forgot to mention that the USB on it seems flaky.
    So we are apparently full of problems. 

  • How to get rid of the blue underline with green arrows on words and then a pop-up ad appears.

    How to get rid of the blue underline with green arrows on words and then a pop-up ad appears.

    Click here and follow the instructions, or if they don't cover the type of adware on the computer, these ones. If you're willing to use a tool to remove it(you don't need to, but may find it easier), you can instead run Adware Medic; this link is a direct download.
    (119795)

  • How to get the stock of STO Report with suppling Plant/receiving Plant/open

    How to get the stock of STO Report with suppling Plant/receiving Plant/open/close qty.

    MB5T gives you Details of STO which have stok in transit.
    ME2W gives you supplying plant wise STO details.  Also in ME2W , in the ALV report output, if you select  the "delivery Schedule line" icon , you will get details such as , STO qty, Issued qty , undelivered qty etc.

  • How to get the iPhone 5c to pair with my mac book pro and my ue speaker

    How to get the iphone 5c to pair with my mac book pro and my ue speaker

    TerryReynar wrote:
    How to get the iphone 5c to pair with my mac book pro
    You don't. It only sync using iTunes.
    It doesn't "pair".
    and my ue speaker
    What is "ue speaker"?
    Ultimate Ears wirless bluetooth speaker?
    Set speaker to Pairing mode.
    On the iPhone, Settings > BlueTooth.
    Select the speaker.

  • How to get the 4 digit number associated with a SAP icon ( ICON_MAIL )

    Hi Friends,
                   Could anyone please tell me how to get the 4 digit number associated with a SAP icon ( ICON_MAIL ).
                   eg: - For ICON_GREEN_LIGHT the four digit id code is '@08@' (which you can get from ICON table )and the associated 4 digit number is'1003'.
                  Similarly I want to get the 4 digit number for ICON_MAIL(e-mail icon)
    <b><REMOVED BY MODERATOR></b>
    Ashiq
    Message was edited by:
            Alvaro Tejada Galindo

    You can use this report...It's not mine...
    REPORT zdummy_atg_2.
    TABLES: ICON.
    INCLUDE <ICON>.
    FIELD-SYMBOLS: <F>.
    SELECT * FROM ICON.
       ASSIGN (ICON-NAME) TO <F>.
       WRITE:   /(5) <F>, 20 '@',21 ICON-ID+1(2),23 '@',ICON-OLENG,
                ICON-BUTTON,ICON-STATUS,ICON-MESSAGE,ICON-FUNCTION,
                ICON-NAME.
    ENDSELECT.
    Greetings,
    Blag.

Maybe you are looking for

  • ALV Report Print

    Hi All, can any one tel the solution fort me is there any function module to print ALV report with out giving print option manually( user press print button)

  • 64-bit OS on T61p's

    How come there is no option to install any 64-bit OS's on the TP's?  Ideally, I'd like to get XP 64, but am I looking to purchase one OS factory-installed only to change it to 64-bit on my own?

  • SENDING MAIL TO ANOTHER SYSTEM IN INTRANET BY USING SMTP

    hi i am able to send simple smtp messages within the single localhost but i am not able to send it to another system ,plz help me .i also need to get the reply from that system since i am the server. i am using jsp code. i have enclosed the code mail

  • After installing 10.6.7 everything is gone from hard drive

    just as if I did a clean install. I just hit the install when prompted with the software update. There was no message that it would result in a clean wiped install.

  • Single Click on simple tree node

    Hi Experts, I have a problem ,please help me. I need event is trigger on single click on node of simple tree.There is event of double click but i need on single click only. If you have any test program please forward it also. Ankur Garg.