• 数据库类型空间效率探索(四)-tinyint与enum与set


    mysql> select count(*) from userinfo;
    +----------+
    | count(*) |
    +----------+
    | 115597 |
    +----------+
    1 row in set (0.00 sec)

    mysql> select concat(truncate(sum(data_length)/1024/1024,3),'MB') as data_size,

    -> concat(truncate(sum(max_data_length)/1024/1024,3),'MB') as max_data_leng
    th,
    -> concat(truncate(sum(data_free)/1024/1024,3),'MB') as data_free,
    -> concat(truncate(sum(index_length)/1024/1024,3),'MB') as index_length
    -> from information_schema.tables where table_name='userinfo';
    +-----------+-----------------+-----------+--------------+
    | data_size | max_data_length | data_free | index_length |
    +-----------+-----------------+-----------+--------------+
    | 21.477MB | 268435455.999MB | 0.000MB | 1.319MB |
    +-----------+-----------------+-----------+--------------+

    以下测试tinyint

    mysql> ALTER TABLE `userinfo`
    -> ADD COLUMN `type` tinyint NOT NULL DEFAULT 0 COMMENT '反应类型' AFTER `i
    ntegral`;
    Query OK, 115597 rows affected (0.54 sec)
    Records: 115597 Duplicates: 0 Warnings: 0

    mysql> select concat(truncate(sum(data_length)/1024/1024,3),'MB') as data_size,

    -> concat(truncate(sum(max_data_length)/1024/1024,3),'MB') as max_data_leng
    th,
    -> concat(truncate(sum(data_free)/1024/1024,3),'MB') as data_free,
    -> concat(truncate(sum(index_length)/1024/1024,3),'MB') as index_length
    -> from information_schema.tables where table_name='userinfo';
    +-----------+-----------------+-----------+--------------+
    | data_size | max_data_length | data_free | index_length |
    +-----------+-----------------+-----------+--------------+
    | 21.477MB | 268435455.999MB | 0.000MB | 1.319MB |
    +-----------+-----------------+-----------+--------------+

    mysql> insert into userinfo(app,imei,type) values('','0',43);
    Query OK, 1 row affected (0.00 sec)

    mysql> select concat(round(sum(data_length/1024/1024),3),'MB') as data_size,
    -> concat(round(sum(max_data_length/1024/1024),3),'MB') as max_data_length,
    -> concat(round(sum(data_free/1024/1024),3),'MB') as data_free,
    -> concat(round(sum(index_length/1024/1024),3),'MB') as index_length
    -> from information_schema.tables where table_name='userinfo'
    -> ;
    +-----------+-----------------+-----------+--------------+
    | data_size | max_data_length | data_free | index_length |
    +-----------+-----------------+-----------+--------------+
    | 21.478MB | 268435456.000MB | 0.000MB | 1.319MB |
    +-----------+-----------------+-----------+--------------+
    1 row in set (0.00 sec)

    mysql> update userinfo set type=30;
    Query OK, 115598 rows affected (2.70 sec)
    Rows matched: 115598 Changed: 115598 Warnings: 0

    mysql> select concat(round(sum(data_length/1024/1024),3),'MB') as data_size,
    -> concat(round(sum(max_data_length/1024/1024),3),'MB') as max_data_length,
    -> concat(round(sum(data_free/1024/1024),3),'MB') as data_free,
    -> concat(round(sum(index_length/1024/1024),3),'MB') as index_length
    -> from information_schema.tables where table_name='userinfo';
    +-----------+-----------------+-----------+--------------+
    | data_size | max_data_length | data_free | index_length |
    +-----------+-----------------+-----------+--------------+
    | 22.038MB | 268435456.000MB | 0.000MB | 1.319MB |
    +-----------+-----------------+-----------+--------------+
    1 row in set (0.00 sec)

    以下测试enum

    mysql> select concat(round(sum(data_length/1024/1024),3),'MB') as data_size,
    -> concat(round(sum(max_data_length/1024/1024),3),'MB') as max_data_length,
    -> concat(round(sum(data_free/1024/1024),3),'MB') as data_free,
    -> concat(round(sum(index_length/1024/1024),3),'MB') as index_length
    -> from information_schema.tables where table_name='userinfo';
    +-----------+-----------------+-----------+--------------+
    | data_size | max_data_length | data_free | index_length |
    +-----------+-----------------+-----------+--------------+
    | 21.478MB | 268435456.000MB | 0.000MB | 1.319MB |
    +-----------+-----------------+-----------+--------------+

    mysql> ALTER TABLE `userinfo`
    -> ADD COLUMN `type` enum('未知','化合','分解','置换','复分解','取代','加成'
    ,'消去','加聚','酯化','水解','聚合','缩聚','吸热','放热','氧化','还原') AFTER `i
    ntegral`;
    Query OK, 115597 rows affected (0.63 sec)
    Records: 115597 Duplicates: 0 Warnings: 0

    mysql> select concat(round(sum(data_length/1024/1024),3),'MB') as data_size,
    -> concat(round(sum(max_data_length/1024/1024),3),'MB') as max_data_length,
    -> concat(round(sum(data_free/1024/1024),3),'MB') as data_free,
    -> concat(round(sum(index_length/1024/1024),3),'MB') as index_length
    -> from information_schema.tables where table_name='userinfo';
    +-----------+-----------------+-----------+--------------+
    | data_size | max_data_length | data_free | index_length |
    +-----------+-----------------+-----------+--------------+
    | 21.694MB | 268435456.000MB | 0.000MB | 1.319MB |
    +-----------+-----------------+-----------+--------------+
    1 row in set (0.00 sec)

    mysql> update userinfo set type='复分解';
    Query OK, 115597 rows affected (2.54 sec)
    Rows matched: 115597 Changed: 115597 Warnings: 0

    mysql> select concat(round(sum(data_length/1024/1024),3),'MB') as data_size,
    -> concat(round(sum(max_data_length/1024/1024),3),'MB') as max_data_length,
    -> concat(round(sum(data_free/1024/1024),3),'MB') as data_free,
    -> concat(round(sum(index_length/1024/1024),3),'MB') as index_length
    -> from information_schema.tables where table_name='userinfo';
    +-----------+-----------------+-----------+--------------+
    | data_size | max_data_length | data_free | index_length |
    +-----------+-----------------+-----------+--------------+
    | 21.694MB | 268435456.000MB | 0.000MB | 1.319MB |
    +-----------+-----------------+-----------+--------------+
    1 row in set (0.00 sec)

    以下测试set

    mysql> select concat(round(sum(data_length/1024/1024),3),'MB') as data_size,
    -> concat(round(sum(max_data_length/1024/1024),3),'MB') as max_data_length,
    -> concat(round(sum(data_free/1024/1024),3),'MB') as data_free,
    -> concat(round(sum(index_length/1024/1024),3),'MB') as index_length
    -> from information_schema.tables where table_name='userinfo'
    -> ;
    +-----------+-----------------+-----------+--------------+
    | data_size | max_data_length | data_free | index_length |
    +-----------+-----------------+-----------+--------------+
    | 21.478MB | 268435456.000MB | 0.000MB | 1.319MB |
    +-----------+-----------------+-----------+--------------+
    1 row in set (0.00 sec)

    mysql> ALTER TABLE `userinfo`
    -> ADD COLUMN `type` set('未知','化合','分解','置换','复分解','取代','加成',
    '消去','加聚','酯化','水解','聚合','缩聚','吸热','放热','氧化','还原') AFTER `in
    tegral`;
    Query OK, 115597 rows affected (0.61 sec)
    Records: 115597 Duplicates: 0 Warnings: 0

    mysql> select concat(round(sum(data_length/1024/1024),3),'MB') as data_size,
    -> concat(round(sum(max_data_length/1024/1024),3),'MB') as max_data_length,
    -> concat(round(sum(data_free/1024/1024),3),'MB') as data_free,
    -> concat(round(sum(index_length/1024/1024),3),'MB') as index_length
    -> from information_schema.tables where table_name='userinfo';
    +-----------+-----------------+-----------+--------------+
    | data_size | max_data_length | data_free | index_length |
    +-----------+-----------------+-----------+--------------+
    | 21.590MB | 268435456.000MB | 0.000MB | 1.319MB |
    +-----------+-----------------+-----------+--------------+
    1 row in set (0.01 sec)

    mysql> update userinfo set type='加成';
    Query OK, 115597 rows affected (3.63 sec)
    Rows matched: 115597 Changed: 115597 Warnings: 0

    mysql> select concat(round(sum(data_length/1024/1024),3),'MB') as data_size,
    -> concat(round(sum(max_data_length/1024/1024),3),'MB') as max_data_length,
    -> concat(round(sum(data_free/1024/1024),3),'MB') as data_free,
    -> concat(round(sum(index_length/1024/1024),3),'MB') as index_length
    -> from information_schema.tables where table_name='userinfo';
    +-----------+-----------------+-----------+--------------+
    | data_size | max_data_length | data_free | index_length |
    +-----------+-----------------+-----------+--------------+
    | 23.235MB | 268435456.000MB | 0.000MB | 1.319MB |
    +-----------+-----------------+-----------+--------------+
    1 row in set (0.00 sec)

    mysql> update userinfo set type='加成,取代,消去,放热';
    Query OK, 115597 rows affected (4.37 sec)
    Rows matched: 115597 Changed: 115597 Warnings: 0

    mysql> select concat(round(sum(data_length/1024/1024),3),'MB') as data_size,
    -> concat(round(sum(max_data_length/1024/1024),3),'MB') as max_data_length,
    -> concat(round(sum(data_free/1024/1024),3),'MB') as data_free,
    -> concat(round(sum(index_length/1024/1024),3),'MB') as index_length
    -> from information_schema.tables where table_name='userinfo';
    +-----------+-----------------+-----------+--------------+
    | data_size | max_data_length | data_free | index_length |
    +-----------+-----------------+-----------+--------------+
    | 23.235MB | 268435456.000MB | 0.000MB | 1.319MB |
    +-----------+-----------------+-----------+--------------+
    1 row in set (0.01 sec)

  • 相关阅读:
    mysql系列~mysqldump使用技巧
    mysql系列~logrotate
    最详细的经典双向电平转换电路的工作原理图文分析
    《USB应用分析精粹:从设备硬件、固件到主机程序设计》已经完稿
    Windows x86环境下使用QEMU安装arm架构银河麒麟V10操作系统
    不动产测绘包含哪些内容
    java问题收集
    java调用接口(rest-assured)
    java调用接口(okhttp )
    testng+allure
  • 原文地址:https://www.cnblogs.com/shixm/p/6881231.html
Copyright © 2020-2023  润新知