MySQL Workbench中的以下查询需要0.156秒才能完成:
SELECT
date, time, minute_price_id
FROM
minute_prices
WHERE
contract_id = 673 AND
TIMESTAMP(date, time) >= '2013-05-15 13:15:00' AND
TIMESTAMP(date, time) <= '2015-02-23 13:15:00'
LIMIT 1000000;
虽然使用mysql.connector在Python中使用相同的查询需要3.3秒:
import mysql.connector
con = mysql.connector.connect(...)
cur = con.cursor()
sql = \
"""
SELECT
date, time, minute_price_id
FROM
minute_prices
WHERE
contract_id = 673 AND
TIMESTAMP(date, time) >= '2013-05-15 13:15:00' AND
TIMESTAMP(date, time) <= '2015-02-23 13:15:00'
"""
cur.execute(sql)
cur.fetchall()
我希望MySQL Workbench比Python更快,因为数据需要传输,但速度要快20倍?任何线索?谢谢。
答案 0 :(得分:0)
我可以想到几个原因来解释这个:
为了对此进行排序,请尝试使用timeit python模块(或手动定时)并仅包含execute / fetchall命令。