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)

  • 相关阅读:
    hibernate各种状态
    Persistence createEntityManagerFactory方法使用
    JS数组学习笔记
    ES6笔记之参数默认值(译)
    JS是按值传递还是按引用传递?
    linux awk命令详解
    Linux Shell笔记之sed
    类似微信红包随机分配js方法
    ionic tabs隐藏完美解决
    mustache 获取json数据内数组对象指定元素的方法
  • 原文地址:https://www.cnblogs.com/shixm/p/6881231.html
Copyright © 2011-2022 走看看