pomm-project / ModelManager

Model Manager for the Pomm database framework.
MIT License
66 stars 27 forks source link

Does Pomm suffer of the problem of useless order by on some ORM prefetches ? #94

Closed LLyaudet closed 3 months ago

LLyaudet commented 4 months ago

Hello,

Recently I found a problem with Django and submitted a patch in a PR: https://code.djangoproject.com/ticket/35309 https://github.com/django/django/pull/17984 I also developped a work-around for old versions of Django: https://github.com/LLyaudet/django-monkey-patches/blob/main/src/django_monkey_patches/django__orm__prefetch_without_useless_order_by.py

I don't know yet Pomm details. The idea is just that some models can have a default ordering (I assume this functionality is present in Pomm also). And that some ORM may still add this ordering in the SQL query whilst it is not needed because only a single object will be prefetched per instance of the original result set. On very big prefetches I noticed a gain of 10 - 15 %, since the rest of the DB query is mainly an index scan.

ClimateChangeBrake

Can someone please dump the queries of such prefetches and see if the bug is present in Pomm ? If so submitting a PR should not be too hard. I will try to help. But right now, I start by warning the frameworks/ORM I am aware of :)

Best regards, Laurent Lyaudet

chanmix51 commented 3 months ago

Hello Laurent, thank you for making us aware of that kind of climate related problems.

Pomm is not a good candidate for that kind of bugs since most of the time, developers write their own SQL queries in the model's methods.

Of course there are default CRUD SQL queries provided by the framework but they do not use any ordering.

LLyaudet commented 3 months ago

Thanks for your answer :)