Search code examples
pythonmysqlcprofile

Why query taking more time to execute.


When I execute delete query, It takes more time to execute. I am reading parameters from csv file and the delete data from database using parameters. My delete query is,

delete_query = 'delete from app_outage_dfr_correlation_report_exclusions where start_time= %s AND stop_time= %s AND gil_site_id = %s AND total_time_in_mins = %s;'
args = (start_time,stop_time,gil_site_id,total_time_in_mins,)
cursor.execute(delete_query,args)

When I checked in cProfile, It shows following results.

1/8    0.000    0.000    0.000    0.000 {method 'join' of 'str' objects}
       46    0.000    0.000    0.000    0.000 {method 'lower' of 'str' objects}
        1    0.000    0.000    0.000    0.000 {method 'lstrip' of 'str' objects}
       13    0.000    0.000    0.000    0.000 {method 'match' of '_sre.SRE_Pattern' objects}
        4    0.000    0.000    0.000    0.000 {method 'pop' of 'dict' objects}
        1   11.135   11.135   11.135   11.135 {method 'query' of '_mysql.connection' objects}
        1    0.000    0.000    0.000    0.000 {method 'release' of 'thread.lock' objects}
       27    0.000    0.000    0.000    0.000 {method 'remove' of 'list' objects}
        9    0.000    0.000    0.000    0.000 {method 'remove' of 'set' objects}
       66    0.000    0.000    0.000    0.000 {method 'replace' of 'str' objects}
        3    0.000    0.000    0.000    0.000 {method 'setter' of 'property' objects}

Can anybody tell me why it takes more time to execute. Thank you.


Solution

  • Try to check your query with EXPLAIN SQL statement, perhaps your table is really big, and query take long time to execute.