檢索大量數據的最佳 MySQL 設定
由於檢索大量數據,您的 MySQL 查詢正在遇到嚴重的效能問題。若要最佳化效能,請考慮以下策略:
資料庫引擎選擇:
查詢最佳化:
伺服器設定:
其他注意事項:
伺服器端處理的範例預存程序:
InnoDB 表:
CREATE TABLE `results_innodb` ( `rc` tinyint unsigned NOT NULL, `df` int unsigned NOT NULL default 0, `id` int unsigned NOT NULL, `val` double(10,4) NOT NULL default 0, `ts` timestamp NOT NULL default now(), PRIMARY KEY (`rc`, `df`, `id`) ) ENGINE=innodb;
已儲存程式:
CREATE PROCEDURE process_results_innodb( IN p_rc tinyint unsigned, IN p_df int unsigned ) BEGIN DECLARE done TINYINT DEFAULT 0; DECLARE result_cur CURSOR FOR SELECT `id` FROM `results_innodb` WHERE `rc` = p_rc AND `df` > p_df; DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = 1; OPEN result_cur; REPEAT FETCH result_cur INTO @id; -- Do processing here SET @count = @count + 1; UNTIL done END REPEAT; CLOSE result_cur; SELECT @count as `counter`; END
以上是如何優化MySQL以檢索大量資料?的詳細內容。更多資訊請關注PHP中文網其他相關文章!