forked from facebook/mysql-5.6
-
Notifications
You must be signed in to change notification settings - Fork 0
collate rocksdb_strict_collation_check
zhangyuan edited this page Aug 27, 2018
·
2 revisions
myrocks::Rdb_field_packing::setup
字符转分三种
1 在utf8_bin, binary, latin_bin等可以直接转换
2 rdb_init_collation_mapping 有些可以从memcompareable format转换为原格式,需在value中增加unpack_info (例如latin1_general_ci, 参考rdb_is_collation_supported)
3 rdb_init_collation_mapping不能转换的,需从主键中读取此值 (例如utf8_general_ci)
myrocks::Rdb_field_packing::setup
#0 myrocks::Rdb_field_packing::setup (this=0x7fffb0427c60, key_descr=0x0, field=0x7fff6c008e60, keynr_arg=@0x7fffb0427c54, key_part_arg=@0x7fffb0427c50,
key_length=@0x7fff6c008dc8) at /home/zhangyuan.zy/git/git6/storage/rocksdb/rdb_datadic.cc:3040
#1 0x00000000015d921b in myrocks::ha_rocksdb::check_keyread_allowed (this=0x7fff6c00ea50, inx=0, part=0, all_parts=true)
at /home/zhangyuan.zy/git/git6/storage/rocksdb/ha_rocksdb.cc:7202
#2 0x00000000015db204 in myrocks::ha_rocksdb::index_flags (this=0x7fff6c00ea50, inx=0, part=0, all_parts=true) at /home/zhangyuan.zy/git/git6/storage/rocksdb/ha_rocksdb.cc:7590
#3 0x00000000011061e6 in setup_key_part_field (share=0x7fff6c00e3d0, handler_file=0x7fff6c00ea50, primary_key_n=0, keyinfo=0x7fff6c008d30, key_n=0, key_part_n=0,
usable_parts=0x7fffb0427ffc) at /home/zhangyuan.zy/git/git6/sql/table.cc:1009
#4 0x000000000110b2ba in open_binary_frm (thd=0x54f23c0, share=0x7fff6c00e3d0, head=0x7fffb04282b0 "\376\001\n\035\003", file=21)
at /home/zhangyuan.zy/git/git6/sql/table.cc:2072
#5 0x000000000110560d in open_table_def (thd=0x54f23c0, share=0x7fff6c00e3d0, db_flags=8192) at /home/zhangyuan.zy/git/git6/sql/table.cc:873
#6 0x0000000000e826d7 in get_table_share (thd=0x54f23c0, table_list=0x7fff6c005118, key=0x7fff6c0054f5 "test", key_length=8, db_flags=8192, error=0x7fffb04288b4,
hash_value=1096967734) at /home/zhangyuan.zy/git/git6/sql/sql_base.cc:512
#7 0x0000000000e82f1d in get_table_share_with_discover (thd=0x54f23c0, table_list=0x7fff6c005118, key=0x7fff6c0054f5 "test", key_length=8, db_flags=8192, error=0x7fffb04288b4,
hash_value=1096967734) at /home/zhangyuan.zy/git/git6/sql/sql_base.cc:591
#8 0x0000000000e8d4ec in open_table (thd=0x54f23c0, table_list=0x7fff6c005118, ot_ctx=0x7fffb0428a80) at /home/zhangyuan.zy/git/git6/sql/sql_base.cc:3045
#9 0x0000000000e93968 in open_and_process_table (thd=0x54f23c0, lex=0x54f4d90, tables=0x7fff6c005118, counter=0x54f4e40, flags=0, prelocking_strategy=0x7fffb0428b80,
has_prelocking_list=false, ot_ctx=0x7fffb0428a80) at /home/zhangyuan.zy/git/git6/sql/sql_base.cc:4730
#10 0x0000000000e954bf in open_tables (thd=0x54f23c0, start=0x7fffb0428b40, counter=0x54f4e40, flags=0, prelocking_strategy=0x7fffb0428b80)
at /home/zhangyuan.zy/git/git6/sql/sql_base.cc:5184
#11 0x0000000000e977bb in open_normal_and_derived_tables (thd=0x54f23c0, tables=0x7fff6c005118, flags=0) at /home/zhangyuan.zy/git/git6/sql/sql_base.cc:5888
#12 0x0000000000f36930 in mysql_insert (thd=0x54f23c0, table_list=0x7fff6c005118, fields=..., values_list=..., update_fields=..., update_values=..., duplic=DUP_ERROR,
ignore=false) at /home/zhangyuan.zy/git/git6/sql/sql_insert.cc:754
#13 0x0000000000f7c8ef in mysql_execute_command (thd=0x54f23c0) at /home/zhangyuan.zy/git/git6/sql/sql_parse.cc:4274
#14 0x0000000000f8eec8 in mysql_parse (thd=0x54f23c0, rawbuf=0x7fff6c005030 "insert into t1 values('ef')", length=27, parser_state=0x7fffb042a1d0,
async_commit=0x7fffb042a91f "") at /home/zhangyuan.zy/git/git6/sql/sql_parse.cc:7444
#15 0x0000000000f6f15e in dispatch_command (command=COM_QUERY, thd=0x54f23c0, packet=0x54f9631 "insert into t1 values('ef')", packet_length=27)
at /home/zhangyuan.zy/git/git6/sql/sql_parse.cc:1665
#16 0x0000000000f6c2a4 in do_command (thd=0x54f23c0) at /home/zhangyuan.zy/git/git6/sql/sql_parse.cc:1149
#17 0x0000000000ef7924 in do_handle_one_connection (thd_arg=0x54f23c0) at /home/zhangyuan.zy/git/git6/sql/sql_connect.cc:1023
#18 0x0000000000ef6ff9 in handle_one_connection (arg=0x54f23c0) at /home/zhangyuan.zy/git/git6/sql/sql_connect.cc:939
#19 0x00000000027e38b5 in pfs_spawn_thread (arg=0x548b500) at /home/zhangyuan.zy/git/git6/storage/perfschema/pfs.cc:1858
#20 0x00007ffff77c2851 in start_thread () from /lib64/libpthread.so.0
#21 0x0000003330ce767d in clone () from /lib64/libc.so.6
set global rocksdb_strict_collation_check=on;
create table t1(c1 int primary key, c2 varchar(10) unique) engine =rocksdb character set utf8 collate utf8_bin;
insert into t1 values(1,'ab');
insert into t1 values(2,'cd');
explain select c2 from t1 where c2='ab';
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 const c2 c2 33 const 1 Using index
explain select c2 from t1 force index(c2) where c2='ab';
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 const c2 c2 33 const 1 Using index
select c2 from t1;
c2
ab
cd
select c2 from t1 where c2='ab';
c2
ab
select c2 from t1 force index(c2) where c2='ab';
c2
ab
drop table t1;
create table t1(c1 int primary key, c2 varchar(10) unique) engine =rocksdb character set utf8 collate utf8_general_ci;
ERROR HY000: Unsupported collation on string indexed column test.t1.c2 Use binary collation (binary, latin1_bin, utf8_bin, utf8mb4_bin).
set global rocksdb_strict_collation_check=off;
create table t1(c1 int primary key, c2 varchar(10) unique) engine =rocksdb character set utf8 collate utf8_general_ci;
insert into t1 values(3,'ef');
insert into t1 values(4,'jh');
//utf8_general_ci memcomparable format不能转化为原值,没有using index
explain select c2 from t1 where c2='ef';
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 const c2 c2 33 const 1 NULL
explain select c2 from t1 force index(c2) where c2='ef';
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 const c2 c2 33 const 1 NULL
select c2 from t1;
c2
ef
jh
select c2 from t1 where c2='ef';
c2
ef
select c2 from t1 force index(c2) where c2='ef';
c2
ef
drop table t1;
//没有走myrocks::ha_rocksdb::secondary_index_read, 而是read_row_from_secondary_key, 从二级索引读出PK, 再根据pk查找
#0 myrocks::ha_rocksdb::convert_record_from_storage_format (this=0x7fff6c012520, key=0x7fffb0418ec0, buf=0x7fff6c00f0d0 "\376")
at /home/zhangyuan.zy/git/git6/storage/rocksdb/ha_rocksdb.cc:5612
#1 0x00000000015e026f in myrocks::ha_rocksdb::get_row_by_rowid (this=0x7fff6c012520, buf=0x7fff6c00f0d0 "\376", rowid=0x7fff6c010d30 "", rowid_size=8, skip_lookup=false,
skip_ttl_check=true) at /home/zhangyuan.zy/git/git6/storage/rocksdb/ha_rocksdb.cc:8323
#2 0x00000000016106cf in myrocks::ha_rocksdb::get_row_by_rowid (this=0x7fff6c012520, buf=0x7fff6c00f0d0 "\376", rowid=0x7fff6c010d30 "", rowid_size=8, skip_lookup=false,
skip_ttl_check=true) at /home/zhangyuan.zy/git/git6/storage/rocksdb/./ha_rocksdb.h:660
#3 0x00000000015db105 in myrocks::ha_rocksdb::read_row_from_secondary_key (this=0x7fff6c012520, buf=0x7fff6c00f0d0 "\376", kd=..., move_forward=true)
at /home/zhangyuan.zy/git/git6/storage/rocksdb/ha_rocksdb.cc:7550
#4 0x00000000015dcdb8 in myrocks::ha_rocksdb::index_read_map_impl (this=0x7fff6c012520, buf=0x7fff6c00f0d0 "\376", key=0x7fff6c006a08 "", keypart_map=1,
find_flag=HA_READ_KEY_EXACT, end_key=0x0) at /home/zhangyuan.zy/git/git6/storage/rocksdb/ha_rocksdb.cc:7898
#5 0x00000000015dc100 in myrocks::ha_rocksdb::index_read_map (this=0x7fff6c012520, buf=0x7fff6c00f0d0 "\376", key=0x7fff6c006a08 "", keypart_map=1, find_flag=HA_READ_KEY_EXACT)
at /home/zhangyuan.zy/git/git6/storage/rocksdb/ha_rocksdb.cc:7739
#6 0x0000000000c4c505 in handler::index_read_idx_map (this=0x7fff6c012520, buf=0x7fff6c00f0d0 "\376", index=1, key=0x7fff6c006a08 "", keypart_map=1,
find_flag=HA_READ_KEY_EXACT) at /home/zhangyuan.zy/git/git6/sql/handler.cc:7330
#7 0x0000000000c3b93a in handler::ha_index_read_idx_map (this=0x7fff6c012520, buf=0x7fff6c00f0d0 "\376", index=1, key=0x7fff6c006a08 "", keypart_map=1,
find_flag=HA_READ_KEY_EXACT) at /home/zhangyuan.zy/git/git6/sql/handler.cc:3136
#8 0x0000000000f15368 in join_read_const (tab=0x7fff6c0061a0) at /home/zhangyuan.zy/git/git6/sql/sql_executor.cc:1975
#9 0x0000000000f14a8c in join_read_const_table (tab=0x7fff6c0061a0, pos=0x7fff6c006690) at /home/zhangyuan.zy/git/git6/sql/sql_executor.cc:1864
#10 0x0000000001345a77 in make_join_statistics (join=0x7fff6c005bf0, tables_arg=0x7fff6c005240, conds=0x7fff6c005990, keyuse_array=0x7fff6c005e18, first_optimization=true)
at /home/zhangyuan.zy/git/git6/sql/sql_optimizer.cc:3592
#11 0x0000000001335605 in JOIN::optimize (this=0x7fff6c005bf0) at /home/zhangyuan.zy/git/git6/sql/sql_optimizer.cc:364
#12 0x0000000000fdcdb2 in mysql_execute_select (thd=0x54e2440, select_lex=0x54e5538, free_join=true) at /home/zhangyuan.zy/git/git6/sql/sql_select.cc:1116
#13 0x0000000000fdd5f5 in mysql_select (thd=0x54e2440, tables=0x7fff6c005240, wild_num=0, fields=..., conds=0x7fff6c005990, order=0x54e5708, group=0x54e5640, having=0x0,
select_options=2147748608, result=0x7fff6c005bc8, unit=0x54e4ed0, select_lex=0x54e5538) at /home/zhangyuan.zy/git/git6/sql/sql_select.cc:1257
#14 0x0000000000fd9552 in handle_select (thd=0x54e2440, result=0x7fff6c005bc8, setup_tables_done_option=0) at /home/zhangyuan.zy/git/git6/sql/sql_select.cc:127
#15 0x0000000000f8909b in execute_sqlcom_select (thd=0x54e2440, all_tables=0x7fff6c005240) at /home/zhangyuan.zy/git/git6/sql/sql_parse.cc:6144
#16 0x0000000000f779f3 in mysql_execute_command (thd=0x54e2440) at /home/zhangyuan.zy/git/git6/sql/sql_parse.cc:3364
#17 0x0000000000f8eec8 in mysql_parse (thd=0x54e2440, rawbuf=0x7fff6c005030 "select c2 from t1 where c2='ef'", length=31, parser_state=0x7fffb041b1d0,
async_commit=0x7fffb041b91f "") at /home/zhangyuan.zy/git/git6/sql/sql_parse.cc:7444
#18 0x0000000000f6f15e in dispatch_command (command=COM_QUERY, thd=0x54e2440, packet=0x54e96b1 "select c2 from t1 where c2='ef'", packet_length=31)
at /home/zhangyuan.zy/git/git6/sql/sql_parse.cc:1665
#19 0x0000000000f6c2a4 in do_command (thd=0x54e2440) at /home/zhangyuan.zy/git/git6/sql/sql_parse.cc:1149
#20 0x0000000000ef7924 in do_handle_one_connection (thd_arg=0x54e2440) at /home/zhangyuan.zy/git/git6/sql/sql_connect.cc:1023
#21 0x0000000000ef6ff9 in handle_one_connection (arg=0x54e2440) at /home/zhangyuan.zy/git/git6/sql/sql_connect.cc:939
// latin1_general_ci 通过unpact_info可以转化原值。 所以可以走cover_index
mysql> create table t1(c1 int primary key, c2 varchar(10) unique) engine =rocksdb character set latin1 collate latin1_general_ci;
Query OK, 0 rows affected (0.00 sec)
mysql> insert into t1 values(3,'ef');
Query OK, 1 row affected (0.00 sec)
mysql> explain select c2 from t1 where c2='ef';
+----+-------------+-------+-------+---------------+------+---------+-------+------+-------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+-------+-------+---------------+------+---------+-------+------+-------------+
| 1 | SIMPLE | t1 | const | c2 | c2 | 13 | const | 1 | Using index |
+----+-------------+-------+-------+---------------+------+---------+-------+------+-------------+
1 row in set (0.00 sec)