Magic MySQL Partition _ MySQL

Source: Internet
Author: User
Magic MySQL partition bitsCN.com

Amazing MySQL partition

= First View result =

There are two tables with the same structure: no_part_tab and part_tab. one uses partitions and the other does not. The result is as follows.

Mysql> select * from no_part_tab where c1 = '201312 '; + ------- + hour + ------------ + | c1 | c2 | c3 | + ------- + hour + ------------ + | 80000 | testing partitions | + ------- + -------------------- + ------------ + 1 row in set (1.57 sec) mysql> select * from part_tab where c1 = '201312 '; + ------- + hour + ------------ + | c1 | c2 | c3 | + ------- + hour + ------------ + | 80000 | testing partitions | + ------- + -------------------- + ------------ + 1 row in set (0.02 sec) mysql> update part_tab set c2 = 'zhmsong 'where c1 = '000000'; Query OK, 1 row affected (80000 sec) Rows matched: 1 Changed: 1 Warnings: 0 mysql> update no_part_tab set c2 = 'zhmsong 'where c1 = '000000'; Query OK, 1 row affected (80000 sec) Rows matched: 1 Changed: 1 Warnings: 0 mysql> delete from no_part_tab where c1 = '000000'; Query OK, 1 row affected (80000 sec) mysql> delete from part_tab where c1 = '000000'; 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> = '000000' and c1 <= '000000'; + ---------- + | count (*) | + ---------- + | 70000 | + ---------- + 1 row in set (0.05 sec) mysql> select count (*) from no_part_tab where c1> = '000000' and c1 <= '000000'; + ---------- + | count (*) | + ---------- + | 70000 | + ---------- + 1 row in set (1.89 sec) mysql> select count (*) from no_part_tab where c2 like '% test % '; + ---------- + | count (*) | + ---------- + | 7999999 | + ---------- + 1 row in set (1.52 sec) mysql> select count (*) from part_tab where c2 like '% test %'; + ---------- + | count (*) | + ---------- + | 7999999 | + ---------- + 1 row in set (1.59 sec) mysql> select * from no_part_tab where c2 like '% zhmsong %' limit 10 offset 100; + --------- + ------------ + | c1 | c2 | c3 | + --------- + ------------ + | 1100100 | zhmsong | 1100101 | zhmsong | 1100102 | zhmsong | | 1100103 | zhmsong | 1100104 | zhmsong | 1100105 | zhmsong | 1100106 | zhmsong | 1100107 | zhmsong | 1100108 | zhmsong | zhmsong | 1100109 | zhmsong | + --------- + -------------- + 10 rows in set (0.22 sec) mysql> select * from part_tab where c2 like '% zhmsong %' limit 10 offset 100; + --------- + ------------ + | c1 | c2 | c3 | + --------- + ------------ + | 1100100 | zhmsong | 1100101 | zhmsong | 1100102 | zhmsong | | 1100103 | zhmsong | 1100104 | zhmsong | 1100105 | zhmsong | 1100106 | zhmsong | 1100107 | zhmsong | 1100108 | zhmsong | zhmsong | 1100109 | zhmsong | + --------- + -------------- + 10 rows in set (0.22 sec) =====01 drop table if exists part_tab; 02 create 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 p2values 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 P2 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 ); 4041 drop table if exists no_part_tab; 42 create table no_part_tab (43 c1 int (11) default NULL, 44 c2 varchar (30) default NULL, 45 c3 date default NULL46) engine = myisam; 4748 drop procedure if exists load_part_tab; 4950 delimiter // 51 52 create PROCEDURE load_part_tab () 53 begin54 declare v int default 0; 55 while v <800000056 do57 insert into part_tab values (v, 'testing partitions', adddate ('1970-01-01 ', (rand (v) * 1995) mod 36520); 58 set v = v + 1; 59 end while; 60 end61 // 62 delimiter;

BitsCN.com

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.