Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/72.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中使用sqlite3时会遇到如此缓慢的fetchmany()性能?_Python_Sql_Performance_Sqlite - Fatal编程技术网

为什么我在python中使用sqlite3时会遇到如此缓慢的fetchmany()性能?

为什么我在python中使用sqlite3时会遇到如此缓慢的fetchmany()性能?,python,sql,performance,sqlite,Python,Sql,Performance,Sqlite,我有两个表,有大约900万到1200万条记录,所有列(每个列30列)都通过主键连接。然后,我一次将100000行(也尝试了1000、10000等)加载到内存中,以分块处理它 此查询需要约9秒的SQL时间: 9477056行以9646ms的速度从以下位置返回:使用(符号)从“tableA_2019-12-08”A中选择A,从“tableA_2019-12-08”A连接到“tableB_2019-12-08” 但我在python中看到了250-300秒 下面是python代码: myQuery =

我有两个表,有大约900万到1200万条记录,所有列(每个列30列)都通过主键连接。然后,我一次将100000行(也尝试了1000、10000等)加载到内存中,以分块处理它

此查询需要约9秒的SQL时间:

9477056行以9646ms的速度从以下位置返回:使用(符号)从“tableA_2019-12-08”A中选择A,从“tableA_2019-12-08”A连接到“tableB_2019-12-08”

但我在python中看到了250-300秒

下面是python代码:

myQuery = "SELECT {} FROM '{}' A JOIN '{}' B USING(Symbol)".format(ColumnsToSelect,table1_name,table2_name)
c.execute(myQuery)
nr = 0
while c.fetchmany(100000) != []: # this will break when no more rows will be returned i.e end of table
    nr+=1
    print(nr)
    results = c.fetchmany(100000)
    #code to process results goes here but I commented it out to test the fetchmany speed```

Does anyone know why this is happening?

Edit: Tried changing it to this but I have the same issue, taking 250 seconds:

```DataProcessed = False
    start_time_diffgen = time.time()
    while DataProcessed is not True: # this will break when no more rows will be returned i.e end of table
        result = c.fetchmany(1000000)
        nr+=1
        if result == []:
            DataProcessed = True```

您正在while语句中调用
fetchmany()
,而没有将结果分配给变量。这实际上是丢弃100000行,然后将接下来的100000行存储在
结果中,然后丢弃接下来的100000行,…打印从来都不是对执行速度/效率的良好测试。相反,您只是在测试打印到控制台的速度。根据文本输出缓冲、开发环境等的不同,这可能会有很大的差异。谢谢,我当时尝试过更改代码(请参阅主要的后期编辑),但同样花费了大约252秒的时间,这似乎太多了。这个代码看起来还是错的吗?