2.9.x query issue with @Unique constraint

#1

Query doesn't return results in versions 2.9.x when there's a unique property in (where/and .. or ..) clause. It ignores the or operator.


@Entity public class User { .. @Unique private String userName; .. }

select u
from User u
where (u.userName = :userName or :userName is null)

// null input for :userName parameter

2.8.9
Query plan description
============================

[Step 1]
Scan type User
locating all the User (u) instances.

[Step 2]
Evaluate fields in User (u) instances.

[Step 3]
Filter the results of step 2
retaining only results that satisfy:
  or((:userName==null),(u.userName=:userName)).

[Step 4]
Apply selection and prepare final results.

<filterPlan 3.786 0.76/1.18 or((:userName==null),(u.userName=:userName))>
  <extractPlan 3.7225 0.70/1.18 u(User)>
    <btreePlan 3.6342 0.70/1.18 u(User) type(User[all]) />
  </extractPlan>
</filterPlan>

 


2.9.x
Query plan description
============================

[Step 1]
Scan index User[userName]
locating User (u) instances that satisfy:
  (u.userName=:userName).

[Step 2]
Order the results of step 1 by:
  u.

[Step 3]
Use NULL as a result (for LEFT OUTER JOIN).

[Step 4]
Merge the results of steps 2, 3 using OR.

[Step 5]
Apply selection and prepare final results.

<mergePlan or 3.1183 0.72/-0.43 0>
  <orderPlan 4.9074 0.71/-0.12 u>
    <btreePlan 3.0043 0.71/-0.12 u(User) index(-101[(u.userName=:userName)]) />
  </orderPlan>
  <onlyNull />
</mergePlan>
#2

The difference in the results between 2.8.9 and 2.9.x is the selection of the query plan, where in this case version 2.9.x uses an index (probably generated for the @Unique annotation you mentioned). However, both query plans seems correct.

Maybe the index is broken. Try to fix the database by running the Doctor and check if the repaired database works properly.

If not, is it possible to share a sample database with that issue?

ObjectDB Support
#3

Thank you for your reply.

This is the database file.

The query works as expected in 2.8.9 but not in 2.9.x

#4

Thank you for this report. Please check version 2.9.2_02, which should solve it.

ObjectDB Support
#5

It works fine in 2.9.2_02, thank you.

Reply