Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/63.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 为什么查询需要更多的时间来执行。_Python_Mysql_Cprofile - Fatal编程技术网

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

Python 为什么查询需要更多的时间来执行。,python,mysql,cprofile,Python,Mysql,Cprofile,当我执行delete查询时,它需要更多的时间来执行。 我正在从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,st

当我执行delete查询时,它需要更多的时间来执行。 我正在从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}

有人能告诉我为什么执行起来要花更多的时间吗。谢谢。

请尝试使用EXPLAIN SQL语句检查您的查询,可能您的表太大了,执行查询需要很长时间。

在我的表4Lacs+记录中可用@Oleg ButuzovSo(包括我在内的所有非印度人)您的表中有40多万条记录。你运行delete wich需要11秒,这真是太多了。我建议优化您的表和sql。python中没有的问题,数据结构和sql语句中的问题。在你的查询过程中检查每一行,这显然很慢。。