mysql 学习---->表优化、合成索引、浮点数与定点数
2015-10-15 10:48
495 查看
1.表优化
mysql> use test1;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> alter table t rename t_old;
mysql> create table t ( id varchar(100),content text);
mysql> insert into t values
-> (1,repeat('haha',100)),
-> (2,repeat('test',100)),
-> (3,repeat('java',100));
mysql> insert into t select * from t;
mysql> alter table t rename t_optimize;
mysql> select table_name,data_length from information_schema.tables where table_name = "t_optimize";
+------------+-------------+
| table_name | data_length |
+------------+-------------+
| t_optimize | 16384 |
+------------+-------------+
mysql> optimize table t_optimize;
+------------------+----------+----------+-------------------------------------------------------------------+
| Table | Op | Msg_type | Msg_text |
+------------------+----------+----------+-------------------------------------------------------------------+
| test1.t_optimize | optimize | note | Table does not support optimize, doing recreate + analyze instead |
| test1.t_optimize | optimize | status | OK |
+------------------+----------+----------+-------------------------------------------------------------------+
mysql> select table_name,data_length from information_schema.tables where table_name = "t_optimize";
+------------+-------------+
| table_name | data_length |
+------------+-------------+
| t_optimize | 16384 |
+------------+-------------+
2.合成索引
mysql> create table t (id varchar(100),context blob,hash_value varchar(40));
mysql> insert into t values(1,repeat('zhejiang',2),md5(context));
mysql> insert into t values(1,repeat('jiangsu',2),md5(context));
mysql> insert into t values(1,repeat('fujian 2008',2),md5(context));
mysql> select * from t;
+------+------------------------+----------------------------------+
| id | context | hash_value |
+------+------------------------+----------------------------------+
| 1 | zhejiangzhejiang | 8f36854efa45585f35e6ca54b7d58f31 |
| 1 | jiangsujiangsu | e2817db97256ac13805ee1ccfc1048e7 |
| 1 | fujian 2008fujian 2008 | 1efb8d993ee2cae7532407ff30b5778c |
+------+------------------------+----------------------------------+
mysql> select * from t ;
+------+------------------------+----------------------------------+
| id | context | hash_value |
+------+------------------------+----------------------------------+
| 1 | zhejiangzhejiang | 8f36854efa45585f35e6ca54b7d58f31 |
| 1 | jiangsujiangsu | e2817db97256ac13805ee1ccfc1048e7 |
| 1 | fujian 2008fujian 2008 | 1efb8d993ee2cae7532407ff30b5778c |
+------+------------------------+----------------------------------+
mysql> select * from t
-> where hash_value=md5(repeat('fujian 2008',2));
+------+------------------------+----------------------------------+
| id | context | hash_value |
+------+------------------------+----------------------------------+
| 1 | fujian 2008fujian 2008 | 1efb8d993ee2cae7532407ff30b5778c |
+------+------------------------+----------------------------------+
mysql> desc t;
+------------+--------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+------------+--------------+------+-----+---------+-------+
| id | varchar(100) | YES | | NULL | |
| context | blob | YES | | NULL | |
| hash_value | varchar(40) | YES | | NULL | |
+------------+--------------+------+-----+---------+-------+
mysql> create index inx_blob on t(context(100));
mysql> select * from t;
+------+------------------------+----------------------------------+
| id | context | hash_value |
+------+------------------------+----------------------------------+
| 1 | zhejiangzhejiang | 8f36854efa45585f35e6ca54b7d58f31 |
| 1 | jiangsujiangsu | e2817db97256ac13805ee1ccfc1048e7 |
| 1 | fujian 2008fujian 2008 | 1efb8d993ee2cae7532407ff30b5778c |
+------+------------------------+----------------------------------+
mysql> desc select * from t where context like 'fujian%' \G;
*************************** 1. row ***************************
id: 1
select_type: SIMPLE
table: t
type: range
possible_keys: inx_blob
key: inx_blob
key_len: 103
ref: NULL
rows: 1
Extra: Using where
ERROR:
No query specified
mysql> desc select * from t where context like '%fujian' \G;
*************************** 1. row ***************************
id: 1
select_type: SIMPLE
table: t
type: ALL
possible_keys: NULL
key: NULL
key_len: NULL
ref: NULL
rows: 3
Extra: Using where
1 row in set (0.00 sec)
ERROR:
No query specified
3.浮点数、定点数
mysql> create table t(f float(8,1));
mysql> desc t;
+-------+------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+------------+------+-----+---------+-------+
| f | float(8,1) | YES | | NULL | |
+-------+------------+------+-----+---------+-------+
mysql> insert into t values(1.23456);
mysql> select * from t;
+------+
| f |
+------+
| 1.2 |
+------+
mysql> insert into t values(1.25456);
mysql> select * from t;
+------+
| f |
+------+
| 1.2 |
| 1.3 |
+------+
mysql> create table test(c1 float(10,2),c2 decimal(10,2));
mysql> insert into test values(131072.32,131072.32);
mysql> select * from test;
+-----------+-----------+
| c1 | c2 |
+-----------+-----------+
| 131072.31 | 131072.32 |
+-----------+-----------+
mysql> use test1;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> alter table t rename t_old;
mysql> create table t ( id varchar(100),content text);
mysql> insert into t values
-> (1,repeat('haha',100)),
-> (2,repeat('test',100)),
-> (3,repeat('java',100));
mysql> insert into t select * from t;
mysql> alter table t rename t_optimize;
mysql> select table_name,data_length from information_schema.tables where table_name = "t_optimize";
+------------+-------------+
| table_name | data_length |
+------------+-------------+
| t_optimize | 16384 |
+------------+-------------+
mysql> optimize table t_optimize;
+------------------+----------+----------+-------------------------------------------------------------------+
| Table | Op | Msg_type | Msg_text |
+------------------+----------+----------+-------------------------------------------------------------------+
| test1.t_optimize | optimize | note | Table does not support optimize, doing recreate + analyze instead |
| test1.t_optimize | optimize | status | OK |
+------------------+----------+----------+-------------------------------------------------------------------+
mysql> select table_name,data_length from information_schema.tables where table_name = "t_optimize";
+------------+-------------+
| table_name | data_length |
+------------+-------------+
| t_optimize | 16384 |
+------------+-------------+
2.合成索引
mysql> create table t (id varchar(100),context blob,hash_value varchar(40));
mysql> insert into t values(1,repeat('zhejiang',2),md5(context));
mysql> insert into t values(1,repeat('jiangsu',2),md5(context));
mysql> insert into t values(1,repeat('fujian 2008',2),md5(context));
mysql> select * from t;
+------+------------------------+----------------------------------+
| id | context | hash_value |
+------+------------------------+----------------------------------+
| 1 | zhejiangzhejiang | 8f36854efa45585f35e6ca54b7d58f31 |
| 1 | jiangsujiangsu | e2817db97256ac13805ee1ccfc1048e7 |
| 1 | fujian 2008fujian 2008 | 1efb8d993ee2cae7532407ff30b5778c |
+------+------------------------+----------------------------------+
mysql> select * from t ;
+------+------------------------+----------------------------------+
| id | context | hash_value |
+------+------------------------+----------------------------------+
| 1 | zhejiangzhejiang | 8f36854efa45585f35e6ca54b7d58f31 |
| 1 | jiangsujiangsu | e2817db97256ac13805ee1ccfc1048e7 |
| 1 | fujian 2008fujian 2008 | 1efb8d993ee2cae7532407ff30b5778c |
+------+------------------------+----------------------------------+
mysql> select * from t
-> where hash_value=md5(repeat('fujian 2008',2));
+------+------------------------+----------------------------------+
| id | context | hash_value |
+------+------------------------+----------------------------------+
| 1 | fujian 2008fujian 2008 | 1efb8d993ee2cae7532407ff30b5778c |
+------+------------------------+----------------------------------+
mysql> desc t;
+------------+--------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+------------+--------------+------+-----+---------+-------+
| id | varchar(100) | YES | | NULL | |
| context | blob | YES | | NULL | |
| hash_value | varchar(40) | YES | | NULL | |
+------------+--------------+------+-----+---------+-------+
mysql> create index inx_blob on t(context(100));
mysql> select * from t;
+------+------------------------+----------------------------------+
| id | context | hash_value |
+------+------------------------+----------------------------------+
| 1 | zhejiangzhejiang | 8f36854efa45585f35e6ca54b7d58f31 |
| 1 | jiangsujiangsu | e2817db97256ac13805ee1ccfc1048e7 |
| 1 | fujian 2008fujian 2008 | 1efb8d993ee2cae7532407ff30b5778c |
+------+------------------------+----------------------------------+
mysql> desc select * from t where context like 'fujian%' \G;
*************************** 1. row ***************************
id: 1
select_type: SIMPLE
table: t
type: range
possible_keys: inx_blob
key: inx_blob
key_len: 103
ref: NULL
rows: 1
Extra: Using where
ERROR:
No query specified
mysql> desc select * from t where context like '%fujian' \G;
*************************** 1. row ***************************
id: 1
select_type: SIMPLE
table: t
type: ALL
possible_keys: NULL
key: NULL
key_len: NULL
ref: NULL
rows: 3
Extra: Using where
1 row in set (0.00 sec)
ERROR:
No query specified
3.浮点数、定点数
mysql> create table t(f float(8,1));
mysql> desc t;
+-------+------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+------------+------+-----+---------+-------+
| f | float(8,1) | YES | | NULL | |
+-------+------------+------+-----+---------+-------+
mysql> insert into t values(1.23456);
mysql> select * from t;
+------+
| f |
+------+
| 1.2 |
+------+
mysql> insert into t values(1.25456);
mysql> select * from t;
+------+
| f |
+------+
| 1.2 |
| 1.3 |
+------+
mysql> create table test(c1 float(10,2),c2 decimal(10,2));
mysql> insert into test values(131072.32,131072.32);
mysql> select * from test;
+-----------+-----------+
| c1 | c2 |
+-----------+-----------+
| 131072.31 | 131072.32 |
+-----------+-----------+
相关文章推荐
- mysql 学习----> 查看引擎、myisam引擎、自增长、主外键关联、memory引擎、merge引擎
- MySql乱码
- mysql 修改表结构脚本
- mysql 学习---->字符串、数值处理、日期、查询的逻辑处理、系统相关内容查询、IP地址相关、密码
- MySQL数据库
- mysql 学习---->数值计算、逻辑判断、范围选择、位运算
- mysql 学习---->字段
- MYSQL CLUSTER 7.4 + 5.6 创建磁盘表和内存表
- mysql ODBC 在64位下提示找不到odbc驱动问题
- MySQL information_schema 数据库
- mysql 学习----->查询,权限,字段控制
- Mysql_mysql force Index 强制索引
- codeigniter 操作mysql的PHP代码--更新
- MySQL 5.6内存占用过高解决方案
- PowerDesigner生成mysql字段comment注释
- MySql:备份与恢复数据库
- 多mysql环境(wamp和单独配置的环境同时存在)如何使用这个环境
- ubuntu install mysql
- win8 下免安装版mysql
- MySql调优