InnoDB與Oracle單行儲存長度對比

來源:互聯網
上載者:User

眾所周知,MySQL InnoDB儲存引擎與Oracle非常相似,支援事務,row-locking,經過實際測試,innodb與oracle一個比較大的差異點為,相同資料,innodb單行儲存長度大概是oracle單行儲存長度的1.8倍。
測試的表,常見的各種類型都有,number,varchar2,date

--首先在Oracle中做測試 , 在Oracle資料庫中此表單行長度平均為458位元組

09:49:45 danchen@ test_oracle>select blocks from dba_extents where segment_name='test_dc' and rownum<2;

    BLOCKS
----------
      1280

1 row selected.

09:52:55 danchen@ test_oracle>select /*+ rowid(u)*/  count(*) from test_dc u where rowid>=CHARTOROWID('AAADQdAA6AAADcJAAA') and rowid<=CHARTOROWID('AAADQdAA6AAADwICcQ');

  COUNT(*)
----------

     22852

09:54:55 danchen@ test_oracle>select 1280*8*1024/22852 bytes from dual;

     BYTES
----------
458.855242

--在mysql作對比測試
root@test_mysql 09:47:47>select count(*) from test_dc_181;
+----------+
| count(*) |
+----------+
|   128928 |
+----------+
1 row in set (0.08 sec)

root@test_mysql 09:45:57>show table status like 'test_dc_181'\G;
*************************** 1. row ***************************
           Name: test_dc_181
         Engine: InnoDB
        Version: 10
     Row_format: Compact
           Rows: 85668   --統計資訊不準確
 Avg_row_length: 1122
    Data_length: 96141312
Max_data_length: 0
   Index_length: 0
      Data_free: 0
 Auto_increment: NULL
    Create_time: 2009-05-27 11:23:55
    Update_time: NULL
     Check_time: NULL
      Collation: gbk_chinese_ci
       Checksum: NULL
 Create_options:
        Comment: InnoDB free: 292984832 kB
1 row in set (0.00 sec)

ERROR:
No query specified


--重新分析一下,發現執行分析操作時間非常快,資料也比較準確,估計mysql的分析的演算法原理為基於抽樣的統計,比如說一個page裡有多少記錄,總的page數是多少,兩者相乘即可得到行數。
root@test_mysql 09:46:01>analyze table test_dc_181;
+---------------------+---------+----------+----------+
| Table               | Op      | Msg_type | Msg_text |
+---------------------+---------+----------+----------+
| test_mysql.test_dc_181 | analyze | status   | OK       |
+---------------------+---------+----------+----------+
1 row in set (0.00 sec)

root@test_mysql 09:46:46>show table status like 'test_dc_181'\G;
*************************** 1. row ***************************
           Name: test_dc_181
         Engine: InnoDB
        Version: 10
     Row_format: Compact
           Rows: 115074
 Avg_row_length: 835
    Data_length: 96141312
Max_data_length: 0
   Index_length: 0
      Data_free: 0
 Auto_increment: NULL
    Create_time: 2009-05-27 11:23:55
    Update_time: NULL
     Check_time: NULL
      Collation: gbk_chinese_ci
       Checksum: NULL
 Create_options:
        Comment: InnoDB free: 292984832 kB
1 row in set (0.00 sec)

ERROR:
No query specified

--在mysql innodb的表中平均單行長度為835位元組

root@test_mysql 09:46:50>select 96141312/115074;
+-----------------+
| 96141312/115074 |
+-----------------+
|        835.4738 |
+-----------------+
1 row in set (0.00 sec)


--同一行記錄,在oracle與mysql儲存空間對比為1.8:1,所以在做容量估計的時候要注意。
root@test_mysql 09:48:14>select 835.4738/458.855242 ;
+---------------------+
| 835.4738/458.855242 |
+---------------------+
|          1.82077859 |
+---------------------+
1 row in set (0.00 sec)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.