MySQL 分区

https://dev.mysql.com/doc/refman/9.2/en/partitioning.html

https://www.cnblogs.com/chenmh/p/5644496.html

https://kimi.moonshot.cn/share/cuj182051tqdt9c6uu4g

sql 复制代码
DROP TABLE IF EXISTS `tb_ad_account_insight_0`;
CREATE TABLE `tb_ad_account_insight_0`
(
    `id`           bigint      NOT NULL AUTO_INCREMENT COMMENT '主键',
    `account_id`   varchar(30) NOT NULL COMMENT '账户id',
    `account_name` varchar(30) NOT NULL COMMENT '账户名称',
    `date_start`   varchar(30) NOT NULL COMMENT '统计起始日期',
    `date_stop`    varchar(30) NOT NULL COMMENT '统计终止日期',
    `impressions`  decimal(20, 2) NULL DEFAULT 0 COMMENT '展示',
    `clicks`       decimal(20, 2) NULL DEFAULT 0 COMMENT '点击',
    `created_time` datetime    NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
    `updated_time` datetime    NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '更新时间',
    `is_delete`    tinyint(1) NOT NULL DEFAULT 0 COMMENT '逻辑删除',
    PRIMARY KEY (`id`, `account_id`)
) PARTITION BY KEY(account_id)
PARTITIONS 10;
sql 复制代码
DROP TABLE IF EXISTS `tb_ad_account_insight_0`;
CREATE TABLE `tb_ad_account_insight_0`
(
    `id`           BIGINT         NOT NULL AUTO_INCREMENT COMMENT '主键',
    `account_id`   varchar(30) NOT NULL COMMENT '账户id',
    `account_name` varchar(30) NOT NULL COMMENT '账户名称',
    `country`      varchar(80) NOT NULL COMMENT '国家',
    `date_start`   varchar(30) NOT NULL COMMENT '统计开始日期',
    `date_stop`    varchar(30) NOT NULL COMMENT '统计终止日期',
    `impressions`  decimal(20, 2) NULL DEFAULT 0 COMMENT '展示',
    `clicks`       decimal(20, 2) NULL DEFAULT 0 COMMENT '点击',
    `created_time` datetime    NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
    `updated_time` datetime    NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '更新时间',
    `is_delete`    tinyint(1) NOT NULL DEFAULT 0 COMMENT '逻辑删除',
    PRIMARY KEY (`id`, `account_id`, `country`),
    INDEX `idx_account_id_date_start` (`account_id`, `date_start`)
)
PARTITION BY KEY(account_id, country)
PARTITIONS 10;

account_id 本身就是唯一的,那么这里的 id 还有必要吗?

MySQL 中的分区仅支持水平分区

MySQL 中的分区会对表中的数据及表中的唯一索引(包括主键)进行分区,而分区的依据是分区键,故表的所有唯一索引中必须包含分区键。

复制代码
1503 - A UNIQUE INDEX must include all columns in the table's partitioning function (prefixed columns are not considered).

前缀列的含义:在某些数据库系统中,前缀列(prefixed columns)可能指的是那些只使用了部分列值的列。例如,如果你有一个列是字符串类型,而你只用它的前几个字符作为索引的一部分,那么这个列就被认为是"前缀列"。这种情况下,数据库系统会明确指出,仅使用列的前缀部分是不足以满足分区键的要求的。

相关推荐
周航宇JoeZhou4 小时前
JP3-3-MyClub后台后端(二)
java·mysql·vue·ssm·springboot·项目·myclub
-SGlow-6 小时前
MySQL相关概念和易错知识点(3)(表内容的CURD、内置函数)
linux·运维·服务器·数据库·mysql
飞翔的佩奇6 小时前
基于SpringBoot+MyBatis+MySQL+VUE实现的经方药食两用服务平台管理系统(附源码+数据库+毕业论文+部署教程+配套软件)
数据库·vue.js·spring boot·mysql·毕业设计·mybatis·经方药食两用平台
孫治AllenSun9 小时前
【Mysql】字段隐式转换对where条件和join关联条件的影响
数据库·mysql·oracle
Doris_LMS10 小时前
保姆级别IDEA关联数据库方式、在IDEA中进行数据库的可视化操作(包含图解过程)
java·mysql·postgresql
2301_7930868710 小时前
Mysql group by
数据库·mysql
_码农1213811 小时前
spring boot + mybatis + mysql 只有一个实体类的demo
spring boot·mysql·mybatis
IT-david14 小时前
MySQL分析步
mysql
止水编程 water_proof15 小时前
MySQL——事务详解
数据库·mysql
不似桂花酒16 小时前
数据库小知识
数据库·sql·mysql