我看了帖子:How number of columns affects performance ?。好像是 列数会显着降低插入速度。所以我创建了两个表: 第一个包含100个tinyint列和100个smallint列,第二个包含 一个二进制(100)列和一个二进制(200)列。所以这两个表的行长相同。
更特别地说:
CREATE TABLE 'users'(
'c0' tinyint(4) not null default '0',
'd0' smallint(6) not null default '0',
.....
'c99' tinyint(4) not null default '0',
'd99' smallint(6) not null default '0'
) ENGINE = InnoDB default CHARSET = utf8
CREATE TABLE 'users2'(
'c0' binary(100) not null default '\0 *100',
'd0' binary(200) not null default '\0 * 200'
) ENGINE = InnoDB default CHARSET = utf8
然后我从mysql workbench运行了以下两个过程。
create procedure insert1()
begin
declare v_max int default 1000;
declare v_counter int default 0;
while v_counter < v_max do
insert into user (c0, d0, c1, d1....c99, d99) values (0,0,0.....0);
set v_counter = v_counter + 1;
end while;
end
create procedure insert2()
begin
declare v_max int default 1000;
declare v_counter int default 0;
while v_counter < v_max do
insert into users2 (c0, d0) values (0x0000...00, 0x000....00);
set v_counter = v_counter + 1;
end while;
end
结果是:
调用insert1():0.999秒
调用insert2():3.479秒
由于这两个表具有相同的行长度,并且第一个表具有更多列(200列),我预计第一个表的插入速度应该慢于第二个表。 有人可以帮助解释为什么会这样吗?提前谢谢!
答案 0 :(得分:0)
您必须将二进制(100)更改为二进制(4),将二进制(200)更改为二进制(6)。 我听说二进制(n)是n = 1个字节,而不是二进制数字。