From 515767f2ec9e1c4640ac8865154769d1ef20858c Mon Sep 17 00:00:00 2001 From: zhangxuan_hw Date: Thu, 18 Apr 2024 15:35:15 +0800 Subject: [PATCH 1/3] Fix Bug --- .../suite/tianchi/r/ctc_ddl_analyze.result | 41 +++++++++++++++++++ .../suite/tianchi/t/ctc_ddl_analyze.test | 41 ++++++++++++++++++- storage/tianchi/ha_tsepart.cc | 41 ++++++++++++++----- 3 files changed, 112 insertions(+), 11 deletions(-) diff --git a/mysql-test/suite/tianchi/r/ctc_ddl_analyze.result b/mysql-test/suite/tianchi/r/ctc_ddl_analyze.result index be63df2..d95d74b 100644 --- a/mysql-test/suite/tianchi/r/ctc_ddl_analyze.result +++ b/mysql-test/suite/tianchi/r/ctc_ddl_analyze.result @@ -70,3 +70,44 @@ Warnings: Note 1003 /* select#1 */ select `test`.`t1`.`a1` AS `a1` from `test`.`t1` where (`test`.`t1`.`a1` = 1) drop table t1; drop table DEMO; +create table t1( +c30 BIGINT +)partition by range(c30) +subpartition by hash(c30) subpartitions 2( +partition p0 values less than (1000000), +partition p1 values less than (2000000), +partition p2 values less than (6000000) +); +alter table t1 analyze Partition p1; +Table Op Msg_type Msg_text +test.t1 analyze status OK +drop table if exists t1; +create table t1( +a int not null, +b varchar(500) default null, +primary Key(a) +) +PARTITION by range(`a`) +SUBPARTITION by HASH(`a`) +(PARTITION p0 values less than(100) +(SUBPARTITION sp0, +SUBPARTITION sp1), +PARTITION p1 values less than MAXVALUE +(SUBPARTITION sp2, +SUBPARTITION sp3)); +alter table t1 analyze partition sp3; +Table Op Msg_type Msg_text +test.t1 analyze status OK +drop table if exists t1; +create table t1( +a int not null, +b varchar(500) default null, +primary Key(a) +) +PARTITION by range(`a`) +(PARTITION p0 values less than(100), +PARTITION p1 values less than MAXVALUE); +alter table t1 analyze partition p0; +Table Op Msg_type Msg_text +test.t1 analyze status OK +drop table t1; diff --git a/mysql-test/suite/tianchi/t/ctc_ddl_analyze.test b/mysql-test/suite/tianchi/t/ctc_ddl_analyze.test index b36212a..e63a6e1 100644 --- a/mysql-test/suite/tianchi/t/ctc_ddl_analyze.test +++ b/mysql-test/suite/tianchi/t/ctc_ddl_analyze.test @@ -49,4 +49,43 @@ explain select a1 from t1 where a1 = 1; drop table t1; #drop table -drop table DEMO; \ No newline at end of file +drop table DEMO; + +create table t1( +c30 BIGINT +)partition by range(c30) +subpartition by hash(c30) subpartitions 2( +partition p0 values less than (1000000), +partition p1 values less than (2000000), +partition p2 values less than (6000000) +); +alter table t1 analyze Partition p1; + +drop table if exists t1; +create table t1( +a int not null, +b varchar(500) default null, +primary Key(a) +) +PARTITION by range(`a`) +SUBPARTITION by HASH(`a`) +(PARTITION p0 values less than(100) +(SUBPARTITION sp0, +SUBPARTITION sp1), +PARTITION p1 values less than MAXVALUE +(SUBPARTITION sp2, +SUBPARTITION sp3)); +alter table t1 analyze partition sp3; +drop table if exists t1; +create table t1( +a int not null, +b varchar(500) default null, +primary Key(a) +) +PARTITION by range(`a`) +(PARTITION p0 values less than(100), +PARTITION p1 values less than MAXVALUE); +alter table t1 analyze partition p0; +drop table t1; + + diff --git a/storage/tianchi/ha_tsepart.cc b/storage/tianchi/ha_tsepart.cc index 0a93cb3..be58669 100644 --- a/storage/tianchi/ha_tsepart.cc +++ b/storage/tianchi/ha_tsepart.cc @@ -72,18 +72,33 @@ static uint32_t get_ct_part_no(uint num_subparts, uint part_id) { return (uint32_t)part_no; } -static void get_used_partitions(partition_info *part_info, uint32_t **part_ids, uint32_t *used_parts) { +static void get_used_partitions(partition_info *part_info, + uint32_t **part_ids,uint32_t **subpart_ids, uint32_t *used_parts) { *used_parts = part_info->num_partitions_used(); + assert(*used_parts == 0); *part_ids = (uint32_t *)my_malloc(PSI_NOT_INSTRUMENTED, (*used_parts) * sizeof(uint32_t), MYF(MY_WME)); - - uint32_t part_id = part_info->get_first_used_partition(); - **part_ids = part_id; - for (uint32_t i = 1; i < *used_parts; i++) { - part_id = part_info->get_next_used_partition(part_id); - *(*part_ids + i) = part_id; + *subpart_ids = (uint32_t *)my_malloc(PSI_NOT_INSTRUMENTED, (*used_parts) * sizeof(uint32_t), MYF(MY_WME)); + uint32_t part_id = part_info->get_first_used_partition(); + if(part_id == MY_BIT_NONE){ + return; + } + if(part_info->num_subparts > 0){ + // partition + for (uint32_t i = 0; i < *used_parts; i++) { + *(*part_ids + i) = part_id / part_info->num_subparts; + *(*subpart_ids + i) = part_id % part_info->num_subparts; + part_id = part_info->get_next_used_partition(part_id); + } + }else{ + // subpartition + for (uint32_t i = 0; i < *used_parts; i++) { + *(*part_ids + i) = part_id; + *(*subpart_ids + i) = 0; + part_id = part_info->get_next_used_partition(part_id); + } } } -//计算申请cbo_stats结构所需内存 + uint64_t calculate_size_of_cbo_part_stats(TABLE *table,uint32_t part_num){ uint64_t size_mem = 0; for (uint i = 0; i < part_num; i++) { @@ -916,30 +931,36 @@ int ha_tsepart::analyze(THD *thd, HA_CHECK_OPT *opt) { } int ret; uint32_t used_parts; - uint32_t *part_ids = NULL; + uint32_t *part_ids = nullptr; + uint32_t *subpart_ids = nullptr; if (!m_part_info->set_read_partitions(&alter_info->partition_names)) { - get_used_partitions(m_part_info, &part_ids, &used_parts); + get_used_partitions(m_part_info, &part_ids, &subpart_ids, &used_parts); } else { tse_log_error("no partition alter !"); return HA_ERR_GENERIC; } if (m_part_info->num_parts == used_parts) { m_tch.part_id = INVALID_PART_ID; + my_free(subpart_ids); my_free(part_ids); m_part_share->need_fetch_cbo = true; return ha_tse::analyze(thd, opt); } for (uint i = 0; i < used_parts; i++) { uint32_t part_id = part_ids[i]; + uint32_t subpart_id = subpart_ids[i]; m_tch.part_id = part_id; + m_tch.subpart_id = subpart_id; m_part_share->need_fetch_cbo = true; ret = ha_tse::analyze(thd, opt); if (ret != 0) { tse_log_error("analyze partition error!"); + my_free(subpart_ids); my_free(part_ids); return ret; } } + my_free(subpart_ids); my_free(part_ids); return ret; } -- Gitee From c1108db102cbe7969f4ca08e42b3d9f0b261a044 Mon Sep 17 00:00:00 2001 From: zhangxuan_hw Date: Thu, 18 Apr 2024 15:35:15 +0800 Subject: [PATCH 2/3] Fix Bug --- .../suite/tianchi/r/ctc_ddl_analyze.result | 41 +++++++++++++++++ .../suite/tianchi/t/ctc_ddl_analyze.test | 41 ++++++++++++++++- storage/tianchi/ha_tsepart.cc | 44 ++++++++++++++----- 3 files changed, 114 insertions(+), 12 deletions(-) diff --git a/mysql-test/suite/tianchi/r/ctc_ddl_analyze.result b/mysql-test/suite/tianchi/r/ctc_ddl_analyze.result index be63df2..d95d74b 100644 --- a/mysql-test/suite/tianchi/r/ctc_ddl_analyze.result +++ b/mysql-test/suite/tianchi/r/ctc_ddl_analyze.result @@ -70,3 +70,44 @@ Warnings: Note 1003 /* select#1 */ select `test`.`t1`.`a1` AS `a1` from `test`.`t1` where (`test`.`t1`.`a1` = 1) drop table t1; drop table DEMO; +create table t1( +c30 BIGINT +)partition by range(c30) +subpartition by hash(c30) subpartitions 2( +partition p0 values less than (1000000), +partition p1 values less than (2000000), +partition p2 values less than (6000000) +); +alter table t1 analyze Partition p1; +Table Op Msg_type Msg_text +test.t1 analyze status OK +drop table if exists t1; +create table t1( +a int not null, +b varchar(500) default null, +primary Key(a) +) +PARTITION by range(`a`) +SUBPARTITION by HASH(`a`) +(PARTITION p0 values less than(100) +(SUBPARTITION sp0, +SUBPARTITION sp1), +PARTITION p1 values less than MAXVALUE +(SUBPARTITION sp2, +SUBPARTITION sp3)); +alter table t1 analyze partition sp3; +Table Op Msg_type Msg_text +test.t1 analyze status OK +drop table if exists t1; +create table t1( +a int not null, +b varchar(500) default null, +primary Key(a) +) +PARTITION by range(`a`) +(PARTITION p0 values less than(100), +PARTITION p1 values less than MAXVALUE); +alter table t1 analyze partition p0; +Table Op Msg_type Msg_text +test.t1 analyze status OK +drop table t1; diff --git a/mysql-test/suite/tianchi/t/ctc_ddl_analyze.test b/mysql-test/suite/tianchi/t/ctc_ddl_analyze.test index b36212a..e63a6e1 100644 --- a/mysql-test/suite/tianchi/t/ctc_ddl_analyze.test +++ b/mysql-test/suite/tianchi/t/ctc_ddl_analyze.test @@ -49,4 +49,43 @@ explain select a1 from t1 where a1 = 1; drop table t1; #drop table -drop table DEMO; \ No newline at end of file +drop table DEMO; + +create table t1( +c30 BIGINT +)partition by range(c30) +subpartition by hash(c30) subpartitions 2( +partition p0 values less than (1000000), +partition p1 values less than (2000000), +partition p2 values less than (6000000) +); +alter table t1 analyze Partition p1; + +drop table if exists t1; +create table t1( +a int not null, +b varchar(500) default null, +primary Key(a) +) +PARTITION by range(`a`) +SUBPARTITION by HASH(`a`) +(PARTITION p0 values less than(100) +(SUBPARTITION sp0, +SUBPARTITION sp1), +PARTITION p1 values less than MAXVALUE +(SUBPARTITION sp2, +SUBPARTITION sp3)); +alter table t1 analyze partition sp3; +drop table if exists t1; +create table t1( +a int not null, +b varchar(500) default null, +primary Key(a) +) +PARTITION by range(`a`) +(PARTITION p0 values less than(100), +PARTITION p1 values less than MAXVALUE); +alter table t1 analyze partition p0; +drop table t1; + + diff --git a/storage/tianchi/ha_tsepart.cc b/storage/tianchi/ha_tsepart.cc index 0a93cb3..2925b08 100644 --- a/storage/tianchi/ha_tsepart.cc +++ b/storage/tianchi/ha_tsepart.cc @@ -72,18 +72,34 @@ static uint32_t get_ct_part_no(uint num_subparts, uint part_id) { return (uint32_t)part_no; } -static void get_used_partitions(partition_info *part_info, uint32_t **part_ids, uint32_t *used_parts) { +static void get_used_partitions(partition_info *part_info, + uint32_t **part_ids,uint32_t **subpart_ids, uint32_t *used_parts) { *used_parts = part_info->num_partitions_used(); - *part_ids = (uint32_t *)my_malloc(PSI_NOT_INSTRUMENTED, (*used_parts) * sizeof(uint32_t), MYF(MY_WME)); - - uint32_t part_id = part_info->get_first_used_partition(); - **part_ids = part_id; - for (uint32_t i = 1; i < *used_parts; i++) { - part_id = part_info->get_next_used_partition(part_id); - *(*part_ids + i) = part_id; + if (*used_parts != 0) { + *part_ids = (uint32_t *)my_malloc(PSI_NOT_INSTRUMENTED, (*used_parts) * sizeof(uint32_t), MYF(MY_WME)); + *subpart_ids = (uint32_t *)my_malloc(PSI_NOT_INSTRUMENTED, (*used_parts) * sizeof(uint32_t), MYF(MY_WME)); + uint32_t part_id = part_info->get_first_used_partition(); + if(part_id == MY_BIT_NONE){ + return; + } + if(part_info->num_subparts > 0){ + // partition + for (uint32_t i = 0; i < *used_parts; i++) { + *(*part_ids + i) = part_id / part_info->num_subparts; + *(*subpart_ids + i) = part_id % part_info->num_subparts; + part_id = part_info->get_next_used_partition(part_id); + } + }else{ + // subpartition + for (uint32_t i = 0; i < *used_parts; i++) { + *(*part_ids + i) = part_id; + *(*subpart_ids + i) = 0; + part_id = part_info->get_next_used_partition(part_id); + } + } } } -//计算申请cbo_stats结构所需内存 + uint64_t calculate_size_of_cbo_part_stats(TABLE *table,uint32_t part_num){ uint64_t size_mem = 0; for (uint i = 0; i < part_num; i++) { @@ -916,30 +932,36 @@ int ha_tsepart::analyze(THD *thd, HA_CHECK_OPT *opt) { } int ret; uint32_t used_parts; - uint32_t *part_ids = NULL; + uint32_t *part_ids = nullptr; + uint32_t *subpart_ids = nullptr; if (!m_part_info->set_read_partitions(&alter_info->partition_names)) { - get_used_partitions(m_part_info, &part_ids, &used_parts); + get_used_partitions(m_part_info, &part_ids, &subpart_ids, &used_parts); } else { tse_log_error("no partition alter !"); return HA_ERR_GENERIC; } if (m_part_info->num_parts == used_parts) { m_tch.part_id = INVALID_PART_ID; + my_free(subpart_ids); my_free(part_ids); m_part_share->need_fetch_cbo = true; return ha_tse::analyze(thd, opt); } for (uint i = 0; i < used_parts; i++) { uint32_t part_id = part_ids[i]; + uint32_t subpart_id = subpart_ids[i]; m_tch.part_id = part_id; + m_tch.subpart_id = subpart_id; m_part_share->need_fetch_cbo = true; ret = ha_tse::analyze(thd, opt); if (ret != 0) { tse_log_error("analyze partition error!"); + my_free(subpart_ids); my_free(part_ids); return ret; } } + my_free(subpart_ids); my_free(part_ids); return ret; } -- Gitee From 8dc9b3efd440c4e270bb5968aae0fa771ca00c50 Mon Sep 17 00:00:00 2001 From: zhangxuan_hw Date: Tue, 30 Apr 2024 16:16:58 +0800 Subject: [PATCH 3/3] fix --- storage/tianchi/ha_tsepart.cc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/storage/tianchi/ha_tsepart.cc b/storage/tianchi/ha_tsepart.cc index 89ca831..54a9462 100644 --- a/storage/tianchi/ha_tsepart.cc +++ b/storage/tianchi/ha_tsepart.cc @@ -75,7 +75,7 @@ static uint32_t get_ct_part_no(uint num_subparts, uint part_id) { static void get_used_partitions(partition_info *part_info, uint32_t **part_ids,uint32_t **subpart_ids, uint32_t *used_parts) { *used_parts = part_info->num_partitions_used(); - if (*used_parts != 0) { + if (*used_parts > 0) { *part_ids = (uint32_t *)my_malloc(PSI_NOT_INSTRUMENTED, (*used_parts) * sizeof(uint32_t), MYF(MY_WME)); *subpart_ids = (uint32_t *)my_malloc(PSI_NOT_INSTRUMENTED, (*used_parts) * sizeof(uint32_t), MYF(MY_WME)); uint32_t part_id = part_info->get_first_used_partition(); @@ -96,6 +96,7 @@ static void get_used_partitions(partition_info *part_info, *(*subpart_ids + i) = 0; part_id = part_info->get_next_used_partition(part_id); } + } } } -- Gitee