The following query in MySQL Workbench takes 0.156 second to complete:
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;
While the same query in Python using mysql.connector takes over 3.3 seconds:
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()
I expected MySQL Workbench to be faster than Python because data needs to be transferred, but 20x faster? Any clue? Thank you.
There are a few reasons I can think of to explain this:
In order to sort this out, try using the timeit python module (or do manual timing) and only include the execute/fetchall commands.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With