检索大量数据的最佳 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中文网其他相关文章!