Download as pdf or txt
Download as pdf or txt
You are on page 1of 16

Range

mysql> create table user(u_id int(5),f_name varchar(20),l_name varchar(20),email


varchar(20))

-> partition by range(u_id)(partition p0 values less than (10),

-> partition p1 values less than (25),

-> partition p2 values less than (43),

-> partition p3 values less than (55));

Query OK, 0 rows affected, 1 warning (0.18 sec)

mysql> insert into user values

(12,'aayush','gala','aayushgala19@gmail.com'); Query OK, 1 row affected

(0.02 sec)

mysql> insert into user values (2,'anish','charak','acharak@gmail.com'); Query

OK, 1 row affected (0.01 sec)

mysql> insert into user values

(14,'ansh','dwivedi','ansh@gmail.com'); Query OK, 1 row affected

(0.01 sec)

mysql> insert into user values (8,'kunal','kapure','kunal@gmail.com');

Query OK, 1 row affected (0.01 sec)

mysql> insert into user values

(35,'vishal','dayma','vishal@gmail.com'); Query OK, 1 row affected

(0.01 sec)

mysql> insert into user values (24,'vinit','sharma','vinit@gmail.com');

Query OK, 1 row affected (0.01 sec)


mysql> insert into user values (28,'tejas','savla','tejas@gmail.com');

Query OK, 1 row affected (0.01 sec)

mysql> insert into user values

(40,'prathamesh','ramane','prathamesh@gmail.com'); Query OK, 1 row

affected (0.01 sec)

mysql> insert into user values

(46,'tanuja','mehera','tanuja@gmail.com'); Query OK, 1 row affected

(0.01 sec)

mysql> insert into user values (52,'nishant','deshpande','nishant@gmail.com');

Query OK, 1 row affected (0.01 sec)

mysql> insert into user values (36,'rugved','shrivastav','rugved@gmail.com');

Query OK, 1 row affected (0.01 sec)

mysql> insert into user values

(28,'akansha','sawant','akansha99999@gmail.com'); Query OK, 1 row

affected (0.01 sec)

mysql> select*from user;

+ + + + +

| u_id | f_name | l_name | email |

+ + + + +

| 2 | anish | charak | acharak@gmail.com |

| 8 | kunal | kapure | kunal@gmail.com |

| 12 | aayush | gala | aayushgala19@gmail.com |

| 14 | ansh | dwivedi | ansh@gmail.com |

| 24 | vinit | sharma | vinit@gmail.com |


| 35 | vishal | dayma | vishal@gmail.com|
| 28 | tejas | savla | tejas@gmail.com |

| 40 | prathamesh | ramane | prathamesh@gmail.com |

| 36 | rugved | shrivastav | rugved@gmail.com |

| 28 | akansha | sawant | akansha99999@gmail.com |

| 46 | tanuja | mehera | tanuja@gmail.com |

| 52 | nishant | deshpande | nishant@gmail.com |

+ + + + +

12 rows in set (0.00 sec)

mysql> select*from user partition (p0);

+ + + + +

| u_id | f_name | l_name | email |

+ + + + +

| 2 | anish | charak | acharak@gmail.com |

99| 8 | kunal | kapure | kunal@gmail.com |

+ + + + +

2 rows in set (0.00 sec)

mysql> select*from user partition (p1);

+ + + + +

| u_id | f_name | l_name | email |

+ + + + +

| 12 | aayush | gala | aayushgala19@gmail.com |

| 14 | ansh | dwivedi | ansh@gmail.com |

| 24 | vinit | sharma | vinit@gmail.com |

+ + + + +

3 rows in set (0.00 sec)


mysql> select*from user partition (p2);

+ + + + +

| u_id | f_name | l_name | email |

+ + + + +

| 35 | vishal | dayma | vishal@gmail.com |

| 28 | tejas | savla | tejas@gmail.com |

| 40 | prathamesh | ramane | prathamesh@gmail.com |

| 36 | rugved | shrivastav | rugved@gmail.com |

| 28 | akansha | sawant| akansha99999@gmail.com |

+ + + + +

5 rows in set (0.00 sec)

mysql> select*from user partition (p3);

+ + + + +

| u_id | f_name | l_name | email |

+ + + + +

| 46 | tanuja | mehera | tanuja@gmail.com |

| 52 | nishant | deshpande | nishant@gmail.com |

+ + + + +

2 rows in set (0.00 sec)

List
mysql> create table orders(employee_id int(5),createsdAt varchar(20),grandtatal int(10),tax
int(10))

-> partition by list(employee_id)(

-> partition p1 values in (5,2),

-> partition p2 values in (16,20,43),

-> partition p3 values in (55));


Query OK, 0 rows affected, 3 warnings (0.09 sec)

mysql> insert into orders values(2,'2-2-2020',300000,5000);

Query OK, 1 row affected (0.01 sec)

mysql> insert into orders values(5,'7-10-2021',600000,10000);

Query OK, 1 row affected (0.01 sec)

mysql> insert into orders values(43,'4-5-2021',650000,19000);

Query OK, 1 row affected (0.01 sec)

mysql> insert into orders values(20,'26-6-2021',45000,7000);

