Mysql-分区表

Mysql-分区表

例子

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
## MYSQL的分区字段,必须包含在主键字段内。
## Error Code: 1171. All parts of a PRIMARY KEY must be NOT NULL; if you need NULL in a key, use UNIQUE instead

CREATE TABLE farm.`test1` (
`id` bigint NOT NULL COMMENT '主键ID',
`task_id` bigint DEFAULT NULL COMMENT '作业ID',
`speed_per_hour` double(10,2) DEFAULT NULL COMMENT '时速',
`total_used_time` int DEFAULT NULL COMMENT '累计耗时',
`operated_offset` double(10,2) DEFAULT NULL COMMENT '偏移量',
`percent` varchar(10) DEFAULT NULL COMMENT '作业任务进度(规则:作业里程结束为任务进度100%)',
`operated_area` double(10,2) DEFAULT NULL COMMENT '已作业亩数(使用田块规划里程和总里程计算)',
`operated_mileage` double(10,2) DEFAULT NULL COMMENT '已作业总路程',
`no_operated_mileage` double(10,2) DEFAULT NULL COMMENT '未作业路程',
`total_mileage` double DEFAULT NULL COMMENT '作业总里程',
`no_operate_area` double(10,2) DEFAULT NULL COMMENT '未作业亩数',
`type_name` varchar(20) DEFAULT NULL COMMENT '作业类型名称',
`total_area` double(10,2) DEFAULT NULL COMMENT '要求作业总亩数',
`remaining_oil` double(10,2) DEFAULT NULL COMMENT '剩余油量',
`driver_mode` tinyint DEFAULT NULL COMMENT '驾驶模式',
`rtk_status` int DEFAULT NULL COMMENT 'RTK状态 固定解=4, 0无效解,1单点定位解,2伪距差分,5浮动解',
`engine_speed` int DEFAULT NULL COMMENT '发动机转速',
`real_oil` double(10,2) DEFAULT NULL COMMENT '实时油耗',
`machine_name` varchar(50) DEFAULT NULL COMMENT '作业农机名称',
`implement_name` varchar(50) DEFAULT NULL COMMENT '作业农具名称',
`segment_percent` varchar(10) DEFAULT NULL COMMENT '路径完成度',
`yaw` double DEFAULT NULL COMMENT '航向角',
`longitude_position` double DEFAULT NULL COMMENT '位置经度',
`latitude_position` double DEFAULT NULL COMMENT '位置纬度',
`gnss_num` int DEFAULT NULL COMMENT '当前卫星数量',
`network_signal` int DEFAULT NULL COMMENT '网络信号强度',
`json_values` json DEFAULT NULL COMMENT '网络信号强度',
`generate_time` bigint DEFAULT NULL COMMENT '设备消息生成时间戳',
`create_time` datetime NOT NULL COMMENT '创建时间',test1
`task_index` int NOT NULL COMMENT '子任务id',
`x_position` double DEFAULT NULL COMMENT '位置x',
`y_position` double DEFAULT NULL COMMENT '位置y',
`operated_offset_direction` tinyint DEFAULT NULL COMMENT '偏移量方向(1左,2右)',
`width_of_cloth` double DEFAULT NULL COMMENT '农具工作幅宽',
`imple_work_state` tinyint DEFAULT NULL COMMENT '农具工作状态: 1未作业 2正在作业',
PRIMARY KEY (`id`,create_time),
KEY `index_name` (`task_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='农机实时消息LOG'

partition by range columns (create_time)(
partition p1 values less than ('2021-11-01'),
partition p2 values less than ('2021-12-01'),
partition p3 values less than ('2022-01-01')
);