Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SQL issue-[Script issue]: Specified key was too long; max key length is 3072 bytes #356

Closed
huan11 opened this issue Jul 9, 2024 · 5 comments

Comments

@huan11
Copy link
Contributor

huan11 commented Jul 9, 2024

Describe the bug

Env: MySQL version: Server version: 8.0.37 MySQL Community Server - GPL

Scripts: https://github.com/sofastack/sofa-registry/blob/master/create_table.sql

CREATE TABLE IF NOT EXISTS multi_cluster_sync_info
(
    id                   bigint(20)    NOT NULL AUTO_INCREMENT COMMENT '主键',
    data_center          varchar(512)  NOT NULL COMMENT '集群名称',
    remote_data_center   varchar(512)  NOT NULL COMMENT '同步的集群名称',
    remote_meta_address  varchar(1024) NOT NULL COMMENT '同步的集群地址',
    enable_sync_datum    varchar(16)   NOT NULL COMMENT 'datum同步的开关是否开启',
    enable_push          varchar(16)   NOT NULL COMMENT '同步的数据是否允许推送',
    sync_datainfoids     MEDIUMTEXT    NOT NULL COMMENT '同步的dataInfoId名单',
    syn_publisher_groups varchar(4096) NOT NULL COMMENT '同步的group名单',
    ignore_datainfoids   MEDIUMTEXT    NOT NULL COMMENT '忽略同步的dataInfoId',
    data_version         bigint(20)    NOT NULL DEFAULT '0' COMMENT '版本号',
    gmt_create           timestamp     NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
    gmt_modified         timestamp     NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '修改时间',
    PRIMARY KEY (id),
    UNIQUE KEY uk_table_key (data_center, remote_data_center),
    KEY idx_data_center (data_center)
);

[2024-07-09 13:07:10] [42000][1071] Specified key was too long; max key length is 3072 bytes

Expected behavior

Script shld be work well.

Actual behavior

When follow the guide (https://www.sofastack.tech/projects/sofa-registry/server-quick-start/ ), it failed at '2.启动 registry-integration' Step.

how to fix

reduce the width of column data_center and column remote_data_center. (change 512 to 255)

CREATE TABLE IF NOT EXISTS multi_cluster_sync_info
(
    id                   bigint(20)    NOT NULL AUTO_INCREMENT COMMENT '主键',
    data_center          varchar(255)  NOT NULL COMMENT '集群名称',
    remote_data_center   varchar(255)  NOT NULL COMMENT '同步的集群名称',
    remote_meta_address  varchar(1024) NOT NULL COMMENT '同步的集群地址',
    enable_sync_datum    varchar(16)   NOT NULL COMMENT 'datum同步的开关是否开启',
    enable_push          varchar(16)   NOT NULL COMMENT '同步的数据是否允许推送',
    sync_datainfoids     MEDIUMTEXT    NOT NULL COMMENT '同步的dataInfoId名单',
    syn_publisher_groups varchar(4096) NOT NULL COMMENT '同步的group名单',
    ignore_datainfoids   MEDIUMTEXT    NOT NULL COMMENT '忽略同步的dataInfoId',
    data_version         bigint(20)    NOT NULL DEFAULT '0' COMMENT '版本号',
    gmt_create           timestamp     NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
    gmt_modified         timestamp     NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '修改时间',
    PRIMARY KEY (id),
    UNIQUE KEY uk_table_key (data_center, remote_data_center),
    KEY idx_data_center (data_center)
);

Environment

Env: MySQL version: Server version: 8.0.37 MySQL Community Server - GPL

@NickNYU
Copy link
Contributor

NickNYU commented Jul 9, 2024

Thanks for contribute @huan11 .
Just to confirm that why we prefer to change remote_data_center, data_center, while keeping syn_publisher_groups as the same, if the issue is varchar length related?

@huan11
Copy link
Contributor Author

huan11 commented Jul 9, 2024

@NickNYU yes, UNIQUE KEY is too long which caused the issue.

UNIQUE KEY uk_table_key (data_center, remote_data_center),

@NickNYU
Copy link
Contributor

NickNYU commented Jul 9, 2024

@NickNYU yes, UNIQUE KEY is too long which caused the issue.

UNIQUE KEY uk_table_key (data_center, remote_data_center),

Awesome!! that's reasonable

Please send a Pull Request according to this question, thanks

The basic idea of the varchar length is a draft thought when I was defining the table, not a big deal. It is just in Ant Group we leverage OceanBase as default DB, and seems like OB has a high toleration than traditional DBs.

@huan11
Copy link
Contributor Author

huan11 commented Jul 9, 2024

@NickNYU PR have been raised : )

@NickNYU
Copy link
Contributor

NickNYU commented Jul 10, 2024

PR has been merged, thx for contribution @huan11
I'll close this issue

@NickNYU NickNYU closed this as completed Jul 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants