I am using sqlalchemy (an expression language not full of ORM) with MySQL and experiencing some unexpected slowness. In particular, the time taken to execute the select query in sqlalchemy is ten times the time taken to execute the same query from the mysql command line.
Exiting cprofile:
ncalls tottime percall cumtime percall filename:lineno(function)
100 206.703 2.067 206.703 2.067 {method 'query' of '_mysql.connection' objects}
MySQL time: 0.26 seconds
The consensus seems to be that there is some overhead using sqlalchemy, but not so much. Any suggestions as to what might cause this behavior?
Requests usually take the form:
SELECT fieldnames.minage, fieldnames.maxage, fieldnames.race,
fieldnames.sex, sum( pop.population ) AS pop, pop.zip5
FROM pop
INNER JOIN fieldnames ON fieldnames.fieldname = pop.fieldname_id
WHERE fieldnames.race IN ("White alone")
AND fieldnames.sex IN ("Female")
AND fieldnames.maxage >=101
AND fieldnames.minage <=107
GROUP BY fieldnames.minage, fieldnames.maxage
source
share