分类: Mysql/postgreSQL
2008-02-28 12:13:01
mysql> create table t_1 (id int not null auto_increment primary key, c_str char(20) not null) engine federated connection = 'mysql://root:123456@192.168.0.233:3307/t_boy/t_tableB';
Query OK, 0 rows affected (0.04 sec)
mysql> create table t_2 (id int not null auto_increment primary key, c_str char(20) not null) engine federated connection = 'mysql://root:123456@192.168.0.233:3308/t_boy/t_tableC';
Query OK, 0 rows affected (0.03 sec)
mysql> insert into t_1(c_str) values (rand());
Query OK, 1 row affected (0.53 sec)
mysql> insert into t_2(c_str) values (rand());
Query OK, 1 row affected (0.03 sec)
mysql> select t_1.*,t_2.* from t_1 inner join t_2 using(id);
+----+----------------+----+------------------+
| id | c_str | id | c_str |
+----+----------------+----+------------------+
| 1 | 0.304819039353 | 1 | 0.24238659184648 |
+----+----------------+----+------------------+
1 row in set (0.00 sec)
插入百万级别的数据后
mysql> select t_1.*,t_2.* from t_1 inner join t_2 using(id) limit 20;
+----+----------------------+----+----------------------+
| id | c_str | id | c_str |
+----+----------------------+----+----------------------+
| 1 | 0.304819039353 | 1 | 0.24238659184648 |
| 2 | 1.304819039353 | 2 | 1.2423865918465 |
| 3 | 1.304819039352999920 | 3 | 1.242386591846480037 |
| 4 | 2.304819039353000143 | 4 | 2.242386591846500021 |
| 5 | 1.304819039352999920 | 5 | 1.242386591846480037 |
| 6 | 2.304819039353000143 | 6 | 2.242386591846500021 |
| 7 | 2.304819039353000143 | 7 | 2.242386591846480037 |
| 8 | 3.304819039353000143 | 8 | 3.242386591846500021 |
| 9 | 1.304819039352999920 | 9 | 1.242386591846480037 |
| 10 | 2.304819039353000143 | 10 | 2.242386591846500021 |
| 11 | 2.304819039353000143 | 11 | 2.242386591846480037 |
| 12 | 3.304819039353000143 | 12 | 3.242386591846500021 |
| 13 | 2.304819039353000143 | 13 | 2.242386591846480037 |
| 14 | 3.304819039353000143 | 14 | 3.242386591846500021 |
| 15 | 3.304819039353000143 | 15 | 3.242386591846480037 |
| 16 | 4.304819039353000143 | 16 | 4.242386591846500465 |
| 17 | 1.304819039352999920 | 17 | 1.242386591846480037 |
| 18 | 2.304819039353000143 | 18 | 2.242386591846500021 |
| 19 | 2.304819039353000143 | 19 | 2.242386591846480037 |
| 20 | 3.304819039353000143 | 20 | 3.242386591846500021 |
+----+----------------------+----+----------------------+
20 rows in set (0.73 sec)
mysql> select max(id),min(id) from t_1;
+---------+---------+
| max(id) | min(id) |
+---------+---------+
| 1048576 | 1 |
+---------+---------+
1 row in set (1.40 sec)
mysql> select max(id),min(id) from t_2;
+---------+---------+
| max(id) | min(id) |
+---------+---------+
| 1048576 | 1 |
+---------+---------+
1 row in set (1.40 sec)
mysql> update t_2 set id = id +1048576;
Query OK, 1048576 rows affected (2 min 10.38 sec)
Rows matched: 1048576 Changed: 1048576 Warnings: 0
mysql> select max(id),min(id) from t_2;
+---------+---------+
| max(id) | min(id) |
+---------+---------+
| 2097152 | 1048577 |
+---------+---------+
1 row in set (1.63 sec)
mysql> explain select id c_str from t_1 where id between 1 and 1048576;
+----+-------------+-------+-------+---------------+---------+---------+------+------+-------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+-------+-------+---------------+---------+---------+------+------+-------------+
| 1 | SIMPLE | t_1 | range | PRIMARY | PRIMARY | 4 | NULL | 2 | Using where |
+----+-------------+-------+-------+---------------+---------+---------+------+------+-------------+
1 row in set (0.00 sec)
mysql> create table t(id int not null auto_increment primary key, c_str char(20));
Query OK, 0 rows affected (0.00 sec)
插入两百万级别数据后。
mysql> select count(*) from t;
+----------+
| count(*) |
+----------+
| 2097152 |
+----------+
1 row in set (0.00 sec)
mysql> analyze table t;
+---------+---------+----------+----------+
| Table | Op | Msg_type | Msg_text |
+---------+---------+----------+----------+
| t_boy.t | analyze | status | OK |
+---------+---------+----------+----------+
1 row in set (0.37 sec)
mysql> explain select id c_str from t where id between 1 and 1048576;