This discussion is archived
3 Replies Latest reply: Sep 27, 2012 8:58 AM by greybird RSS

Querying with or condition - Berkley DB JE

964469 Newbie
Currently Being Moderated
Hi,

How to implement these queries in DPL?

select * from table1 where table1.a1="X" or table1.b1="Y";

select * from table1 where table1.a1="X" or table1.a1="Y";
  • 1. Re: Querying with or condition - Berkley DB JE
    Charles Lamb Pro
    Currently Being Moderated
    Although it may not answer your question directly, you may want to refer to this whitepaper:

    [Performing Queries in Oracle Berkeley DB Direct Persistence Layer|http://www.oracle.com/technetwork/products/berkeleydb/performing.pdf]


    Charles
  • 2. Re: Querying with or condition - Berkley DB JE
    964469 Newbie
    Currently Being Moderated
    Thanks for the reply..

    I have already gone through this doc. it says only for AND Condition (EntityJoin).
  • 3. Re: Querying with or condition - Berkley DB JE
    greybird Expert
    Currently Being Moderated
    I thought the white paper at least mentioned OR conditions, but perhaps it doesn't go into enough detail.

    You have two choices.

    1) Scan all records and filter them using the two conditions.

    2) Do two queries, one for each condition, and union the results.

    In other words, there is nothing built-in that helps you with this. You have to implement the query yourself. And you have to decide which approach will perform best, preferably based on testing.

    For example, a full scan (option 1) can be very expensive if you have a large number of records, so option 1 is usually more expensive than option 2. But on the other hand, if the majority of all records qualifies (will be selected by the query), then a full scan may be the most efficient option.

    --mark                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points