Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/351.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 使用SQL Alchemy和pandas read_SQL避免内存问题_Python_Mysql_Pandas_Memory_Singlestore - Fatal编程技术网

Python 使用SQL Alchemy和pandas read_SQL避免内存问题

Python 使用SQL Alchemy和pandas read_SQL避免内存问题,python,mysql,pandas,memory,singlestore,Python,Mysql,Pandas,Memory,Singlestore,我有一个查询,可以在特定条件下获取一天中的所有记录,这个查询被插入到python循环中,以从我的MySQL(我相信是memsql)数据库中获取数据 根据查询输出大小,我在循环中的某个点收到以下错误(屏蔽了一些信息): pymysql.err.OperationalError: (1712, 'Leaf Error (ip_address:port): Query execution memory use (xxx MB) has reached the maximum memory for it

我有一个查询,可以在特定条件下获取一天中的所有记录,这个查询被插入到python循环中,以从我的MySQL(我相信是memsql)数据库中获取数据

根据查询输出大小,我在循环中的某个点收到以下错误(屏蔽了一些信息):

pymysql.err.OperationalError: (1712, 'Leaf Error (ip_address:port): Query execution memory use (xxx MB) has reached the maximum memory for its resource pool `pool_name` (y%).')
查询的相关代码位设置如下:

engine = create_engine(engine_string, echo=False)
for day in year:
    query = "sql query with variables that change the days within the loop"
    df = pd.read_sql(query, con=engine)
这里我发现最奇怪的是,如果我将查询更改为限制性更强,并减少结果数据集,我可以在内存错误消失之前迭代更多天的查询


如何避免这种情况?

我猜在循环时,用于存储数据库中查询结果的内存不会被释放。我希望会有某种方法告诉数据库,您不再需要查询结果。顺便问一下,你的例子中pd是什么?每个查询结果中的行数是多少?@ivan_onys-啊,有趣的是,我不认为数据库在发送数据后会保存循环信息。我会调查的。。。pd是我在python中导入pandas的别名,python在创建连接引擎字符串后执行查询。