ObjectDB ObjectDB

Issue #2853: Logical "or" works not correcly when field is @Id and first position

Type: Bug ReoprtVersion: 2.8.8_05Priority: HighStatus: FixedReplies: 3

The following code doesn't respect the logical "or" correctly. Instead of returns all 2 datasets it returns only this one, which matches the first predicate in the or. BUT: this happens only, if the field for the "or" is the first one defined as @Id.

public class OrTest {
    static class Data {
        Data(String a, String b) {
            this.a = a;
            this.b = b;
        String a;
        String b;
        public Data() {

    public static void main(String[] args) {
        EntityManagerFactory emf = Persistence.createEntityManagerFactory("or_test.odb");
        EntityManager em = emf.createEntityManager();
        em.persist(new Data("1", "x"));
        em.persist(new Data("12", "y"));
        CriteriaBuilder builder = em.getCriteriaBuilder();
        CriteriaQuery<Data> query = builder.createQuery(Data.class);
        Root<Data> root = query.from(Data.class);
            builder.equal(root.get("a"), "1"),
            builder.like(root.get("a"), "1%")

This outputs instead of 2 only:


If you change the order:

        String b;
        String a;

the code outputs:


What is wrong? I'm afraid that the order of @Id changes query behaviour to wrong.


One more hours of research later it seems, whenever an indexed field (means b-tree can used) is inside an or condition, the query optimizer using only the b-tree for the query and the other part of the or is ignored.

For the database created with the example code above, this query also returns only the object matches the b-tree (field "a"). The condition regarding the "b" field is ignored.

select from Data where b = 'x' or a = '12'

The ObjectDB Explorer says:

Query plan 1/1 description

[Step 1]
Scan type org.example.OrTest$Data
locating OrTest$Data (this) instances that satisfy:

[Step 2]
Apply selection and prepare final results.

<btreePlan 3.6393 1,18/1,18 this(OrTest$Data) type(OrTest$Data[or(['12'->'12':notNull],[pos<1>'x'->'x':notNull])]) />

This means, everybody using or conditions for indexed fields went into wrong results.


Thank you for this report. Version 2.8.9 should fix the issue.

ObjectDB Support

Thanks to the support 🤟 It works now!



To post on this website please sign in.