bin
发布于

在 varchar 列上对 mysql 表进行分区

有一个包含 40 亿条记录的 mysql(v8.x) 表,需要对其中一个 varchar 列进行分区。 在这种情况下,日期列或整数列分区不起作用。 这是一个独特的用例。

分区将在 cust_id 列上进行 cust_id 包含如下数据

  | 2184-204CECE8FPNE_01_0102_4 |
| 2184-08NFINO3NC0E_01_0102_4 |
| 2185-B28RNFPE3NCS_01_0102_4 |
| 2185-HP3DNFNF2DNF_01_0102_4 |
| 9732-0I02NCNN30DW_01_0102_4 |
| 9732-8JFN30FJMDP3_01_0102_4 |
| 9732-B02F30CN3D25_01_0102_4 |
| 3184-N33NF4FNPF33_01_0102_4 |
| 3184-0702NDNDJD3S_01_0102_4 |

既然数据中有连字符,该如何对数据进行分区呢?

这是尝试的 create 语句,它不起作用

  CREATE TABLE cust_part (
  id varchar(127) NOT NULL,
  cust_id varchar(127) NOT NULL,
  PRIMARY KEY (id,cust_id),
  KEY idx_cust_id (cust_id)
) 
PARTITION BY RANGE COLUMNS (substring_index(cust_id,'-',1))
(
PARTITION p1000 VALUES LESS THAN ('1000'),
PARTITION p2000 VALUES LESS THAN ('2000'),
PARTITION p3000 VALUES LESS THAN ('3000'),
PARTITION p4000 VALUES LESS THAN ('4000'),
PARTITION p5000 VALUES LESS THAN ('5000'),
PARTITION p6000 VALUES LESS THAN ('6000'),
PARTITION p7000 VALUES LESS THAN ('7000'),
PARTITION p8000 VALUES LESS THAN ('8000'),
PARTITION p9000 VALUES LESS THAN ('9000'),
PARTITION p10000 VALUES LESS THAN ('10000'),
PARTITION pMax VALUES LESS THAN MAXVALUE
);
浏览 (29)
点赞 (1)
收藏
1条评论
Klustron小助手
Klustron小助手
试试这个: CREATE TABLE cust_part ( id varchar(127) NOT NULL, cust_id varchar(127) NOT NULL, PRIMARY KEY (id,cust_id), KEY idx_cust_id (cust_id) ) PARTITION BY RANGE COLUMNS (cust_id) ( PARTITION p1000 VALUES LESS THAN ('1000-'), PARTITION p10000 VALUES LESS THAN ('10000-'), PARTITION p2000 VALUES LESS THAN ('2000-'), PARTITION p3000 VALUES LESS THAN ('3000-'), PARTITION p4000 VALUES LESS THAN ('4000-'), PARTITION p5000 VALUES LESS THAN ('5000-'), PARTITION p6000 VALUES LESS THAN ('6000-'), PARTITION p7000 VALUES LESS THAN ('7000-'), PARTITION p8000 VALUES LESS THAN ('8000-'), PARTITION p9000 VALUES LESS THAN ('9000-'), PARTITION pMax VALUES LESS THAN MAXVALUE ); 按字母顺序,介于 和 之间。您必须以类似的方式订购任何其他分区。'10000-''1000-''2000-
点赞
评论