mysql分區表—list partition

來源:互聯網
上載者:User

author:skate
time:2012/11/28

mysql分區---list partition

 

mysql的list分區和range的分區十分類似,只是list分區的範圍是一列表,用PARTITION BY LIST(expr)類似定義,expr是基於一列或某列返回interger的運算式

 

list分區定義
mysql> show create table list_t;
 CREATE TABLE `list_t` (
  `c1` int(11) DEFAULT NULL,
  `c2` int(11) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1
/*!50100 PARTITION BY LIST (c1)
(PARTITION p0 VALUES IN (1,4,7) ENGINE = InnoDB,
 PARTITION p1 VALUES IN (2,5,8) ENGINE = InnoDB) */

mysql> insert into list_t values(1,3),(3,4),(4,5);
ERROR 1526 (HY000): Table has no partition for value 3

mysql> insert into list_t values(1,3),(5,4),(4,5);
Query OK, 3 rows affected (0.04 sec)
Records: 3  Duplicates: 0  Warnings: 0

清空表
mysql> truncate table list_t;
Query OK, 0 rows affected (0.12 sec)

忽略不匹配的行
mysql> insert ignore into list_t values(1,3),(3,4),(4,5);
Query OK, 2 rows affected (0.04 sec)
Records: 3  Duplicates: 1  Warnings: 0

mysql> select * from list_t;
+------+------+
| c1   | c2   |
+------+------+
|    1 |    3 |
|    4 |    5 |
+------+------+
2 rows in set (0.01 sec)

mysql>

添加分區
mysql> alter table list_t add partition (partition p2 values in (3,6,9));
Query OK, 0 rows affected (0.17 sec)
Records: 0  Duplicates: 0  Warnings: 0

mysql> show create table list_t;
 CREATE TABLE `list_t` (
  `c1` int(11) DEFAULT NULL,
  `c2` int(11) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1
/*!50100 PARTITION BY LIST (c1)
(PARTITION p0 VALUES IN (1,4,7) ENGINE = InnoDB,
 PARTITION p1 VALUES IN (2,5,8) ENGINE = InnoDB,
 PARTITION p2 VALUES IN (3,6,9) ENGINE = InnoDB) */

mysql>

mysql> insert  into list_t values(3,3),(6,4),(9,5);
Query OK, 3 rows affected (0.06 sec)
Records: 3  Duplicates: 0  Warnings: 0

mysql> select * from list_t;
+------+------+
| c1   | c2   |
+------+------+
|    1 |    3 |
|    4 |    5 |
|    3 |    3 |
|    6 |    4 |
|    9 |    5 |
+------+------+
5 rows in set (0.00 sec)

 

rebuild分區
mysql> alter table list_t rebuild partition p1;
Query OK, 0 rows affected (0.12 sec)
Records: 0  Duplicates: 0  Warnings: 0

檢查分區表
mysql> alter table list_t check partition p1;
+--------------+-------+----------+----------+
| Table        | Op    | Msg_type | Msg_text |
+--------------+-------+----------+----------+
| skate.list_t | check | status   | OK       |
+--------------+-------+----------+----------+
1 row in set (0.02 sec)

收集統計資訊
mysql> alter table list_t analyze partition p1;
+--------------+---------+----------+----------+
| Table        | Op      | Msg_type | Msg_text |
+--------------+---------+----------+----------+
| skate.list_t | analyze | status   | OK       |
+--------------+---------+----------+----------+
1 row in set (0.01 sec)

mysql>

清空表
mysql> alter table list_t truncate partition p1;
Query OK, 0 rows affected (0.04 sec)

刪除分區表
mysql> alter table list_t drop partition p1;
Query OK, 0 rows affected (0.03 sec)
Records: 0  Duplicates: 0  Warnings: 0

mysql>

重新命名分區
-------------------------------------------------
mysql> show create table list_t;
 CREATE TABLE `list_t` (
  `c1` int(11) DEFAULT NULL,
  `c2` int(11) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1
/*!50100 PARTITION BY LIST (c1)
(PARTITION p0 VALUES IN (1,4,7) ENGINE = InnoDB,
 PARTITION p2 VALUES IN (3,6,9) ENGINE = InnoDB,
 PARTITION p1 VALUES IN (2,5,8) ENGINE = InnoDB) */

mysql> alter table list_t  reorganize partition p0,p2 into ( partition p0 values in (1,4), partition p2 values in(7,3,6,9));
Query OK, 5 rows affected (0.26 sec)
Records: 5  Duplicates: 0  Warnings: 0

mysql> show create table list_t;
CREATE TABLE `list_t` (
  `c1` int(11) DEFAULT NULL,
  `c2` int(11) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1
/*!50100 PARTITION BY LIST (c1)
(PARTITION p0 VALUES IN (1,4) ENGINE = InnoDB,
 PARTITION p2 VALUES IN (7,3,6,9) ENGINE = InnoDB,
 PARTITION p1 VALUES IN (2,5,8) ENGINE = InnoDB) */

---------------------------------------------------

 

 

-----end----

 

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.