首頁 > 資料庫 > mysql教程 > 神奇的MySQL分区_MySQL

神奇的MySQL分区_MySQL

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
發布: 2016-06-01 13:31:53
原創
1102 人瀏覽過

bitsCN.com

神奇的MySQL分区

 

==先看结果==

 

有两个结构一样的表,no_part_tab 和 part_tab,一个使用了分区,一个不使用,结果如下。

 

mysql> select * from no_part_tab where c1 = &#39;80000&#39;;+-------+--------------------+------------+| c1    | c2                 | c3         |+-------+--------------------+------------+| 80000 | testing partitions | 1995-05-25 |+-------+--------------------+------------+1 row in set (1.57 sec)mysql> select * from part_tab where c1 = &#39;80000&#39;;+-------+--------------------+------------+| c1    | c2                 | c3         |+-------+--------------------+------------+| 80000 | testing partitions | 1995-05-25 |+-------+--------------------+------------+1 row in set (0.02 sec)mysql> update part_tab set c2=&#39;zhmsong&#39; where c1 = &#39;80000&#39;;Query OK, 1 row affected (0.21 sec)Rows matched: 1  Changed: 1  Warnings: 0mysql> update no_part_tab set c2=&#39;zhmsong&#39; where c1 = &#39;80000&#39;;Query OK, 1 row affected (15.55 sec)Rows matched: 1  Changed: 1  Warnings: 0mysql> delete from no_part_tab where c1 = &#39;80000&#39;;Query OK, 1 row affected (1.46 sec)mysql> delete from part_tab where c1 = &#39;80000&#39;;Query OK, 1 row affected (0.02 sec)mysql> select count(*) from no_part_tab;+----------+| count(*) |+----------+|  7999999 |+----------+1 row in set (0.00 sec)mysql> select count(*) from part_tab;+----------+| count(*) |+----------+|  7999999 |+----------+1 row in set (0.01 sec)mysql> select count(*) from part_tab where c1 >= &#39;80000&#39; and c1 <= &#39;150000&#39;;+----------+| count(*) |+----------+|    70000 |+----------+1 row in set (0.05 sec)mysql> select count(*) from no_part_tab where c1 >= &#39;80000&#39; and c1 <= &#39;150000&#39;;+----------+| count(*) |+----------+|    70000 |+----------+1 row in set (1.89 sec)mysql> select count(*) from no_part_tab where c2 like &#39;%test%&#39;;+----------+| count(*) |+----------+|  7999999 |+----------+1 row in set (1.52 sec)mysql> select count(*) from part_tab where c2 like &#39;%test%&#39;;+----------+| count(*) |+----------+|  7999999 |+----------+1 row in set (1.59 sec)mysql> select * from no_part_tab where c2 like &#39;%zhmsong%&#39; limit 10 offset 100;+---------+---------+------------+| c1      | c2      | c3         |+---------+---------+------------+| 1100100 | zhmsong | 2004-05-13 || 1100101 | zhmsong | 1999-05-21 || 1100102 | zhmsong | 2004-05-26 || 1100103 | zhmsong | 1999-06-03 || 1100104 | zhmsong | 2004-06-09 || 1100105 | zhmsong | 1999-06-16 || 1100106 | zhmsong | 2004-06-22 || 1100107 | zhmsong | 1999-06-30 || 1100108 | zhmsong | 2004-07-05 || 1100109 | zhmsong | 1999-07-13 |+---------+---------+------------+10 rows in set (0.22 sec)mysql> select * from part_tab where c2 like &#39;%zhmsong%&#39; limit 10 offset 100;+---------+---------+------------+| c1      | c2      | c3         |+---------+---------+------------+| 1100100 | zhmsong | 2004-05-13 || 1100101 | zhmsong | 1999-05-21 || 1100102 | zhmsong | 2004-05-26 || 1100103 | zhmsong | 1999-06-03 || 1100104 | zhmsong | 2004-06-09 || 1100105 | zhmsong | 1999-06-16 || 1100106 | zhmsong | 2004-06-22 || 1100107 | zhmsong | 1999-06-30 || 1100108 | zhmsong | 2004-07-05 || 1100109 | zhmsong | 1999-07-13 |+---------+---------+------------+10 rows in set (0.22 sec)== 实现==01DROP TABLE IF EXISTS part_tab;02CREATE TABLE part_tab (03        c1 int default NULL,04        c2 varchar(30) default NULL,05        c3 date default NULL06) engine=myisam07        PARTITION BY RANGE (c1) (08        PARTITION p1 VALUES LESS THAN (100000),09    PARTITION p2 VALUES LESS THAN (200000),10        PARTITION p3 VALUES LESS THAN (300000),11    PARTITION p4 VALUES LESS THAN (400000),12        PARTITION p5 VALUES LESS THAN (500000),13    PARTITION p6 VALUES LESS THAN (600000),14        PARTITION p7 VALUES LESS THAN (700000),15    PARTITION p8 VALUES LESS THAN (800000),16        PARTITION p9 VALUES LESS THAN (900000),17    PARTITION p10 VALUES LESS THAN (1000000),18        PARTITION p11 VALUES LESS THAN (1100000),19    PARTITION p12 VALUES LESS THAN (1200000),20        PARTITION p13 VALUES LESS THAN (1300000),21    PARTITION p14 VALUES LESS THAN (1400000),22        PARTITION p15 VALUES LESS THAN (1500000),23    PARTITION p16 VALUES LESS THAN (1600000),24        PARTITION p17 VALUES LESS THAN (1700000),25    PARTITION p18 VALUES LESS THAN (1800000),26        PARTITION p19 VALUES LESS THAN (1900000),27    PARTITION p20 VALUES LESS THAN (2000000),28        PARTITION p21 VALUES LESS THAN (2100000),29    PARTITION p22 VALUES LESS THAN (2200000),30        PARTITION p23 VALUES LESS THAN (2300000),31    PARTITION p24 VALUES LESS THAN (2400000),32        PARTITION p25 VALUES LESS THAN (2500000),33    PARTITION p26 VALUES LESS THAN (2600000),34        PARTITION p27 VALUES LESS THAN (2700000),35    PARTITION p28 VALUES LESS THAN (2800000),36        PARTITION p29 VALUES LESS THAN (2900000),37        PARTITION p30 VALUES LESS THAN (3000000),38    PARTITION p31 VALUES LESS THAN MAXVALUE39);4041DROP TABLE IF EXISTS no_part_tab;42create table no_part_tab (43        c1 int(11) default NULL,44    c2 varchar(30) default NULL,45    c3 date default NULL46) engine=myisam;4748DROP PROCEDURE IF EXISTS load_part_tab;4950delimiter //51  52create PROCEDURE load_part_tab()53    begin54    declare v int default 0;55                while v < 800000056                do57                        insert into part_tab values (v,&#39;testing partitions&#39;,adddate(&#39;1995-01-01&#39;,(rand(v)*36520) mod 3652));58                        set v = v + 1;59                end while;60    end61     //62delimiter ;
登入後複製

 

 

bitsCN.com
相關標籤:
來源:php.cn
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
最新問題
linux安裝mysql報錯
來自於 1970-01-01 08:00:00
0
0
0
mysql 升級後無法重新啟動mysql服務的問題
來自於 1970-01-01 08:00:00
0
0
0
MySQL停止進程
來自於 1970-01-01 08:00:00
0
0
0
phpstudy不能啟動mysql?
來自於 1970-01-01 08:00:00
0
0
0
環境中mysql
來自於 1970-01-01 08:00:00
0
0
0
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板