merge引擎的疑问
时间:2011-08-14
来源:互联网
最近看文档有提到merge引擎有这么个有点:查询时候能够访问更少的数据,只在目标子表进行查询。
这是不是意味着类似分区表的功能?
但是我实验好像不是这样的:
是我理解有误,还是实验有误,还是explain的rows不是实际查询的数据量?????
[ 本帖最后由 linjia828 于 2011-8-14 14:06 编辑 ]
这是不是意味着类似分区表的功能?
但是我实验好像不是这样的:
QUOTE:mysql> create table t1 (tp char(10),id int , name char(20)) engine=myisam;
Query OK, 0 rows affected (0.01 sec)
mysql> create table t2 (tp char(10),id int , name char(20)) engine=myisam;
Query OK, 0 rows affected (0.00 sec)
mysql> create table t3 (tp char(10),id int , name char(20)) engine=myisam;
Query OK, 0 rows affected (0.01 sec)
mysql> create table t_merge (tp char(10),id int , name char(20)) engine=merge union=(t2,t3);
Query OK, 0 rows affected (0.00 sec)
mysql> insert into t1 values ('a',1,'aaa'),('a',1,'bbb'),('a',2,'ccc'),('a',2,'ddd');
Query OK, 4 rows affected (0.00 sec)
Records: 4 Duplicates: 0 Warnings: 0
mysql> insert into t2 values ('a',1,'aaa'),('a',1,'bbb'),('a',2,'ccc'),('a',2,'ddd');
Query OK, 4 rows affected (0.01 sec)
Records: 4 Duplicates: 0 Warnings: 0
mysql> insert into t1 values ('b',1,'aaa'),('b',1,'bbb'),('b',2,'ccc'),('b',2,'ddd');
Query OK, 4 rows affected (0.00 sec)
Records: 4 Duplicates: 0 Warnings: 0
mysql> insert into t3 values ('b',1,'aaa'),('b',1,'bbb'),('b',2,'ccc'),('b',2,'ddd');
Query OK, 4 rows affected (0.00 sec)
Records: 4 Duplicates: 0 Warnings: 0
mysql> explain select * from t1 where tp='a' ;
+----+-------------+-------+------+---------------+------+---------+------+------+-------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+-------+------+---------------+------+---------+------+------+-------------+
| 1 | SIMPLE | t1 | ALL | NULL | NULL | NULL | NULL | 8 | Using where |
+----+-------------+-------+------+---------------+------+---------+------+------+-------------+
1 row in set (0.00 sec)
mysql> explain select * from t_merge where tp='a' ;
+----+-------------+---------+------+---------------+------+---------+------+------+-------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+---------+------+---------------+------+---------+------+------+-------------+
| 1 | SIMPLE | t_merge | ALL | NULL | NULL | NULL | NULL | 8 | Using where |
+----+-------------+---------+------+---------------+------+---------+------+------+-------------+
1 row in set (0.00 sec)
mysql> alter table t1 add index (tp);
Query OK, 8 rows affected (0.01 sec)
Records: 8 Duplicates: 0 Warnings: 0
mysql> alter table t_merge add index (tp);
Query OK, 0 rows affected (0.00 sec)
Records: 0 Duplicates: 0 Warnings: 0
mysql> alter table t2 add index (tp);
Query OK, 4 rows affected (0.01 sec)
Records: 4 Duplicates: 0 Warnings: 0
mysql> alter table t3 add index (tp);
Query OK, 4 rows affected (0.00 sec)
Records: 4 Duplicates: 0 Warnings: 0
mysql> explain select * from t1 where tp='a';
+----+-------------+-------+------+---------------+------+---------+-------+------+-------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+-------+------+---------------+------+---------+-------+------+-------------+
| 1 | SIMPLE | t1 | ref | tp | tp | 31 | const | 3 | Using where |
+----+-------------+-------+------+---------------+------+---------+-------+------+-------------+
1 row in set (0.00 sec)
mysql> explain select * from t_merge where tp='a';
+----+-------------+---------+------+---------------+------+---------+-------+------+-------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+---------+------+---------------+------+---------+-------+------+-------------+
| 1 | SIMPLE | t_merge | ref | tp | tp | 31 | const | 4 | Using where |
+----+-------------+---------+------+---------------+------+---------+-------+------+-------------+
1 row in set (0.00 sec)
Query OK, 0 rows affected (0.01 sec)
mysql> create table t2 (tp char(10),id int , name char(20)) engine=myisam;
Query OK, 0 rows affected (0.00 sec)
mysql> create table t3 (tp char(10),id int , name char(20)) engine=myisam;
Query OK, 0 rows affected (0.01 sec)
mysql> create table t_merge (tp char(10),id int , name char(20)) engine=merge union=(t2,t3);
Query OK, 0 rows affected (0.00 sec)
mysql> insert into t1 values ('a',1,'aaa'),('a',1,'bbb'),('a',2,'ccc'),('a',2,'ddd');
Query OK, 4 rows affected (0.00 sec)
Records: 4 Duplicates: 0 Warnings: 0
mysql> insert into t2 values ('a',1,'aaa'),('a',1,'bbb'),('a',2,'ccc'),('a',2,'ddd');
Query OK, 4 rows affected (0.01 sec)
Records: 4 Duplicates: 0 Warnings: 0
mysql> insert into t1 values ('b',1,'aaa'),('b',1,'bbb'),('b',2,'ccc'),('b',2,'ddd');
Query OK, 4 rows affected (0.00 sec)
Records: 4 Duplicates: 0 Warnings: 0
mysql> insert into t3 values ('b',1,'aaa'),('b',1,'bbb'),('b',2,'ccc'),('b',2,'ddd');
Query OK, 4 rows affected (0.00 sec)
Records: 4 Duplicates: 0 Warnings: 0
mysql> explain select * from t1 where tp='a' ;
+----+-------------+-------+------+---------------+------+---------+------+------+-------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+-------+------+---------------+------+---------+------+------+-------------+
| 1 | SIMPLE | t1 | ALL | NULL | NULL | NULL | NULL | 8 | Using where |
+----+-------------+-------+------+---------------+------+---------+------+------+-------------+
1 row in set (0.00 sec)
mysql> explain select * from t_merge where tp='a' ;
+----+-------------+---------+------+---------------+------+---------+------+------+-------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+---------+------+---------------+------+---------+------+------+-------------+
| 1 | SIMPLE | t_merge | ALL | NULL | NULL | NULL | NULL | 8 | Using where |
+----+-------------+---------+------+---------------+------+---------+------+------+-------------+
1 row in set (0.00 sec)
mysql> alter table t1 add index (tp);
Query OK, 8 rows affected (0.01 sec)
Records: 8 Duplicates: 0 Warnings: 0
mysql> alter table t_merge add index (tp);
Query OK, 0 rows affected (0.00 sec)
Records: 0 Duplicates: 0 Warnings: 0
mysql> alter table t2 add index (tp);
Query OK, 4 rows affected (0.01 sec)
Records: 4 Duplicates: 0 Warnings: 0
mysql> alter table t3 add index (tp);
Query OK, 4 rows affected (0.00 sec)
Records: 4 Duplicates: 0 Warnings: 0
mysql> explain select * from t1 where tp='a';
+----+-------------+-------+------+---------------+------+---------+-------+------+-------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+-------+------+---------------+------+---------+-------+------+-------------+
| 1 | SIMPLE | t1 | ref | tp | tp | 31 | const | 3 | Using where |
+----+-------------+-------+------+---------------+------+---------+-------+------+-------------+
1 row in set (0.00 sec)
mysql> explain select * from t_merge where tp='a';
+----+-------------+---------+------+---------------+------+---------+-------+------+-------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+---------+------+---------------+------+---------+-------+------+-------------+
| 1 | SIMPLE | t_merge | ref | tp | tp | 31 | const | 4 | Using where |
+----+-------------+---------+------+---------------+------+---------+-------+------+-------------+
1 row in set (0.00 sec)
是我理解有误,还是实验有误,还是explain的rows不是实际查询的数据量?????
[ 本帖最后由 linjia828 于 2011-8-14 14:06 编辑 ]
作者: linjia828 发布时间: 2011-08-14
另外为什么下面这个查询检索的数据量只有3呢?数据应该是4条才对。
QUOTE:mysql> select * from t1 where tp='a';
+------+------+------+
| tp | id | name |
+------+------+------+
| a | 1 | aaa |
| a | 1 | bbb |
| a | 2 | ccc |
| a | 2 | ddd |
+------+------+------+
4 rows in set (0.00 sec)
mysql> explain select * from t1 where tp='a';
+----+-------------+-------+------+---------------+------+---------+-------+------+-------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+-------+------+---------------+------+---------+-------+------+-------------+
| 1 | SIMPLE | t1 | ref | tp | tp | 31 | const | 3 | Using where |
+----+-------------+-------+------+---------------+------+---------+-------+------+-------------+
1 row in set (0.00 sec)
+------+------+------+
| tp | id | name |
+------+------+------+
| a | 1 | aaa |
| a | 1 | bbb |
| a | 2 | ccc |
| a | 2 | ddd |
+------+------+------+
4 rows in set (0.00 sec)
mysql> explain select * from t1 where tp='a';
+----+-------------+-------+------+---------------+------+---------+-------+------+-------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+-------+------+---------------+------+---------+-------+------+-------------+
| 1 | SIMPLE | t1 | ref | tp | tp | 31 | const | 3 | Using where |
+----+-------------+-------+------+---------------+------+---------+-------+------+-------------+
1 row in set (0.00 sec)
作者: linjia828 发布时间: 2011-08-14
相关阅读 更多
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28