2012-07-09 35 views
1

我在閱讀帖子:How number of columns affects performance ?。看來,列數會顯着減慢插入速度。所以我創建了兩個表: 第一個帶有100個tinyint列和100個smallint列,第二個帶有 一個二進制(100)列和一個二進制(200)列。所以這兩個表具有相同的行長度。int和二進制的插入速度

更特別:

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列),我預計第一個表的插入速度應該比第二個錶慢。 有人可以幫助解釋爲什麼會發生這種情況?先謝謝你!

回答

0

您必須將二進制(100)更改爲二進制(4),二進制(200)更改爲二進制(6)。 我聽說二進制(n)是n = 1個字節,而不是二進制數字。