DB_GET_BOTH_RANGE fails when there is only one record for a key

Using the DB_GET_BOTH_RANGE flag doesn't seem to work when there is a
single record for a key.
Here's a sample Python program that illustrates the problem. If you
don't know Python, then consider this to be pseudo code. :)
from bsddb3 import db
import os
env = db.DBEnv()
os.mkdir('t')
env.open('t',
db.DB_INIT_LOCK | db.DB_INIT_LOG | db.DB_INIT_MPOOL |
db.DB_INIT_TXN | db.DB_RECOVER | db.DB_THREAD |
db.DB_CREATE | db.DB_AUTO_COMMIT)
data = db.DB(env)
data.set_flags(db.DB_DUPSORT)
data.open('data', dbtype=db.DB_HASH,
flags=(db.DB_CREATE | db.DB_THREAD | db.DB_AUTO_COMMIT |
db.DB_MULTIVERSION),
txn = env.txn_begin()
#data.put('0', '6ob 0 rev 6', txn)
data.put('0', '7ob 0 rev 7', txn)
#data.put('0', '8ob 0 rev 8', txn)
data.put('1', '9ob 1 rev 9', txn)
txn.commit()
cursor = data.cursor()
print cursor.get('0', '7', flags=db.DB_GET_BOTH_RANGE)
cursor.close()
data.close()
env.close()
This prints None, indicating that the record who's key is '0' and
who's data begins with '7' couldn't be found. If I uncomment wither of
the commented out puts, so that there is more than one record for the
key, then the get with DB_GET_BOTH_RANGE works.
Is this expected behavior? or a bug?

You can use the DB_SET flag which will look for an exact key match. If
you use it with the DB_MULTIPLE_KEY flag, it will return multiple keys
after the point it gets a match. If you can post here how all your
LIKE QUERIES look, I may be able to provide you with the suited
combination of the flags you can use for them.I'm not doing like queries. I'm using BDB as a back end for an object
database. In the object database, I keep multiple versions of object
records tagged by timestamp. The most common query is to get the
current (most recent version) for an object, but sometimes I want the
version for a specific timestamp or the latest version before some
timestamp.
I'm leveraging duplicate keys to implement a nested mapping:
{oid -> {timestamp -> data}}
I'm using a hash access method for mapping object ids to a collection
of time stamps and data. The mapping of timestamps to data is
implemented as duplicate records for the oid key, where each record is
an 8-byte inverse timestamp concatenated with the data. The inverse
timestamps are constructed in such a way that they sort
lexicographically in inverse chronological order. So there are
basically 3 kinds of query:
A. Get the most recent data for an object id.
B. Get the data for an object id and timestamp.
C. Get the most recent data for an object id who's timestamp is before
a given timestamp.
For query A, I can use DB->get.
For query B, I want to do a prefix match on the values. This can be
thought of as a like query: "like <inverse-time-stamp>%", but it can
also be modelled as a range search: "get the smallest record that is >=
a given inverse time stamp". Of course, after such a range search,
I'd have to check whether the inverse time stamp matches.
For query C, I really want to do a range search on the inverse time
stamp prefixes. This cannot be modelled as a like query.
I could model this instead as {oid+timestamp -> data}, but then I'd
have to use the btree access method, and I don't expect that to scale
as I'll have hundreds of millions of objects.
We tried using BDB as a back end for our database (ZODB) several years
ago and it didn't scale well. I think there were 2 reasons for
this. First, we used the btree access method for all of our
databases. Second, we used too many tables. This time, I'm hoping that
the hash access method and a leaner design will provide better
scalability. We'll see. :)
If you want to start
on a key partial match you should use the DB_SET_RANGE flag instead of
the DB_SET flag.I don't want to do a key partial match.
Indeed, with DB_GET_BOTH_RANGE you can do partial
matches in the duplicate data set and this should be used only if you
look for duplicate data sets.I can't know ahead of time whether there will be duplicates for an
object. So, that means I have to potentially do the query 2 ways,
which is quite inconvenient.
As you saw, the flags you can use with cursor.get are described in
detailed here.But it wasn't at all clear from the documentation that
DB_GET_BOTH_RANGE wouldn't work unless there were duplicates. As I
mentioned earlier, I think if this was documented more clearly and
especially of there was an example of how one would work around the
behavior, someone would figure out that behavior wasn't very useful.
What you should know is that the usual piece of
information after which the flags are accessing the records, is the
key. What I advice you is to look over Secondary indexes and Foreign
key indexes, as you may need them in implementing your queries.I don't see how secondary indexes help in this situation.
BDB is
used as the storage engine underneath RDBMS. In fact, BDB was the
first "generic data storage library" implemented underneath MySQL. As
such, BDB 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.Yup.
Sometimes you may find it unsatisfying, but it may be more
efficient than you think.Sure, I just think the notion that DB_GET_BOTH_RANGE should fail if
the number of records for a key is 1 is rather silly. It's hard for me
to imagine that it would be less efficient to handle the non duplicate
case. It is certainly less efficient to handle this at the application
level, as I'm likely to have to implement this with multiple database
queries. Hopefully, BDB's cache will mitigate this.
Thanks again for digging into this.
Jim

Similar Messages

  • Search help dialog when there is only one entry

    Hi experts,
    I am developing a Webdynpro app and I can't find the way of skiping the search help dialog when there is only one entry on the result, just like in SE37 when you put the function name with * and it automatically puts the only ocurrence in the field with no dialog for selection. Right now my application is working correctly but it alwas show the dialog even when there is only one entry on the result.
    Thanks in advance!
    Daniel
    Moderator message - Moved to the correct forum
    Edited by: Rob Burbank on May 4, 2011 2:35 PM

    Hi,,
    Use OVS to  achieve this., when u press start search select the values from table into internal table (lt_object_list)
    n = lines( lt_object_list ).  " this gives the number of records in internal table..
    if n = 1.
    set_attribute(  ) .. to the input field.
    else.
    co phase 3.
    call popup window to display objects
    endif.
    hope this helps u.,
    Thanks & Regards,
    Kiran

  • I am no longer able to use a keyboard shortcut to close a window when there is only one window open.

    I can use Command+W when there are multiple tabs open to close one window at a time, but not when there is only one window remaining. It's driving me crazy because I have to click on the red dot. It won't close with File > Close either. Nothing changed (that I know of) from last week to this that would cause this. It works fine in safe mode but I can't figure out what's conflicting. Also, I've tried reinstalling Firefox but that did nothing. Help?

    Problem solved! It's the Evernote add-on. They updated something on November 6. I've disabled it until that quirk is fixed. Thanks.

  • Why does fix capitalization work when there is only one space after the period in pages 09?

    why does fix capitalization work when there is only one space after the period in pages 09?  For example:  "Turn on 3rd St. After the traffic light."  There is only one space after the period in "St."  shouldn't it only auto correct after TWO spaces..??  the word After, should be after..

    You may also use a noBreak space after the period at the end of the abbreviation.
    If I remember well, in such case the capitalization will not apply.
    Yvan KOENIG (VALLAURIS, France) mercredi 27 avril 2011 23:34:46

  • Why does it say More. . . in email address line when there is only one email address?

    When receiving an email, why does it say 'More. . .' in the To email address line when there is only one email address? It looks like there is more than one recipient when there is actually just one. 

    Have you rebooted since the deletions.  That will empty a number of caches and may restore the freed up space. Also open the iPhoto Library package with the Finder as shown in this screenshot
    locate the iPod Photo Cache folder and delete its contents.  Make no other changes to the contents of the iPHoto LIbrary Package.
    OT

  • Why can I not set a member attribute when there is only one child below the member?

    Why can I not set a member attribute when there is only one child below the member?The "member attribute" tab on the properties window of App Manager is grayed out. What am I forgetting?TIA,Craig Wahlmeier

    Most likely because Essbase is creating an implicit share relationship between the two members, which is causing the association tab to be grayed out. Tag the parent member with the "Never Share" attribute and see if that fixes the problem.Regards,Jade-----------------------------------Jade ColeSenior Business Intelligence ConsultantClarity [email protected]

  • 3D Axis System (bar type) doesn't work when there is only one z-channel

    Hello,
    I have a problem with a 3D Axis System, bar type.
    Everything works fine as long as the y-channel contains more than one value (meaning there is more than one z-channel too).
    But when my y-channel has only one value, and there is only one z-channel, the axis system goes blank (there is just an empty white field with a thin outline).
    I don't understand why it doesn't work that way. The length of my one z-channel is the same length as my x-channel, as it should be.

    HI, 
    could you describe your hardware and software setup?
    If this is possible please attache your project.
    Roman Rolnik
    Application Engineer
    NI Germany

  • Two SSL Certificates when there is only one

    I am getting my server set up with third party authentication.  Everything is checking out except that when I do a check, my server is reporting two certificates that are completely identical.  However, there is only one in the certificates section and only one in the keychain.  I am lost as to why it is responding with two certificates.  Because of this, my third party SSL certifier is stating I am improperly configured.

    OS X Server will create a self-signed certificate on initial setup.  For example, let's say your server is mini.cpnea.com.  A self-signed cert will be created on initial server setup.  Then you purchase one with the same host name, mini.cpnea.com.  Once you install it, the server has two, the self-signed and the 3rd party trusted one.  To get rid of the self signed, follow these steps.
    1. Launch Server.app
    2:  Select Certificates from the sidebar
    3:  Reveal the popup "Secure services using" and select your purchased cert (the icon should be blue as self signed are brown).
    4:  This will release the self-signed from being in use
    5:  Click on the Gear button and choose Show all Certificates
    6:  Select the self-signed (brown) certification and then press the - button to delete it.
    That should do it.
    R-
    Apple Consultants Network
    Apple Professional Services
    Author "Mavericks Server – Foundation Services" :: Exclusively available in Apple's iBooks Store

  • Security Filter fails when level has only one member

    Hi.
    This is Essbase version 9.3. I have a forecast app\db to allow users enter\modify the forecast of the different products. The Product Dimension has the following hierarchy.
    All Products
    Planner 1
    Supplier A
    Product_A1
    Product_A2Supplier B
    Product_B1
    Product is the lowest level, level 0, or Gen 4.
    I need to allow the "Planner 1" to write only to his products, where the member is "My Scenario" from Scenario Dimension, and where the UDA's for the month is Forecast. The same planner can't write to the "All Products", "Planner" and "Supplier" levels.
    I have created the following filter:
    None: "All Products"
    Read: @IDESCENDANTS("Planner 1")
    Write: @REMOVE(@LIST(@DESCENDANTS("Planner 1")),@LIST(@LEVMBRS ("Planner 1", 1))), "My Scenario",@UDA("Time","FORECAST")
    Basically, this is the portion most relevant of the filter: @REMOVE(@LIST(@DESCENDANTS("Planner 1")),@LIST(@LEVMBRS ("Planner 1", 1)))
    where
    @LIST(@DESCENDANTS("Planner 1") = List of descendants members from Planner 1, excluding Planner 1. = "FIRST LIST"
    @LIST(@LEVMBRS ("Planner 1", 1)) = List of level 1 members from Product Dimension. = "SECOND LIST"
    @REMOVE will remove values or members in the "SECOND LIST" from the "FIRST LIST".
    This filter works perfectly but it has a little\big exception...
    Based on the example, the filter works fine for Supllier A. Meaning that the user can modifiy the forecast for the products under Supplier A (Product_A1 and Product_A2), and the user can't modify the upper levels, "Supplier A", "Planner 1", "All Products". This is GOOD!
    Now. For Supplier B, Essbase will allow write back to the Product_B1, OK. But will also allow write back to Supplier B, the upper level.
    So. When the supplier has only one product, Essbase presents this exception that allows write to the upper level. This happens everywhere a supplier has only one product. When there are more than one product per supplier, the filter works as expected.
    Is there a missing piece in my filter? Is there a different, better approach to accomplish this?
    Thanks.

    It's probably an implied share problem. That is, because Supplier B has only one child it is treated as a shared member. You can use the "never share" storage property setting to avoid that problem.

  • I write a mail and send it but when there is only one word per line. What do I wrong?

    I write many word per line but when I send it will turn to be only one word per line

    Did you check the HTML code of that message to see if tags like "span" or "p" or "div" were added or other CSS code to limit the width?

  • Get only one record for an id for a date if multiple record exists

    Hi,
    I need help with below mentioned scenario.
    DB Version: 11.2.0.3.0.
    Requirement:
    Fetch account records that were created after last run of program
    Get latest record for an account on a given date if there are multiple records for same account.
    If there is a gap of more than 1 day from last run of program, then get latest record for an account for each date if there are multiple records for same account.
    Create table t_test
      Id           number not null,
      cust_id      number not null,
      cust_Acct_id number not null,
      ins_date     date   not null
    insert into t_test values
    (1, 12345, 678905, to_date('05/31/2012 12:05:10 PM','MM/DD/YYYY HH:MI:SS PM'));
    insert into t_test values
    (2, 12345, 678905, to_date('05/31/2012 05:25:46 PM','MM/DD/YYYY HH:MI:SS PM'));
    insert into t_test values
    (3, 12345, 678905, to_date('05/31/2012 11:48:00 PM','MM/DD/YYYY HH:MI:SS PM'));
    insert into t_test values
    (4, 12345, 678905, to_date('06/01/2012 12:05:10 PM','MM/DD/YYYY HH:MI:SS PM'));
    insert into t_test values
    (5, 12345, 678905, to_date('06/01/2012 05:25:46 PM','MM/DD/YYYY HH:MI:SS PM'));
    insert into t_test values
    (6, 12345, 678905, to_date('06/01/2012 11:48:00 PM','MM/DD/YYYY HH:MI:SS PM'));
    insert into t_test values
    (7, 12345, 678905, to_date('06/02/2012 12:05:10 PM','MM/DD/YYYY HH:MI:SS PM'));
    insert into t_test values
    (8, 12345, 678905, to_date('06/02/2012 05:25:46 PM','MM/DD/YYYY HH:MI:SS PM'));
    insert into t_test values
    (9, 12345, 678905, to_date('06/02/2012 11:48:00 PM','MM/DD/YYYY HH:MI:SS PM'));
    create table t_log
      id            number not null,
      prgrm_id      number not null,
      last_run_date date   not null
    insert into t_log values
    (1,1009,to_date('5/30/2012 07:05:12 AM','MM/DD/YYYY HH:MI:SS PM'));Result required:
    id cust_id cust_acct_id ins_date
    3 12345 678905 '05/31/2012 11:48:00 PM'
    6 12345 678905 '06/01/2012 11:48:00 PM'
    9 12345 678905 '06/02/2012 11:48:00 PM'
    I tried below sql but it will return only id 9 record.
    select
        id,
        cust_id,
        cust_acct_id,
        ins_date
    from
        select
            id,
            cust_id,
            cust_acct_id,
            ins_date,
            row_number() over (partition by cust_acct_id order by ins_date desc) rn
        from
            t_test t
        where
            t.ins_date > (
                          select
                              last_run_date
                          from
                              t_log l
                          where
                              l.prgrm_id = 1009
    where rn = 1;Thanks in advance.

    Try:
    SQL> select
      2      id,
      3      cust_id,
      4      cust_acct_id,
      5      ins_date
      6  from
      7      (   
      8      select
      9          t.id,
    10          t.cust_id,
    11          t.cust_acct_id,
    12          t.ins_date,
    13          row_number() over (partition by cust_acct_id, trunc(ins_date) order by ins_date desc) r
    n
    14      from
    15          t_test t
    16      ,   t_log l 
    17      where
    18          t.ins_date >= l.last_run_date
    19      and l.prgrm_id = 1009
    20      )
    21  where rn = 1;
            ID    CUST_ID CUST_ACCT_ID INS_DATE
             3      12345       678905 31-05-2012 23:48:00
             6      12345       678905 01-06-2012 23:48:00
             9      12345       678905 02-06-2012 23:48:00But I now see that Bob already nailed it, while I was testing it ;)

  • Displaying only one value for a key figure

    Hi guys,
    I am building a query in BEx Analyzer (v 3.5) where I am facing a difficult requirement.
    In the cube I have the following structure:
    Bank Account | Date | (.....) | KF: Amount | KF:Closing Balance
    A                   | 29.10.2008  | 300             |  5000
    A                   | 29.10.2008  | 100             |  5000
    A                   | 29.10.2008  | 600             |  5000
    As you can see there is one entry for every movement on the account for each day, while the closing balance is the same and entered for each record.
    It is not an option to change this logic in the source system.
    The problem is that I don't have any differentiating characteristics that is useful for the query and I only want to display the closing balance once (i.e. 5000). Now I am getting 15000.
    Is there any way to do this without adding new characteristics?
    Will appreciate all ideas!
    Br,
    TM

    Hi TM,
    Did you try with the aggregation: Set this to Maximum in stead of Sum.
    Success,
    Udo

  • Omit -01 from exported filename when there's only one artboard

    99% of my files only have one artboard and when I export them as TIFFs I just want the base filename, not one with -01 at the end which I have to remove later. I know I can uncheck "Use Artboards" but I use the artboard to "crop" and export only a part of the document as a TIFF.  Also, it would also be nice if it remembered the last format I chose every time, not PNG.

    Thanks! Unfortunately that didn't make any difference. Something we did notice though, is that when zoomed way in (800%+) it looks perfectly fine. And, it also looks fine on my computer (the computer it was created on) but not on two other monitors in the same room, both with Acrobat 9 Pro. FYI I am using CS4 on a Dell machine.
    We are going to proceed using this weird file out of necessity, but if anyone has any more insights on this problem I'd love to hear it.
    I am attempting to attach an image of the two PDFs side by side, hope it works. These are each zoomed to 'Fit Width' and are from different machines.
    [IMG]http://i1001.photobucket.com/albums/af134/GT-Indy/Good-Bad-PDF.jpg[/IMG]

  • Why does my iPhoto Library say 32gb when there's only one photo in it?

    I am trying to figure out why my MacBook Air is running out of space, and am finding out that Photostream isn't photos in the cloud, it's photos in the cloud that it stores on my different computers hard drives or storage. So, I turned off Photostream, and deleted the pics as Disk Inventory X is telling me that my iPhoto Library is taking up 32.7gb of storage, despite there only being one picture in there that is no special picture. I deleted all the rest. There is ONE picture in the whole iPhoto Library, I deleted all the rest! What is taking up 32gb of my HD???

    Have you rebooted since the deletions.  That will empty a number of caches and may restore the freed up space. Also open the iPhoto Library package with the Finder as shown in this screenshot
    locate the iPod Photo Cache folder and delete its contents.  Make no other changes to the contents of the iPHoto LIbrary Package.
    OT

  • ITunes shows duplicates of about 35 songs when there's only one file...

    In my library everytime I add a folder to the Library it shows duplicates of certain songs and it won't let me send one copy to the trash. Everytime I go to add more songs they all show up again, which is really frustrating because I'm trying to organise my library...any ideas n what to do?
    Compaq Presario R3000   Windows XP   It pwns.

    hi,
    The listener at the standby site spawns the RFS process according to the connection received. What is log archive max process set ?Its not just two RFS process we can see many..
    SQL> SELECT PROCESS, STATUS, THREAD#, SEQUENCE#, BLOCK#, BLOCKS FROM V$MANAGED_STANDBY;
    PROCESS   STATUS          THREAD#  SEQUENCE#     BLOCK#     BLOCKS
    ARCH      CONNECTED             0          0          0          0
    ARCH      CONNECTED             0          0          0          0
    MRP0      APPLYING_LOG          2      56362      17111     601526
    RFS       IDLE                  0          0          0          0
    RFS       IDLE                  0          0          0          0
    RFS       IDLE                  0          0          0          0
    RFS       IDLE                  0          0          0          0
    RFS       IDLE                  1      60056          0          0
    RFS       IDLE                  0          0          0          0
    RFS       IDLE                  0          0          0          0
    RFS       IDLE                  0          0          0          0
    RFS       IDLE                  0          0          0          0
    12 rows selected.baskar.l

Maybe you are looking for

  • Adobe Cloud window and adobe air not showing up or starting even though it is installed, i have tried reinstalling/uninstalling

    I downloaded muse cc 2014. It worked fine for a while (couple of bugs though). Yesterday it would crash whenever it was launched. So i tried to uninstall and re-install. No Luck. Then noticed adobe cloud/adobe air windows were not starting up as per

  • Posting to GL trying to test

    Hi all I have created a company code and woould like to test it. If its possible please explain step by step, i have been using transaction FBN1 but do not know how to go about it. Thanks!

  • Setting Timeout  in URLConnection/HttpURLConnection

    Hi all, I am trying to open a connection a website using the java.net.HttpURLConnection. Please tell me what is the default timeout (how much time it will wait for getting reply ) and how we can change the default value. Please help me. Thanks in adv

  • Need help improving XP SP3 performance on 4-core Mac Pro 2009

    I'm running Windows XP SP3 under Boot Camp 3 (Mac OS X v. 10.6.2). Currently, XP is on a second partitioned HD, but it was previously running on a drive all its own with the same problems which are: When I boot into Windows the sound stutters quite a

  • G70 120em hdmi out put

    Using hdmi on my 3 week old G70 120em I only get blank screen on my Panasonic 42PX plasma tv. I have also Used Friends TV's Sony and Samsung LCD but on response. The computer sees the TV as I get the name up on the nvidia page. I have used advice fro