Ebean ORM adds sort by t0.id
clause to every query and it leads to very very bad performance.
I use Play Framework 2.6, H2 1.4 database and Ebean 11.15 (PlayEbean 4.1.3). I have a table with 100k rows and it grows lager.
I have several schedules tasks which select a batch of records from the table and process data, and order doesn't matter.
So for example I use this query:
Chunk.find.query()
.select("id, lat, lon, data, status")
.fetch("area", "id, polygon")
.setMaxRows(100)
.where()
.eq("status", 0)
.query()
.findList();
Then Eben generates and executes this:
select
c.id,
c.lat,
c.lon,
c.data,
c.status,
a.id,
a.polygon
from chunk c
join area a on a.id = c.area_id
where c.status = 0
order by c.id
limit 100;
It would be superb to have no order by c.id
.
If i execute the query manually it will take ~5000 ms. But if I remove the order by
clause it will take ~10 ms only! And there's so much places in my appication where I do not need sorting and it could work a lot faster.
The only solution for now is to use .orderBy("1")