gpt4 book ai didi

mysql - 为什么 pymysql 会卡在在 MySQL Workbench 中正常工作的 select 语句上?

转载 作者:行者123 更新时间:2023-11-29 15:44:26 25 4
gpt4 key购买 nike

在 MySQL Workbench 中,我运行一个查询,该查询立即返回结果。当通过 pymysql 运行相同的查询时,程序似乎卡在从 SQL 获取结果上。

我尝试使用 MySQL 工作台中的 KILL 命令来终止 MySQL 中运行的其他进程。正如我之前所说,在 MySQL Workbench 中运行查询会立即返回结果。

查询本身如下所示:

SELECT at.instrument, at.timestamp, at.account, at.in_out_flag, SUM(at.value) AS total_value
FROM accounting.transactions AS at
WHERE at.instrument="AAPL"
AND at.account="Ned"
AND at.in_out_flag="OUT"
GROUP BY at.instrument, at.timestamp, at.account, at.in_out_flag
ORDER BY at.timestamp

用于执行查询的 python 代码与其他查询配合良好,如下所示。我的示例卡在了cursor.execute 行上。

    def get_list_of_dictionaries_with_select(select_statement):
conn = get_new_mysql_connection()
cursor = conn.cursor(pymysql.cursors.DictCursor)
cursor.execute(select_statement)
return_value = cursor.fetchall()
cursor.close()
conn.close()
return return_value

预期结果是该函数 (get_list_of_dictionaries_with_select) 返回表示查询结果的字典列表。实际发生的情况是程序挂起。

最佳答案

MySQL 工作台自动将 select 语句截断为 1000 个结果。这意味着如果 select 语句返回大量结果,那么在 MySQL 工作台之外的 SQL 中运行可能需要更长的时间。如果它被截断为 1000 个结果(在工作台中),那么一旦找到 1000 个结果,查询就会停止运行。

关于mysql - 为什么 pymysql 会卡在在 MySQL Workbench 中正常工作的 select 语句上?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57226032/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com