zoukankan      html  css  js  c++  java
  • 数据库类型空间效率探索(四)-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)

  • 相关阅读:
    网络管理和nmcli命令的使用——网络接口配置-bonding实验步骤
    raid组合优缺点介绍和创建LVM实验个人笔记
    磁盘分区就是这么简单,电脑小白都能看懂的磁盘分区教程!
    C盘优化之桌面移动法,拯救你爆满的C盘!
    电脑软件打开也有讲究,电脑软件打开方式总结!
    电脑使用建议大全,注意这些细节可以让你的电脑更好用!
    CentOS服务器apache绑定多个域名的方法
    CentOS 7使用yum安装PHP5.6
    PhpMyAdmin 配置文件现在需要一个短语密码的解决方法
    CentOs 7.*中配置安装phpMyAdmin的完整步骤记录
  • 原文地址:https://www.cnblogs.com/shixm/p/6881231.html
Copyright © 2011-2022 走看看