0

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.

Prafulla
  • 73
  • 2
  • 12

1 Answers1

0

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

Oleg Butuzov
  • 4,795
  • 2
  • 24
  • 33
  • In my table 4Lacs+ record available. @Oleg Butuzov – Prafulla Mar 24 '17 at 10:35
  • So (for everyone including me who is not Indian) you have more than **400000** records in your table. And you running delete wich takes 11 seconds what is a lot. I would suggest optimising your table and sql. Problem you have no in python, the problem in your data structure and sql statement. Imaging it check every single row while your query - it's obviously slow.. – Oleg Butuzov Mar 24 '17 at 10:59