Home > MySQLクライアントからshow tables from information_schema;を発行した際の挙動

MySQLクライアントからshow tables from information_schema;を発行した際の挙動

  • July 18, 2007 12:29 PM
MySQL Bugs: #10783: SHOW TABLES FROM INFORMATION_SCHEMA gives error
このバグについて。

MySQL Lists: internals: bk commit into 5.0 tree (gluh:1.1929) BUG#10018
このページを参考に。

原因は、「大文字、小文字を区別したまま文字列比較していた」ということらしい。

make_db_listまで
#0  make_db_list (thd=0x402c218, files=0xb0499b84, idx_field_vals=0xb0499b94, with_i_schema=0xb0499b93, is_wild_value=false) at sql_show.cc:2031
#1  0x0018736d in get_all_tables (thd=0x402c218, tables=0x4055350, cond=0x0) at sql_show.cc:2198
#2  0x0018ecc1 in get_schema_tables_result (join=0x4055878, executed_place=PROCESSED_BY_JOIN_EXEC) at sql_show.cc:4032
#3  0x000f9b25 in JOIN::exec (this=0x4055878) at sql_select.cc:1658
#4  0x000fb0fd in mysql_select (thd=0x402c218, rref_pointer_array=0x402d1f0, tables=0x4055350, wild_num=0, fields=@0x402d160, conds=0x0, og_num=0, order=0x0, group=0x0, having=0x0, proc_param=0x0, select_options=2693024256, result=0x4055868, unit=0x402ce94, select_lex=0x402d0cc) at sql_select.cc:2231
#5  0x000fb3cd in handle_select (thd=0x402c218, lex=0x402ce30, result=0x4055868, setup_tables_done_option=0) at sql_select.cc:255
#6  0x0009e1cb in mysql_execute_command (thd=0x402c218) at sql_parse.cc:2651
#7  0x000a5ded in mysql_parse (thd=0x402c218, inBuf=0x4055028 "show tables from INFORMATION_SCHEMA", length=35) at sql_parse.cc:6019
#8  0x000a688e in dispatch_command (command=COM_QUERY, thd=0x402c218, packet=0x2d78019 "show tables from INFORMATION_SCHEMA", packet_length=36) at sql_parse.cc:1802
#9  0x000a7db9 in do_command (thd=0x402c218) at sql_parse.cc:1581
#10 0x000a82b1 in handle_one_connection (arg=0x402c218) at sql_parse.cc:1193
#11 0x90024227 in _pthread_body ()
その後
(gdb) s
2032      *with_i_schema= 0;
(gdb)
2033      get_index_field_values(lex, idx_field_vals);
(gdb)
get_index_field_values (lex=0x402ce30, index_field_values=0xb0499b94) at sql_show.cc:1868
1868      const char *wild= lex->wild ? lex->wild->ptr() : NullS;
(gdb)
1869      switch (lex->orig_sql_command) {
(gdb)
1876        index_field_values->db_value= lex->select_lex.db;
(gdb)
1877        index_field_values->table_value= wild;
(gdb)
1878        break;
(gdb)
1884    }
(gdb)
make_db_list (thd=0x402c218, files=0xb0499b84, idx_field_vals=0xb0499b94, with_i_schema=0xb0499b93, is_wild_value=false) at sql_show.cc:2034
2034      if (is_wild_value)
(gdb)
2060      if (lex->orig_sql_command != SQLCOM_END)
(gdb)
2062        if (!my_strcasecmp(system_charset_info, INFORMATION_SCHEMA_NAME.str,
(gdb)
my_strcasecmp_utf8 (cs=0x5577a0, s=0x3a7624 "information_schema", t=0x4055098 "information_schema") at ctype-utf8.c:2471
2471      MY_UNICASE_INFO **uni_plane= cs->caseinfo;


make_db_listの中で、my_strcasecmpが呼ばれている。

if (!my_strcasecmp(system_charset_info, INFORMATION_SCHEMA_NAME.str,
                       idx_field_vals->db_value))
idx_field_vals->db_valueにはshow tables from ...で指定したinformation_schema,またはINFORMATION_SCHEMAという文字列が入っている。

/include/m_ctype.h

#define my_strcasecmp(s, a, b)        ((s)->coll->strcasecmp((s), (a), (b)))

((s)->coll->strcasecmp((s), (a), (b)))がよく分からない!!!
→単純に、sオブジェクトのメンバcoll、そのまたメンバのstrcasecmpへ値を入れているらしい

collはMY_COLLATION_HANDLERのポインター?(/include/m_ctype.h)
使っているCharacter Setに応じて、my_strcasecmp_xxxが呼ばれるらしい。
→ここがよく分からない!!!

my_strcasecmp_utf8では比較する文字列を全て小文字に変換している
/strings/ctype-utf8.c

int my_strcasecmp_utf8(CHARSET_INFO *cs, const char *s, const char *t)
{
  MY_UNICASE_INFO **uni_plane= cs->caseinfo;
  while (s[0] && t[0])
  {
    my_wc_t s_wc,t_wc;

    if ((uchar) s[0] < 128)
    {
     /*      s[0] is between 0 and 127.   
             It represents a single byte character.                           
             Convert it into weight according to collation.
     */
      s_wc= plane00[(uchar) s[0]].tolower;
      s++;
    }
.....
ということで、最近のバージョンでは無事になおっているらしい。

関連エントリー

Home > MySQLクライアントからshow tables from information_schema;を発行した際の挙動

Search
Feeds

Return to page top