diff --git a/mysql-test/enableCases.list b/mysql-test/enableCases.list index c76deb709ac4bbf40e1c442c6895f6223b1c69f9..54b8b11819678945e8f72a0001c43575820b487e 100644 --- a/mysql-test/enableCases.list +++ b/mysql-test/enableCases.list @@ -13,6 +13,8 @@ tianchi.ctc_read_only subselect.test #test_services ctc_datetime_analyze +ctc_enum_analyze +ctc_set_analyze # ------ END TEST CASES OF DML ------ # ------ TEST CASES FROM suite/engines/funcs ------ diff --git a/mysql-test/suite/tianchi/r/ctc_enum_analyze.result b/mysql-test/suite/tianchi/r/ctc_enum_analyze.result new file mode 100644 index 0000000000000000000000000000000000000000..574ae0a3973a52f092b1773dc1c49fa271c138b2 --- /dev/null +++ b/mysql-test/suite/tianchi/r/ctc_enum_analyze.result @@ -0,0 +1,40 @@ +drop table if exists tbl_enum; +create table tbl_enum (a enum('参天插件','参天引擎','参天插件&参天引擎'), index idx_a(a)); +insert into tbl_enum values ('参天插件'); +insert into tbl_enum values ('参天插件'); +insert into tbl_enum values ('参天插件'); +insert into tbl_enum values ('参天插件'); +insert into tbl_enum values ('参天插件'); +insert into tbl_enum values ('参天引擎'); +insert into tbl_enum values ('参天引擎'); +insert into tbl_enum values ('参天引擎'); +insert into tbl_enum values ('参天插件&参天引擎'); +insert into tbl_enum values ('参天插件&参天引擎'); +insert into tbl_enum values ('参天插件&参天引擎'); +insert into tbl_enum values ('参天插件&参天引擎'); +insert into tbl_enum values ('参天插件&参天引擎'); +insert into tbl_enum values ('参天插件&参天引擎'); +insert into tbl_enum values ('参天插件&参天引擎'); +insert into tbl_enum values ('参天插件&参天引擎'); +analyze table tbl_enum; +Table Op Msg_type Msg_text +test.tbl_enum analyze status OK +analyze table tbl_enum; +Table Op Msg_type Msg_text +test.tbl_enum analyze status OK +explain select * from tbl_enum where a = '参天插件'; +id select_type table partitions type possible_keys key key_len ref rows filtered Extra +1 SIMPLE tbl_enum NULL ref idx_a idx_a 2 const 1 100.00 Using where; Using index +Warnings: +Note 1003 /* select#1 */ select `test`.`tbl_enum`.`a` AS `a` from `test`.`tbl_enum` where (`test`.`tbl_enum`.`a` = '参天插件') +explain select * from tbl_enum where a = '参天引擎'; +id select_type table partitions type possible_keys key key_len ref rows filtered Extra +1 SIMPLE tbl_enum NULL ref idx_a idx_a 2 const 1 100.00 Using where; Using index +Warnings: +Note 1003 /* select#1 */ select `test`.`tbl_enum`.`a` AS `a` from `test`.`tbl_enum` where (`test`.`tbl_enum`.`a` = '参天引擎') +explain select * from tbl_enum where a = '参天插件&参天引擎'; +id select_type table partitions type possible_keys key key_len ref rows filtered Extra +1 SIMPLE tbl_enum NULL ref idx_a idx_a 2 const 1 100.00 Using where; Using index +Warnings: +Note 1003 /* select#1 */ select `test`.`tbl_enum`.`a` AS `a` from `test`.`tbl_enum` where (`test`.`tbl_enum`.`a` = '参天插件&参天引擎') +drop table tbl_enum; diff --git a/mysql-test/suite/tianchi/r/ctc_set_analyze.result b/mysql-test/suite/tianchi/r/ctc_set_analyze.result new file mode 100644 index 0000000000000000000000000000000000000000..a03785224da28ad140fb7f5489a9da535ff6e2f0 --- /dev/null +++ b/mysql-test/suite/tianchi/r/ctc_set_analyze.result @@ -0,0 +1,40 @@ +drop table if exists tbl_set; +create table tbl_set (a set('CanTian','Gauss100','MySQL'), index idx_a(a)); +insert into tbl_set values ('CanTian'); +insert into tbl_set values ('Gauss100'); +insert into tbl_set values ('MySQL'); +insert into tbl_set values ('CanTian,Gauss100'); +insert into tbl_set values ('CanTian,Gauss100'); +insert into tbl_set values ('CanTian,Gauss100,MySQL'); +insert into tbl_set values ('CanTian,Gauss100,MySQL'); +insert into tbl_set values ('CanTian,Gauss100,MySQL'); +insert into tbl_set values ('CanTian,Gauss100,MySQL'); +insert into tbl_set values ('CanTian,Gauss100,MySQL'); +insert into tbl_set values ('CanTian,Gauss100,MySQL'); +insert into tbl_set values ('CanTian,Gauss100,MySQL'); +insert into tbl_set values ('CanTian,Gauss100,MySQL'); +insert into tbl_set values ('Gauss100,MySQL'); +insert into tbl_set values ('Gauss100,MySQL'); +insert into tbl_set values ('Gauss100,MySQL'); +analyze table tbl_set; +Table Op Msg_type Msg_text +test.tbl_set analyze status OK +analyze table tbl_set; +Table Op Msg_type Msg_text +test.tbl_set analyze status OK +explain select * from tbl_set where a = 'CanTian,Gauss100,MySQL'; +id select_type table partitions type possible_keys key key_len ref rows filtered Extra +1 SIMPLE tbl_set NULL ref idx_a idx_a 2 const 1 100.00 Using where; Using index +Warnings: +Note 1003 /* select#1 */ select `test`.`tbl_set`.`a` AS `a` from `test`.`tbl_set` where (`test`.`tbl_set`.`a` = 'CanTian,Gauss100,MySQL') +explain select * from tbl_set where a = 'CanTian,Gauss100'; +id select_type table partitions type possible_keys key key_len ref rows filtered Extra +1 SIMPLE tbl_set NULL ref idx_a idx_a 2 const 1 100.00 Using where; Using index +Warnings: +Note 1003 /* select#1 */ select `test`.`tbl_set`.`a` AS `a` from `test`.`tbl_set` where (`test`.`tbl_set`.`a` = 'CanTian,Gauss100') +explain select * from tbl_set where a = 'Gauss100,MySQL'; +id select_type table partitions type possible_keys key key_len ref rows filtered Extra +1 SIMPLE tbl_set NULL ref idx_a idx_a 2 const 1 100.00 Using where; Using index +Warnings: +Note 1003 /* select#1 */ select `test`.`tbl_set`.`a` AS `a` from `test`.`tbl_set` where (`test`.`tbl_set`.`a` = 'Gauss100,MySQL') +drop table tbl_set; diff --git a/mysql-test/suite/tianchi/t/ctc_enum_analyze.test b/mysql-test/suite/tianchi/t/ctc_enum_analyze.test new file mode 100644 index 0000000000000000000000000000000000000000..c4efadfa9b768c837e0f1b63d68190c35d5dc13a --- /dev/null +++ b/mysql-test/suite/tianchi/t/ctc_enum_analyze.test @@ -0,0 +1,45 @@ +--disable_warnings +drop table if exists tbl_enum; +--enable_warnings + +create table tbl_enum (a enum('参天插件','参天引擎','参天插件&参天引擎'), index idx_a(a)); +insert into tbl_enum values ('参天插件'); +insert into tbl_enum values ('参天插件'); +insert into tbl_enum values ('参天插件'); +insert into tbl_enum values ('参天插件'); +insert into tbl_enum values ('参天插件'); +insert into tbl_enum values ('参天引擎'); +insert into tbl_enum values ('参天引擎'); +insert into tbl_enum values ('参天引擎'); +insert into tbl_enum values ('参天插件&参天引擎'); +insert into tbl_enum values ('参天插件&参天引擎'); +insert into tbl_enum values ('参天插件&参天引擎'); +insert into tbl_enum values ('参天插件&参天引擎'); +insert into tbl_enum values ('参天插件&参天引擎'); +insert into tbl_enum values ('参天插件&参天引擎'); +insert into tbl_enum values ('参天插件&参天引擎'); +insert into tbl_enum values ('参天插件&参天引擎'); +analyze table tbl_enum; +drop table tbl_enum; +create table tbl_enum (a enum('参天插件','参天引擎','参天插件&参天引擎'), index idx_a(a)); +insert into tbl_enum values ('参天插件'); +insert into tbl_enum values ('参天插件'); +insert into tbl_enum values ('参天插件'); +insert into tbl_enum values ('参天插件'); +insert into tbl_enum values ('参天插件'); +insert into tbl_enum values ('参天引擎'); +insert into tbl_enum values ('参天引擎'); +insert into tbl_enum values ('参天引擎'); +insert into tbl_enum values ('参天插件&参天引擎'); +insert into tbl_enum values ('参天插件&参天引擎'); +insert into tbl_enum values ('参天插件&参天引擎'); +insert into tbl_enum values ('参天插件&参天引擎'); +insert into tbl_enum values ('参天插件&参天引擎'); +insert into tbl_enum values ('参天插件&参天引擎'); +insert into tbl_enum values ('参天插件&参天引擎'); +insert into tbl_enum values ('参天插件&参天引擎'); +analyze table tbl_enum; +explain select * from tbl_enum where a = '参天插件'; +explain select * from tbl_enum where a = '参天引擎'; +explain select * from tbl_enum where a = '参天插件&参天引擎'; +drop table tbl_enum; \ No newline at end of file diff --git a/mysql-test/suite/tianchi/t/ctc_set_analyze.test b/mysql-test/suite/tianchi/t/ctc_set_analyze.test new file mode 100644 index 0000000000000000000000000000000000000000..c467f804837d4aaeec175958bd855f7a36a8439f --- /dev/null +++ b/mysql-test/suite/tianchi/t/ctc_set_analyze.test @@ -0,0 +1,45 @@ +--disable_warnings +drop table if exists tbl_set; +--enable_warnings + +create table tbl_set (a set('CanTian','Gauss100','MySQL'), index idx_a(a)); +insert into tbl_set values ('CanTian'); +insert into tbl_set values ('Gauss100'); +insert into tbl_set values ('MySQL'); +insert into tbl_set values ('CanTian,Gauss100'); +insert into tbl_set values ('CanTian,Gauss100'); +insert into tbl_set values ('CanTian,Gauss100,MySQL'); +insert into tbl_set values ('CanTian,Gauss100,MySQL'); +insert into tbl_set values ('CanTian,Gauss100,MySQL'); +insert into tbl_set values ('CanTian,Gauss100,MySQL'); +insert into tbl_set values ('CanTian,Gauss100,MySQL'); +insert into tbl_set values ('CanTian,Gauss100,MySQL'); +insert into tbl_set values ('CanTian,Gauss100,MySQL'); +insert into tbl_set values ('CanTian,Gauss100,MySQL'); +insert into tbl_set values ('Gauss100,MySQL'); +insert into tbl_set values ('Gauss100,MySQL'); +insert into tbl_set values ('Gauss100,MySQL'); +analyze table tbl_set; +drop table tbl_set; +create table tbl_set (a set('CanTian','Gauss100','MySQL'), index idx_a(a)); +insert into tbl_set values ('CanTian'); +insert into tbl_set values ('Gauss100'); +insert into tbl_set values ('MySQL'); +insert into tbl_set values ('CanTian,Gauss100'); +insert into tbl_set values ('CanTian,Gauss100'); +insert into tbl_set values ('CanTian,Gauss100,MySQL'); +insert into tbl_set values ('CanTian,Gauss100,MySQL'); +insert into tbl_set values ('CanTian,Gauss100,MySQL'); +insert into tbl_set values ('CanTian,Gauss100,MySQL'); +insert into tbl_set values ('CanTian,Gauss100,MySQL'); +insert into tbl_set values ('CanTian,Gauss100,MySQL'); +insert into tbl_set values ('CanTian,Gauss100,MySQL'); +insert into tbl_set values ('CanTian,Gauss100,MySQL'); +insert into tbl_set values ('Gauss100,MySQL'); +insert into tbl_set values ('Gauss100,MySQL'); +insert into tbl_set values ('Gauss100,MySQL'); +analyze table tbl_set; +explain select * from tbl_set where a = 'CanTian,Gauss100,MySQL'; +explain select * from tbl_set where a = 'CanTian,Gauss100'; +explain select * from tbl_set where a = 'Gauss100,MySQL'; +drop table tbl_set; diff --git a/storage/tianchi/tse_cbo.cc b/storage/tianchi/tse_cbo.cc index c378e6dfbcd78378ca9f130cf29d80268469976e..31c39c903df61756f5f25a067d4ddc318c35f71a 100644 --- a/storage/tianchi/tse_cbo.cc +++ b/storage/tianchi/tse_cbo.cc @@ -45,6 +45,17 @@ void r_key2variant(tse_key *rKey, KEY_PART_INFO *cur_index_part, cache_variant_t uchar tmp_ptr[TSE_BYTE_8] = {0}; const field_cnvrt_aux_t *mysql_info = get_auxiliary_for_field_convert(field, field->type()); switch(field->real_type()) { + case MYSQL_TYPE_SET: + case MYSQL_TYPE_ENUM: + if (field->pack_length() <= 4) { + ret_val->v_int = *(int32_t *)const_cast(key); + } else { + ret_val->v_bigint = *(int64_t *)const_cast(key); + } + break; + case MYSQL_TYPE_BIT: + ret_val->v_ubigint = bit_cnvt_mysql_cantian(key, field); + break; case MYSQL_TYPE_TINY: case MYSQL_TYPE_SHORT: case MYSQL_TYPE_LONG: @@ -468,6 +479,13 @@ double calc_density_by_cond(tse_cbo_stats_table_t *cbo_stats, KEY_PART_INFO cur_ r_key2variant(min_key, &cur_index_part, &min_key_val, low_val, key_offset); r_key2variant(max_key, &cur_index_part, &max_key_val, high_val, key_offset); enum_field_types field_type = cur_index_part.field->real_type(); + if (field_type == MYSQL_TYPE_ENUM || field_type == MYSQL_TYPE_SET) { + if (cur_index_part.field->pack_length() <= 4) { + field_type = MYSQL_TYPE_LONG; + } else { + field_type = MYSQL_TYPE_LONGLONG; + } + } if (compare(&max_key_val, low_val, field_type) == LESS || compare(&min_key_val, high_val, field_type) == GREAT) { return 0; }