mysqlsqlperformance

How can I speed up my python script?


I have the following python script that reads from a file line by line and executes mysql update queries. It is extremely slow, each query seems to take over 1 second. Any idea why it is so slow?

   with open(fname) as f:
        for line in f:
            line = line.rstrip()
            email, name  = line.split(':')[0], line.split(':')[-1]
            try:
                cursor.execute("UPDATE user SET name=%s WHERE email=%s", (name, email))
            except mariadb.Error as error:
                print("Error: {}".format(error))

Solution

  • You should be able to fix the performance problem by using an index:

    create index idx_user_email on user(email);
    

    1 second for an update is a long time.