diff --git a/mysql-test/suite/ctc/r/ctc_ddl_func_index.result b/mysql-test/suite/ctc/r/ctc_ddl_func_index.result index c61b0af2c80c04efe02f38c5c31042f14b6f5918..957ca54bc91769525584481badf70272b0081ee9 100644 --- a/mysql-test/suite/ctc/r/ctc_ddl_func_index.result +++ b/mysql-test/suite/ctc/r/ctc_ddl_func_index.result @@ -139,4 +139,58 @@ create table t6 (c1 int, c2 int); create index index_func_idx_1 on t6 ((if(c1 = 1, 1, 3))); ERROR HY000: Function if is not indexable drop table t6; +create table t7 (c1 varbinary(20)); +insert into t7 values ('ab一二'), ('ab一er'); +create unique index func_idx1 on t7 ((substr(c1, 2, 2))); +ERROR 23000: Duplicate entry 'bä' for key 't7.func_idx1' +create unique index func_idx2 on t7 ((substr(c1, 2, 4))); +ERROR 23000: Duplicate entry 'b一' for key 't7.func_idx2' +alter table t7 add unique key func_idx3(c1(4)); +ERROR 23000: Duplicate entry 'abä¸' for key 't7.func_idx3' +create unique index func_idx4 on t7 ((substr(upper(c1), 2, 2))); +ERROR 23000: Duplicate entry 'Bä' for key 't7.func_idx4' +drop table t7; +create table t8 (c1 blob); +insert into t8 values ('ab一二'), ('ab一er'); +create unique index func_idx1 on t8 ((substr(c1, 2, 2))); +ERROR 23000: Duplicate entry 'bä' for key 't8.func_idx1' +create unique index func_idx2 on t8 ((substr(c1, 2, 4))); +ERROR 23000: Duplicate entry 'b一' for key 't8.func_idx2' +alter table t8 add unique key func_idx3(c1(4)); +ERROR 23000: Duplicate entry 'abä¸' for key 't8.func_idx3' +drop table t8; +create table t9 (c1 varchar(20)); +insert into t9 values ('ab一二'), ('ab一er'); +create unique index func_idx1 on t9 ((substr(c1, 2, 2))); +ERROR 23000: Duplicate entry 'b一' for key 't9.func_idx1' +create unique index func_idx2 on t9 ((substr(c1, 2, 4))); +alter table t9 add unique key func_idx3(c1(4)); +create unique index func_idx4 on t9 ((substr(upper(c1), 2, 2))); +ERROR 23000: Duplicate entry 'B一' for key 't9.func_idx4' +drop table t9; +create table t10 (c1 text); +insert into t10 values ('ab一二'), ('ab一er'); +create unique index func_idx1 on t10 ((substr(c1, 2, 2))); +ERROR 23000: Duplicate entry 'b一' for key 't10.func_idx1' +create unique index func_idx2 on t10 ((substr(c1, 2, 4))); +alter table t10 add unique key func_idx3(c1(4)); +drop table t10; +create table t11 (c1 varchar(20)) default charset = binary; +insert into t11 values ('ab一二'), ('ab一er'); +create unique index func_idx1 on t11 ((substr(c1, 2, 2))); +ERROR 23000: Duplicate entry 'bä' for key 't11.func_idx1' +create unique index func_idx2 on t11 ((substr(c1, 2, 4))); +ERROR 23000: Duplicate entry 'b一' for key 't11.func_idx2' +alter table t11 add unique key func_idx3(c1(4)); +ERROR 23000: Duplicate entry 'abä¸' for key 't11.func_idx3' +drop table t11; +create table t12 (c1 text) default charset = binary; +insert into t12 values ('ab一二'), ('ab一er'); +create unique index func_idx1 on t12 ((substr(c1, 2, 2))); +ERROR 23000: Duplicate entry 'bä' for key 't12.func_idx1' +create unique index func_idx2 on t12 ((substr(c1, 2, 4))); +ERROR 23000: Duplicate entry 'b一' for key 't12.func_idx2' +alter table t12 add unique key func_idx3(c1(4)); +ERROR 23000: Duplicate entry 'abä¸' for key 't12.func_idx3' +drop table t12; drop database db1; diff --git a/mysql-test/suite/ctc/t/ctc_ddl_func_index.test b/mysql-test/suite/ctc/t/ctc_ddl_func_index.test index df44be2aa111d7fd286c9df930059372621ee829..a4c4fd9cc2ee91540240001729aefb4a4b073797 100644 --- a/mysql-test/suite/ctc/t/ctc_ddl_func_index.test +++ b/mysql-test/suite/ctc/t/ctc_ddl_func_index.test @@ -71,4 +71,65 @@ create index index_func_idx_1 on t6 ((if(c1 = 1, 1, 3))); drop table t6; +# 创建混合中英文字符索引场景 +create table t7 (c1 varbinary(20)); +insert into t7 values ('ab一二'), ('ab一er'); +--error ER_DUP_ENTRY +create unique index func_idx1 on t7 ((substr(c1, 2, 2))); +--error ER_DUP_ENTRY +create unique index func_idx2 on t7 ((substr(c1, 2, 4))); +--error ER_DUP_ENTRY +alter table t7 add unique key func_idx3(c1(4)); +--error ER_DUP_ENTRY +create unique index func_idx4 on t7 ((substr(upper(c1), 2, 2))); +drop table t7; + +create table t8 (c1 blob); +insert into t8 values ('ab一二'), ('ab一er'); +--error ER_DUP_ENTRY +create unique index func_idx1 on t8 ((substr(c1, 2, 2))); +--error ER_DUP_ENTRY +create unique index func_idx2 on t8 ((substr(c1, 2, 4))); +--error ER_DUP_ENTRY +alter table t8 add unique key func_idx3(c1(4)); +drop table t8; + +create table t9 (c1 varchar(20)); +insert into t9 values ('ab一二'), ('ab一er'); +--error ER_DUP_ENTRY +create unique index func_idx1 on t9 ((substr(c1, 2, 2))); +create unique index func_idx2 on t9 ((substr(c1, 2, 4))); +alter table t9 add unique key func_idx3(c1(4)); +--error ER_DUP_ENTRY +create unique index func_idx4 on t9 ((substr(upper(c1), 2, 2))); +drop table t9; + +create table t10 (c1 text); +insert into t10 values ('ab一二'), ('ab一er'); +--error ER_DUP_ENTRY +create unique index func_idx1 on t10 ((substr(c1, 2, 2))); +create unique index func_idx2 on t10 ((substr(c1, 2, 4))); +alter table t10 add unique key func_idx3(c1(4)); +drop table t10; + +create table t11 (c1 varchar(20)) default charset = binary; +insert into t11 values ('ab一二'), ('ab一er'); +--error ER_DUP_ENTRY +create unique index func_idx1 on t11 ((substr(c1, 2, 2))); +--error ER_DUP_ENTRY +create unique index func_idx2 on t11 ((substr(c1, 2, 4))); +--error ER_DUP_ENTRY +alter table t11 add unique key func_idx3(c1(4)); +drop table t11; + +create table t12 (c1 text) default charset = binary; +insert into t12 values ('ab一二'), ('ab一er'); +--error ER_DUP_ENTRY +create unique index func_idx1 on t12 ((substr(c1, 2, 2))); +--error ER_DUP_ENTRY +create unique index func_idx2 on t12 ((substr(c1, 2, 4))); +--error ER_DUP_ENTRY +alter table t12 add unique key func_idx3(c1(4)); +drop table t12; + drop database db1; diff --git a/storage/ctc/ha_ctc_ddl.cc b/storage/ctc/ha_ctc_ddl.cc index 56d952f3729d3519efaf07ec87c2bc550d41bdb5..aa0c232e85d69127df440740817270e86a9cc6ad 100644 --- a/storage/ctc/ha_ctc_ddl.cc +++ b/storage/ctc/ha_ctc_ddl.cc @@ -1228,8 +1228,7 @@ static int ctc_ddl_create_table_fill_foreign_key_info(TcDb__CtcDDLCreateTableDef static void ctc_fill_prefix_func_key_part(TcDb__CtcDDLTableKeyPart *req_key_part, const Field *field, uint16 prefix_len) { req_key_part->is_func = true; - if (field->real_type() == MYSQL_TYPE_BLOB && field->charset() == &my_charset_bin && - field->is_flag_set(BINARY_FLAG)) { + if (field->charset() == &my_charset_bin && field->is_flag_set(BINARY_FLAG)) { req_key_part->func_name = const_cast("substrb"); snprintf(req_key_part->func_text, FUNC_TEXT_MAX_LEN - 1, "substrb(%s,1,%d)", field->field_name, prefix_len); @@ -1412,7 +1411,11 @@ static void ctc_print_op(TABLE *form, const THD *thd, Item_func *item_func, Stri static void ctc_print_func(TABLE *form, const THD *thd, Item_func *item_func, String *out) { - out->append(item_func->func_name()); + if (item_func->collation.collation == &my_charset_bin && strcmp(item_func->func_name(), "substr") == 0) { + out->append("substrb"); + } else { + out->append(item_func->func_name()); + } out->append('('); for (uint i = 0; i < item_func->arg_count; i++) { if (i != 0) out->append(',');