Query OK, 1 row affected (0.01 sec)

mysql> insert into orders values(16,'27-3-2022',50000,15000);

Query OK, 1 row affected (0.01 sec)

mysql> insert into orders values(55,'2-8-2022',20000,4000);

Query OK, 1 row affected (0.01 sec)

mysql> insert into orders values(16,'18-11-

2020',27000,14000); Query OK, 1 row affected (0.01 sec)

mysql> insert into orders values(55,'18-12-2021',270000,45000);

Query OK, 1 row affected (0.01 sec)


mysql> insert into orders values(20,'12-12-2018',260000,41000);

Query OK, 1 row affected (0.01 sec)

mysql> select*from orders;

+ + + + +

| employee_id | createdAt | grandtotal | tax |

+ + + + +

| 2 | 2-2-2020 | 300000 | 5000 |

| 5 | 7-10-2020 | 600000 | 10000 |

| 43 | 4-5-2021 | 650000 | 19000 |

| 20 | 26-6-2021 | 45000 | 7000 |

| 16 | 27-3-2022 | 50000 | 15000 |

| 16 | 18-11-2020 | 27000 | 14000 |

| 20 | 12-12-2018 | 260000 | 41000 |

| 55 | 2-8-2022 | 20000 | 4000 |

| 55 | 18-12-2021 | 270000 | 45000 |

+ + + + +

9 rows in set (0.01 sec)

mysql> select*from orders partition( p1);

+ + + + +

| employee_id | createdAt | grandtotal | tax |

+ + + + +

| 2 | 2-2-2020 | 300000 | 5000 |

| 5 | 7-10-2020 | 600000 | 10000 |

+ + + + +

2 rows in set (0.00 sec)


mysql> select*from orders partition( p2);

+ + + + +

| employee_id | createdAt | grandtotal | tax |

+ + + + +

| 43 | 4-5-2021 | 650000 | 19000 |

| 20 | 26-6-2021 | 45000 | 7000 |

| 16 | 27-3-2022 | 50000 | 15000 |

| 16 | 18-11-2020 | 27000 | 14000 |

| 20 | 12-12-2018 | 260000 | 41000 |

+ + + + +

5 rows in set (0.00 sec)

mysql> select*from orders partition( p3);

+ + + + +

| employee_id | createdAt | grandtotal | tax |

+ + + + +

| 55 | 2-8-2022 | 20000 | 4000 |

| 55 | 18-12-2021 | 270000 | 45000 |

+ + + + +

2 rows in set (0.00 sec)

Hash
mysql> create table month(ID int(5),createdAt varchar(20))
-> partition by hash(ID)
-> partitions 4;
Query OK, 0 rows affected, 1 warning (0.11 sec)

mysql> insert into month values(12,'12-5-


2021'); Query OK, 1 row affected (0.03 sec)

mysql> insert into month values(15,'1-6-


2021'); Query OK, 1 row affected (0.01 sec)
mysql> insert into month values(45,'13-5-
2020'); Query OK, 1 row affected (0.01 sec)

mysql> insert into month values(55,'18-10-


2020'); Query OK, 1 row affected (0.01 sec)

mysql> insert into month values(25,'8-1-


2019'); Query OK, 1 row affected (0.01 sec)

mysql> insert into month values(61,'28-12-


2019'); Query OK, 1 row affected (0.00 sec)

mysql> insert into month values(14,'17-9-


2017'); Query OK, 1 row affected (0.01 sec)

mysql> insert into month values(19,'13-9-


2016'); Query OK, 1 row affected (0.01 sec)

mysql> insert into month values(22,'23-4-


2022'); Query OK, 1 row affected (0.01 sec)

mysql> insert into month values(36,'24-5-


2022'); Query OK, 1 row affected (0.04 sec)

mysql> select*from month;


+ + +
| ID | createdAt |
+ + +
| 12 | 12-5-2021 |
| 36 | 24-5-2022 |
| 45 | 13-5-2020 |
| 25 | 8-1-2019 |
| 61 | 28-12-2019 |
| 14 | 17-9-2017 |
| 22 | 23-4-2022 |
| 15 | 1-6-2021 |
| 55 | 18-10-2020 |
| 19 | 13-9-2016 |
+ + +
10 rows in set (0.02 sec)

mysql> select*from month partition(p0);


+ + +
| ID | createdAt |
+ + +
| 12 | 12-5-2021 |
| 36 | 24-5-2022 |
+ + +
2 rows in set (0.00 sec)

mysql> select*from month partition(p1);


+ + +
| ID | createdAt |
+ + +
| 45 | 13-5-2020 |
| 25 | 8-1-2019 |
| 61 | 28-12-2019 |
+ + +
3 rows in set (0.00 sec)

mysql> select*from month partition(p2);


+ + +
| ID | createdAt |
+ + +
| 14 | 17-9-2017 |
| 22 | 23-4-2022 |
+ + +
2 rows in set (0.00 sec)

mysql> select*from month partition(p3);


+ + +
| ID | createdAt |
+ + +
| 15 | 1-6-2021 |
| 55 | 18-10-2020 |
| 19 | 13-9-2016 |
+ + +
3 rows in set (0.00 sec)

You might also like