gpt4 book ai didi

mysql - SQL插入查询太慢

转载 作者:行者123 更新时间:2023-11-30 21:32:13 25 4
gpt4 key购买 nike

每 10,000 行插入大约需要 124 秒,这怎么可能更快

这是我要插入的表格

CREATE TABLE `orders` 
(`oid` int(11) NOT NULL AUTO_INCREMENT,
`countryCode` varchar(10) NOT NULL,
`date` datetime NOT NULL,
`id` bigint(20) NOT NULL,
`productId` bigint(20) NOT NULL,
PRIMARY KEY (`oid`),
UNIQUE KEY `id` (`id`),
KEY `date` (`date`),
KEY `productId` (`productId`)
) ENGINE=InnoDB AUTO_INCREMENT=4833010 DEFAULT CHARSET=latin1

这是我使用的查询

ALTER TABLE `orders` DISABLE KEYS;
SET FOREIGN_KEY_CHECKS=0;
INSERT IGNORE INTO `orders` (`countryCode`, `date`, `id`,`productId`)
VALUES
('ru','2019-04-09 06:59',100453324298986,32829863707) ,
('fr','2019-04-09 05:59',100645420835625,32829863707) ,
('ru','2019-04-08 12:04',704482263524094,32829863707)
.......etc 10,000 rows here at once

最佳答案

尝试将插入语句写成

START TRANSACTION;  
INSERT INTO `insert_table` (`datetime`, `uid`, `content`, `type`) VALUES ('0', 'userid_0', 'content_0', 0);
INSERT INTO `insert_table` (`datetime`, `uid`, `content`, `type`) VALUES ('1', 'userid_1', 'content_1', 1);
...
COMMIT;

关于mysql - SQL插入查询太慢,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55611321/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com