【问题标题】:The insert speed of int and binaryint和binary的插入速度
【发布时间】:2014-10-03 22:06:13
【问题描述】:

我阅读了帖子: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 工作台运行以下两个程序。

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 列),我预计第一个表的插入速度应该比第二个慢。 有人可以帮助解释为什么会这样吗?提前谢谢!

【问题讨论】:

    标签: mysql


    【解决方案1】:

    您必须将二进制 (100) 更改为二进制 (4),将二进制 (200) 更改为二进制 (6)。 我听说 binary(n) 是 n = 1 字节,而不是二进制数字。

    【讨论】:

      猜你喜欢
      • 2016-06-25
      • 2010-12-01
      • 1970-01-01
      • 1970-01-01
      • 2017-05-20
      • 1970-01-01
      • 1970-01-01
      • 2023-03-27
      • 2016-08-14
      相关资源
      最近更新 更多