Friday, 23 August 2013

Query performance difference SQLAlchemy vs pgAdmin

Query performance difference SQLAlchemy vs pgAdmin

I'm testing a query in pgAdmin and SQLAlchemy and found that the execution
time of both varies substantially (SQLA=0.9sec, pgAdmin=0.090s) . I wonder
how this could be?
This is how I profile the SQLA code:
start_time = time.time()
result = session.query(Parent).all()
# I disabled printing...
print 'query execution=', time.time() - start_time, 'seconds'
For pgAdmin, I read the execution speed from the query editor in the
bottom right corner.
What can I do to align both? I would expect SQLA to be a bit slower, but
not this much...
Update I tried querying the database using raw SQL via SQLA and it's
getting close enough to the pgAdmin query speed. Even if I discounted for
the query generation time, I can't get anywhere near the raw SQL
performance using the SQLA ORM (still 10x slower).

No comments:

Post a Comment