InnoDB奇怪的表现
我正在使用一个非常简单的 InnoDB 表(名为 Test)进行一些测试,其结构如下:
Id int(10) unsigned NOT NULL AUTO_INCREMENT
UserId int(10) NOT NULL
Body varchar(512) COLLATE utf8_unicode_ci NOT NULL
CreatedAt datetime NOT NULL
UserId 上的一个附加索引:
KEY Idx_Test_UserId (UserId) USING BTREE
当我尝试执行此查询时...
INSERT INTO Comments (UserId,Body,CreatedAt) VALUES (1,'This is a test',NOW());
...有时我会在几毫秒内完成操作但有时需要大约一秒钟。
我是唯一一个在这个特定表上进行测试的人,我真的不明白我有这样的执行时间差异。
最后一点,当我使用 MyISAM 表进行相同的测试时,我没有任何问题。
I'm doing some tests with a really simple InnoDB table (named Test) with the following structure:
Id int(10) unsigned NOT NULL AUTO_INCREMENT
UserId int(10) NOT NULL
Body varchar(512) COLLATE utf8_unicode_ci NOT NULL
CreatedAt datetime NOT NULL
one additional index on UserId:
KEY Idx_Test_UserId (UserId) USING BTREE
When I try to execute this query...
INSERT INTO Comments (UserId,Body,CreatedAt) VALUES (1,'This is a test',NOW());
...sometimes I get the operation completed in a few milliseconds but some other times it takes around a second.
I'm the only one person doing the tests on this specific table, I really don't understand I have such execution time differences.
Last note, when I'm doing the same tests with a MyISAM table I don't have any issues.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
InnoDB默认工作在AUTOCOMMIT模式,这意味着每次插入都需要两次单独的磁盘写入操作。如果您的计算机中只有一个磁盘驱动器,有时您可能需要稍等一下。另外,AFAIR InnoDB过去在Windows中写入磁盘时存在一些性能问题(不确定是否仍然如此),但我认为它涉及高于1的并发数。
InnoDB works by default in AUTOCOMMIT mode, which means that every insert requires two seperate write to disk operations. If you have only one disk drive in your machine, sometimes you might need to wait a bit fr that. Also, AFAIR InnoDB used to have (not sure if it's still the case) a bit of performance problemws with writing to disk in Windows, but I think it involved concurrency higher than 1.