我想提高以下 Mysql 存储过程的性能。
我正在尝试包含 100 个项目的 XML。它需要将近 90 秒。它太多了。
请检查我的以下SP。
DELIMITER $$
DROP PROCEDURE IF EXISTS `kshitij`.`Insert_date` $$
CREATE DEFINER=`root`@`localhost` PROCEDURE `Insert_date`()
BEGIN
DECLARE itemstart INTEGER default 1;
DECLARE valuestart INTEGER default 1;
DECLARE itemcount INTEGER;
DECLARE valuecount INTEGER;
SET @xml = '<items>
<size>2</size>
<item>
<value columntype="0" columnid="23">Single Line Text_0</value>
<value columntype="1" columnid="24">Multi Line Text_0</value>
<value columntype="2" columnid="25">Number_0</value>
<value columntype="3" columnid="26">Link_0</value>
<value columntype="4" columnid="27">Image_0</value>
<value columntype="5" columnid="28">Date time_0</value>
</item>
TRYING WITH 100 ITEMS.
</items>';
SET itemcount = (SELECT ExtractValue(@xml, 'count(//item)'));
WHILE itemstart < itemcount
DO
SET valuecount = (SELECT ExtractValue(@xml, 'count(/items/item[itemstart]/value)'));
SET valuestart = 1;
WHILE valuestart < valuecount
DO
IF((SELECT ExtractValue(@xml, '/items/item[$itemstart]/value[$valuestart]/@columntype')) = '0') THEN
INSERT INTO singleline_text(value) VALUES(ExtractValue(@xml, '/items/item[$itemstart]/value[$valuestart]'));
INSERT INTO sheet_items(c_id, value_id) VALUES(ExtractValue(@xml, '/items/item[$itemstart]/value[$valuestart]/@columnid'), (SELECT MAX(id) FROM singleline_text));
END IF;
IF((SELECT ExtractValue(@xml, '/items/item[$itemstart]/value[$valuestart]/@columntype')) = '1') THEN
INSERT INTO multiline_text(value) VALUES(ExtractValue(@xml, '/items/item[$itemstart]/value[$valuestart]'));
INSERT INTO sheet_items(c_id, value_id) VALUES(ExtractValue(@xml, '/items/item[$itemstart]/value[$valuestart]/@columnid'), (SELECT MAX(id) FROM multiline_text));
END IF;
IF((SELECT ExtractValue(@xml, '/items/item[$itemstart]/value[$valuestart]/@columntype')) = '2') THEN
INSERT INTO number(value) VALUES(ExtractValue(@xml, '/items/item[$itemstart]/value[$valuestart]'));
INSERT INTO sheet_items(c_id, value_id) VALUES(ExtractValue(@xml, '/items/item[$itemstart]/value[$valuestart]/@columnid'), (SELECT MAX(id) FROM number));
END IF;
IF((SELECT ExtractValue(@xml, '/items/item[$itemstart]/value[$valuestart]/@columntype')) = '3') THEN
INSERT INTO link(value) VALUES(ExtractValue(@xml, '/items/item[$itemstart]/value[$valuestart]'));
INSERT INTO sheet_items(c_id, value_id) VALUES(ExtractValue(@xml, '/items/item[$itemstart]/value[$valuestart]/@columnid'), (SELECT MAX(id) FROM link));
END IF;
IF((SELECT ExtractValue(@xml, '/items/item[$itemstart]/value[$valuestart]/@columntype')) = '4') THEN
INSERT INTO image(value) VALUES(ExtractValue(@xml, '/items/item[$itemstart]/value[$valuestart]'));
INSERT INTO sheet_items(c_id, value_id) VALUES(ExtractValue(@xml, '/items/item[$itemstart]/value[$valuestart]/@columnid'), (SELECT MAX(id) FROM image));
END IF;
IF((SELECT ExtractValue(@xml, '/items/item[$itemstart]/value[$valuestart]/@columntype')) = '5') THEN
INSERT INTO date_time(value) VALUES(ExtractValue(@xml, '/items/item[$itemstart]/value[$valuestart]'));
INSERT INTO sheet_items(c_id, value_id) VALUES(ExtractValue(@xml, '/items/item[$itemstart]/value[$valuestart]/@columnid'), (SELECT MAX(id) FROM date_time));
END IF;
SET valuestart = valuestart + 1;
END WHILE;
SET itemstart = itemstart + 1;
end while;
END $$
DELIMITER ;
谢谢。