MySQL Key分割槽表建立方法介紹
按照KEY進行分割槽類似於按照HASH分割槽,除了HASH分割槽使用的使用者定義的表示式,而KEY分割槽的 雜湊函式是由MySQL 伺服器提供。MySQL 簇(Cluster)使用函式MD5()來實現KEY分割槽;
對於使用其他儲存引擎的表,伺服器使用其自己內部的 雜湊函式,這些函式是基於與PASSWORD()一樣的運演算法則。
Key分割槽與Hash分割槽很相似,只是Hash函式不同,定義時把Hash關鍵字替換成Key即可,同樣Key分割槽也有對應與線性Hash的線性Key分割槽方法。
語法為PARTITION BY LINEAR KEY(列名)
建立key分割槽表舉例如下:
mysql> CREATE TABLE `dsf_data` (
-> `id` bigint(20) NOT NULL AUTO_INCREMENT,
-> `SH` varchar(32) DEFAULT NULL COMMENT '稅號',
-> `KPJH` varchar(32) DEFAULT NULL COMMENT '開票機號',
-> `ZFJH` varchar(32) DEFAULT NULL COMMENT '主分機號',
-> `MONTH` varchar(10) DEFAULT NULL,
-> `STATUS` varchar(255) DEFAULT NULL COMMENT '解析狀態標識',
-> `CREATE_TIME` datetime DEFAULT NULL COMMENT '插入時間',
-> `UPDATE_TIME` datetime DEFAULT NULL COMMENT '更新時間',
-> `FP_DATA` mediumtext COMMENT '發票資料',
-> PRIMARY KEY (`id`,`SH`),
-> KEY `index_sh` (`SH`)
-> ) ENGINE=InnoDB AUTO_INCREMENT=1173560 DEFAULT CHARSET=utf8 PARTITION BY LINEAR KEY (SH) PARTITIONS 8;
Query OK, 0 rows affected (0.11 sec)
備註:如果分割槽欄位中有主鍵或者唯一索引的列,那麼所有主鍵列和唯一索引列都必須包含進來,因此上一步必須有兩個主鍵PRIMARY KEY (`id`,`SH`)存在。
插入資料:
mysql> insert into dsf_data select * from test.fp_data;
Query OK, 202632 rows affected, 1 warning (18.96 sec)
Records: 202632 Duplicates: 0 Warnings: 1
mysql> explain partitions select sh from dsf_data; --全表掃描共訪問了8個分割槽(p0--p7)
+----+-------------+----------+-------------------------+-------+---------------+----------+---------+------+------+-------------+
| id | select_type | table | partitions | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+----------+-------------------------+-------+---------------+----------+---------+------+------+-------------+
| 1 | SIMPLE | dsf_data | p0,p1,p2,p3,p4,p5,p6,p7 | index | NULL | index_sh | 98 | NULL | 8 | Using index |
+----+-------------+----------+-------------------------+-------+---------------+----------+---------+------+------+-------------+
1 row in set (0.00 sec)
mysql> explain partitions select sh from dsf_data where sh='130202568907641'; --值被隨機分到了p0分割槽
+----+-------------+----------+------------+------+---------------+----------+---------+-------+------+--------------------------+
| id | select_type | table | partitions | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+----------+------------+------+---------------+----------+---------+-------+------+--------------------------+
| 1 | SIMPLE | dsf_data | p0 | ref | index_sh | index_sh | 98 | const | 1 | Using where; Using index |
+----+-------------+----------+------------+------+---------------+----------+---------+-------+------+--------------------------+
1 row in set (0.00 sec)
mysql> explain partitions select sh from dsf_data where sh='440300683797687'; --值被隨機分到了p4分割槽
+----+-------------+----------+------------+------+---------------+----------+---------+-------+------+--------------------------+
| id | select_type | table | partitions | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+----------+------------+------+---------------+----------+---------+-------+------+--------------------------+
| 1 | SIMPLE | dsf_data | p4 | ref | index_sh | index_sh | 98 | const | 1 | Using where; Using index |
+----+-------------+----------+------------+------+---------------+----------+---------+-------+------+--------------------------+
1 row in set (0.00 sec)
mysql> explain partitions select sh from dsf_data where sh='91500107784224861G'; --sh的值被隨機分到了p6分割槽
+----+-------------+----------+------------+------+---------------+----------+---------+-------+------+--------------------------+
| id | select_type | table | partitions | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+----------+------------+------+---------------+----------+---------+-------+------+--------------------------+
| 1 | SIMPLE | dsf_data | p6 | ref | index_sh | index_sh | 98 | const | 452 | Using where; Using index |
+----+-------------+----------+------------+------+---------------+----------+---------+-------+------+--------------------------+
1 row in set (0.00 sec)
值被隨機分到各個分割槽,說明分割槽表建立成功。
對於使用其他儲存引擎的表,伺服器使用其自己內部的 雜湊函式,這些函式是基於與PASSWORD()一樣的運演算法則。
Key分割槽與Hash分割槽很相似,只是Hash函式不同,定義時把Hash關鍵字替換成Key即可,同樣Key分割槽也有對應與線性Hash的線性Key分割槽方法。
語法為PARTITION BY LINEAR KEY(列名)
建立key分割槽表舉例如下:
mysql> CREATE TABLE `dsf_data` (
-> `id` bigint(20) NOT NULL AUTO_INCREMENT,
-> `SH` varchar(32) DEFAULT NULL COMMENT '稅號',
-> `KPJH` varchar(32) DEFAULT NULL COMMENT '開票機號',
-> `ZFJH` varchar(32) DEFAULT NULL COMMENT '主分機號',
-> `MONTH` varchar(10) DEFAULT NULL,
-> `STATUS` varchar(255) DEFAULT NULL COMMENT '解析狀態標識',
-> `CREATE_TIME` datetime DEFAULT NULL COMMENT '插入時間',
-> `UPDATE_TIME` datetime DEFAULT NULL COMMENT '更新時間',
-> `FP_DATA` mediumtext COMMENT '發票資料',
-> PRIMARY KEY (`id`,`SH`),
-> KEY `index_sh` (`SH`)
-> ) ENGINE=InnoDB AUTO_INCREMENT=1173560 DEFAULT CHARSET=utf8 PARTITION BY LINEAR KEY (SH) PARTITIONS 8;
Query OK, 0 rows affected (0.11 sec)
備註:如果分割槽欄位中有主鍵或者唯一索引的列,那麼所有主鍵列和唯一索引列都必須包含進來,因此上一步必須有兩個主鍵PRIMARY KEY (`id`,`SH`)存在。
插入資料:
mysql> insert into dsf_data select * from test.fp_data;
Query OK, 202632 rows affected, 1 warning (18.96 sec)
Records: 202632 Duplicates: 0 Warnings: 1
mysql> explain partitions select sh from dsf_data; --全表掃描共訪問了8個分割槽(p0--p7)
+----+-------------+----------+-------------------------+-------+---------------+----------+---------+------+------+-------------+
| id | select_type | table | partitions | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+----------+-------------------------+-------+---------------+----------+---------+------+------+-------------+
| 1 | SIMPLE | dsf_data | p0,p1,p2,p3,p4,p5,p6,p7 | index | NULL | index_sh | 98 | NULL | 8 | Using index |
+----+-------------+----------+-------------------------+-------+---------------+----------+---------+------+------+-------------+
1 row in set (0.00 sec)
mysql> explain partitions select sh from dsf_data where sh='130202568907641'; --值被隨機分到了p0分割槽
+----+-------------+----------+------------+------+---------------+----------+---------+-------+------+--------------------------+
| id | select_type | table | partitions | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+----------+------------+------+---------------+----------+---------+-------+------+--------------------------+
| 1 | SIMPLE | dsf_data | p0 | ref | index_sh | index_sh | 98 | const | 1 | Using where; Using index |
+----+-------------+----------+------------+------+---------------+----------+---------+-------+------+--------------------------+
1 row in set (0.00 sec)
mysql> explain partitions select sh from dsf_data where sh='440300683797687'; --值被隨機分到了p4分割槽
+----+-------------+----------+------------+------+---------------+----------+---------+-------+------+--------------------------+
| id | select_type | table | partitions | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+----------+------------+------+---------------+----------+---------+-------+------+--------------------------+
| 1 | SIMPLE | dsf_data | p4 | ref | index_sh | index_sh | 98 | const | 1 | Using where; Using index |
+----+-------------+----------+------------+------+---------------+----------+---------+-------+------+--------------------------+
1 row in set (0.00 sec)
mysql> explain partitions select sh from dsf_data where sh='91500107784224861G'; --sh的值被隨機分到了p6分割槽
+----+-------------+----------+------------+------+---------------+----------+---------+-------+------+--------------------------+
| id | select_type | table | partitions | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+----------+------------+------+---------------+----------+---------+-------+------+--------------------------+
| 1 | SIMPLE | dsf_data | p6 | ref | index_sh | index_sh | 98 | const | 452 | Using where; Using index |
+----+-------------+----------+------------+------+---------------+----------+---------+-------+------+--------------------------+
1 row in set (0.00 sec)
值被隨機分到各個分割槽,說明分割槽表建立成功。
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/15498/viewspace-2137232/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- MySQL分割槽介紹MySql
- Oracle分割槽表介紹Oracle
- mysql表分割槽技術詳細介紹MySql
- MySQL KEY分割槽MySql
- 分割槽表基礎介紹
- MySQL 分割槽介紹總結MySql
- MySql建立分割槽MySql
- mysql幾種表分割槽建立案例MySql
- 分割槽表及分割槽索引建立示例索引
- (3) MySQL分割槽表使用方法MySql
- 【MYSQL】 分割槽表MySql
- MySQL 分割槽表MySql
- MySQL分割槽表MySql
- Oracle 建立分割槽表Oracle
- mysql分割槽功能、例項詳細介紹MySql
- rebuild分割槽表分割槽索引的方法Rebuild索引
- Oracle 分割槽表的建立Oracle
- OceaBase 分割槽表建立技巧
- MySQL 分割槽表探索MySql
- mysql 分表 分割槽MySql
- mysql 分割槽表用法MySql
- MySQL表分割槽管理MySql
- MySQL 分割槽表 partition線上修改分割槽欄位MySql
- 分割槽表並行建立索引並行索引
- mysql 進行表分割槽MySql
- Mysql表分割槽實現MySql
- mysql分割槽表筆記MySql筆記
- MySQL入門--分割槽表MySql
- mysql —— 分表分割槽(1)MySql
- MySQL的List分割槽表MySql
- windows11怎麼分割槽硬碟 win11硬碟分割槽大小方法介紹Windows硬碟
- MySQL分割槽表的分割槽原理和優缺點MySql
- 將mysql非分割槽錶轉換為分割槽表MySql
- 全面學習分割槽表及分割槽索引(6)--建立range-list組合分割槽索引
- MySQL 分割槽表知識整理MySql
- MySQL調優之分割槽表MySql
- mysql的分割槽和分表MySql
- mysql的分割槽與分表MySql