数据库类型空间效率探索(四)-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)

时间: 2024-11-05 23:20:27

数据库类型空间效率探索(四)-tinyint与enum与set的相关文章

数据库类型空间效率探索(五)

接下来,测试一下 char(1) default null.char(1) not null default ''.char(200) default null.char(200) not null default '' varchar(1) default null.varchar(1) not null default ''.varchar(200) default null.varchar(200) not null default '' nvarchar(1) default null.

数据库类型定义效率探索

经过我的测试,发现 设置表userinfo的字段releas 分别为:varchar(25) default null.varchar(25) not null default ''.char(25) not null default '' 在数据量44460的时候,表userinfo占用的空间相同,根据releas字段模糊查询的速率相同. 这是为什么?是数据量太少,还是测试的方式不对,还是其他的原因? 下面是测试的过程,谁能给解释一下? 1.数据量 2.表结构 3.表占用空间4.将表转储为sq

引擎,创建完整表,数据库模式,数据库类型,约束条件

引擎(****) 前提:引擎是提供给表使用的,不是数据库 mysql> show engines;#展示所有的引擎 #重点: #innodb(默认):支持事务,行级锁,外键 #myisam:查询效率优于innodb,当不需要支持事物,行级锁,外键,可以通过设置myisam来优化数据库 mysql> use db1; mysql> create table t1(id int)engine=innodb; mysql> create table t2(id int)engine=my

Oracle数据库类型

字符类型char[(length)] 定长字符 最长2000字节varchar2[(length)] 可变长度的字符数据类型,最长4000字节NCHAR[(length)] 固定长度的字符数据类型,由国际字符语言(national language Support,NLS)字符集字符组成,最长2000字节LONG 可变长度的字符数据类型 最长2GBRAW 原始的二进制数据类型,最长2000字节long raw 原始的二进制数据类型,最长2GBrawid 数据库中一窜12字节地址,用于定位磁盘上某

NoSQL--非关系型数据库类型总结

随着互联网web2.0网站的兴起,非关系型的数据库现在成了一个极其热门的新领域,非关系数据库产品的发展非常迅速.而传统的关系数据库在应付web2.0网站,特别是超大规模和高并发的SNS类型的web2.0纯动态网站已经显得力不从心,暴露了很多难以克服的问题,例如: 一.High performance - 对数据库高并发读写的需求 web2.0网站要根据用户个性化信息来实时生成动态页面和提供动态信息,所以基本上无法使用动态页面静态化技术,因此数据库并发负载非常高,往往要达到每秒上万次读写请求.关系

2、第八周 - 网络编程进阶 - 数据库类型的理解

前言 1.关系型数据库与非关系型数据库 A.什么是数据库? 数据库是数据的仓库.数据库与普通的文件系统的主要区别:数据库能快速查找对应的数据. B.什么是关系型数据库? 关系型数据库是依据关系模型来创建的数据库.所谓关系模型就是"一对一.一对多.多对多"等关系模型,关系模型就是指二维表格模型,因而一个关系型数据库就是由二维表及其之间的联系组成的一个数据组织.关系模型包括数据结构(数据存储的问题,二维表).操作指令集合(SQL语句).完整性约束(表内数据约束.表与表之间的约束). 常见的

Spring MVC动态切换数据源(多数据库类型)

最近由于项目需求,需要将Sql Server 和 Mysql 两种数据库整合到一个项目,项目的用到的框架是SSM. 因此尝试了利用AOP切面来切每次执行的Servcie方法,根据Service所在的包名来实现数据源自动切换. 1.项目架构如下: 2.在com.jiefupay.database包中建立四个类: 其中 DataSourceContextHolder.java类源码如下: package com.jiefupay.datebase; public class DataSourceCo

Java与数据库类型对照表

 数据库类型  Java类型  INTEGER  int or java.lang.Integer  BIGINT  long or java.lang.Long  SMALLINT  short or java.lang.Short  FLOAT  float or java.lang.Float  DOUBLE  double or java.lang.Double  NUMERIC  java.math.BigDecimal  CHAR  java.lang.String  VARCHAR

Mysql中把varchar类型的字段转化为tinyint类型的字段

因为之前不知道tinyint类型的用法,所以将一些状态属性字段类型设置成了varchar类型,然后用"是"和"否"来判断状态 后来了解到了tinyint,就想试着用一下,但是要把varchar类型的字段转化为tinyint类型的字段,探索方法如下: 1.将表里面的所有"是"或者"否"改成 0,因为当前字段类型是varchar,所以这一步更改是没有问题的 2.运行下面的SQL语句 ALTER TABLE 表名 MODIFY CO