我正在试图找出不同存储引擎的存储要求.我有这张桌子:
CREATE TABLE `mytest` (
`num1` int(10) unsigned NOT NULL,
KEY `key1` (`num1`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
Run Code Online (Sandbox Code Playgroud)
当我插入一些值然后运行时,show table status;我得到以下内容:
+----------------+--------+---------+------------+---------+----------------+-------------+------------------+--------------+-----------+----------------+---------------------+---------------------+------------+-------------------+----------+----------------+---------+ | Name | Engine | Version | Row_format | Rows | Avg_row_length | Data_length | Max_data_length | Index_length | Data_free | Auto_increment | Create_time | Update_time | Check_time | Collation | Checksum | Create_options | Comment | +----------------+--------+---------+------------+---------+----------------+-------------+------------------+--------------+-----------+----------------+---------------------+---------------------+------------+-------------------+----------+----------------+---------+ | mytest | InnoDB | 10 | Compact | 1932473 | 35 | 67715072 | 0 | 48840704 | …
我在看MySQL中一个简单的表,它有4列,大小如下,
unsigned bigint (8 bytes)
unsigned bigint (8 bytes)
unsigned smallint (2 bytes)
unsigned tinyint (1 byte)
Run Code Online (Sandbox Code Playgroud)
所以我希望19字节/行.
此表中有1,654,150行,因此数据大小应为31,428,850字节(或大约30兆字节).
但我可以通过phpMyAdmin看到数据占用136.3 MiB(不包括指数的大小bigint 1, smallint, tinyint为79 MiB).
存储引擎是InnoDB,主键是bigint 1, bigint 2(用户ID和唯一的项ID).
编辑:根据评论中的要求,这是一个结果SHOW CREATE TABLE storage
CREATE TABLE `storage` (
`fbid` bigint(20) unsigned NOT NULL,
`unique_id` bigint(20) unsigned NOT NULL,
`collection_id` smallint(5) unsigned NOT NULL,
`egg_id` tinyint(3) unsigned NOT NULL,
PRIMARY KEY (`fbid`,`unique_id`),
KEY `fbid` (`fbid`,`collection_id`,`egg_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8
Run Code Online (Sandbox Code Playgroud) 我有一个表,其中包含两个32位整数。这两个整数用于创建聚簇索引。用于创建表的SQL如下,
CREATE TABLE `a` (
`var1` int(10) unsigned NOT NULL,
`var2` int(10) unsigned NOT NULL,
PRIMARY KEY (`var2`,`var1`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin;
Run Code Online (Sandbox Code Playgroud)
SELECT COUNT(*) FROM a)SHOW TABLE STATUS)根据我的计算,每一行使用51.8个字节。我知道InnoDB在存储行时会产生开销。但是,使用MySQL网站,我计算出行大小应为26个字节(5个字节的标头,8个字节的整数,6个字节的事务ID和7个字节的滚动指针字段)。
我试图减小行的大小,因为该表可能会填充多达1600亿条记录。
我的计算中缺少什么?如何优化表以使用更少的空间?还是应该切换到其他数据库引擎?
更新资料
我对此表的查询;
INSERT INTO a(var1,var2) VALUES(INTEGER,INTEGER),(INTEGER,INTEGER),...,(INTEGER,INTEGER);
SELECT var1 FROM a WHERE var2=INTEGER;
DELETE FROM a WHERE var2=INTEGER;
Run Code Online (Sandbox Code Playgroud)