views:

40

answers:

1

I'm writing a script for exporting some data.

Some details about the environment:

  • The project is Django based
  • I'm using raw/custom SQL for the export
  • The database engine is MySQL.
  • The database and code are on the same box.-

Details about the SQL:

  • A bunch of inner joins
  • A bunch of columns selected, some with a basic multiplication calculation.
  • The sql result has about 55K rows

When I run the SQL statement in the mysql command line, it takes 3-4 seconds

When I run the SQL in my python script the line cursor.execute(sql, [id]) takes over 60 seconds.

Any ideas on what might be causing this?

A: 

Two ideas:

  1. MySQL may have query caching enabled, which makes it difficult to get accurate timing when you run the same query repeatedly. Try changing the ID in your query to make sure that it really does run in 3-4 seconds consistently.

  2. Try using strace on the python process to see what it is doing during this time.

Jason Hildebrand