我在phpMyAdmin & MySQLdb(python)中執行了以下查詢。MySQLdb對於大型結果集極其緩慢
SELECT *, (SELECT CONCAT(`id`, '|', `name`, '|', `image_code`)
FROM `model_artist` WHERE `id` = `artist_id`) as artist_data,
FIND_IN_SET("metallica", `searchable_words`) as find_0
FROM `model_song` HAVING find_0
phpMyAdmin的表示,查詢了2ms的。 我的Python代碼表示,使用MySQLdb查詢花了848ms(甚至沒有提取結果)。
的Python代碼:
self.db = MySQLdb.connect(host="localhost", user="root", passwd="", db="ibeat")
self.cur = self.db.cursor()
millis = lambda: time.time() * 1000
start_time = millis()
self.cur.execute_cmd("""SELECT *, (SELECT CONCAT(`id`, '|', `name`, '|', `image_code`)
FROM `model_artist` WHERE `id` = `artist_id`) as artist_data,
FIND_IN_SET("metallica", `searchable_words`) as find_0
FROM `model_song` HAVING find_0""")
print millis() - start_time
,你得到了什麼時間? – dusan 2011-05-13 15:51:01
正在返回多少條記錄?你是否_sure_ phpMyAdmin執行查詢? – 2011-05-13 15:51:04