1

I am trying to minimize select query execution times in SQLAlchemy ORM. I tried to see the relative execution time for with_entities and load_only. The database I am working on currently does not have too many entries so I can't really test the efficiency on really large queries. But these are the execution times.

--- 0.0027773380279541016 seconds (load only)---
--- 0.003949403762817383 seconds (with entities)---

Now, load_only creates an SQLAlchemy ORM object wrapping up the selected columns and defers loading additional columns until specifically called for. with_entities simply loads the column values and doesn't form any object. I followed this question for the information.

Therefore I assumed that with_entities should be marginally faster than load_only but I am seeing the opposite here.

Is there any reason for this? Purely accidental or something else? Any help would be appreciated. Thanks in advance.

Shiladitya Bose
  • 893
  • 2
  • 13
  • 31

0 Answers0