为什么查询需要更多时间来执行。

时间:2017-03-24 10:32:05

标签: python mysql cprofile

当我执行删除查询时,执行需要更多时间。 我正在使用参数从csv文件读取参数和从数据库中删除数据。 我的删除查询是,

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)

当我签入cProfile时,它会显示以下结果。

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}

有人可以告诉我为什么需要更多时间来执行。谢谢。

1 个答案:

答案 0 :(得分:0)

尝试使用EXPLAIN SQL语句检查您的查询,也许您的表格确实是,并且查询需要很长时间才能执行。