テーブル名の取得方法
MySQL内部でテーブル名を取得するにはどうしたらいいのでしょう・・・? JavaEEで言うところのApplication Contextみたいなのってどうなってるのかな。
JOIN::prepareの時点で既にTABLE_LISTを持っているので、それより前の段階でテーブルを探してきてるはず。しかしソースをちょっとずつ見ていくのメンドクサイ。
で、いいこと思い付いたw readelfでおk
mir@t43:~/tritonn/show/install/bin$ readelf -s mysqld | grep OBJECT | grep GLOBAL | grep table
16: 084ff7e0 16 OBJECT GLOBAL DEFAULT 23 updatable_views_with_limi
159: 085fc1f4 4 OBJECT GLOBAL DEFAULT 24 lower_case_table_names
371: 085faaf4 4 OBJECT GLOBAL DEFAULT 24 table_alias_charset
439: 084f1244 2 OBJECT GLOBAL DEFAULT 23 internal_table_name
481: 086001f1 1 OBJECT GLOBAL DEFAULT 24 table_rules_on
801: 084fdd40 756 OBJECT GLOBAL DEFAULT 23 schema_tables
966: 085fc208 4 OBJECT GLOBAL DEFAULT 24 dropping_tables
1053: 086006d8 4 OBJECT GLOBAL DEFAULT 24 srv_lower_case_table_name
1682: 084ff7f0 12 OBJECT GLOBAL DEFAULT 23 updatable_views_with_limi
1974: 084ffed0 4 OBJECT GLOBAL DEFAULT 23 myisam_quick_table_bits
2543: 0860020c 20 OBJECT GLOBAL DEFAULT 24 replicate_wild_do_table
2618: 085fa4b0 4 OBJECT GLOBAL DEFAULT 24 unknown_table_name
2875: 08604d44 4 OBJECT GLOBAL DEFAULT 24 table_lock_wait_timeout
2906: 085fc1c8 4 OBJECT GLOBAL DEFAULT 24 table_cache_size
3062: 084fe280 120 OBJECT GLOBAL DEFAULT 23 open_tables_fields_info
3789: 084f8500 32 OBJECT GLOBAL DEFAULT 23 sys_max_tmp_tables
3887: 084f8160 32 OBJECT GLOBAL DEFAULT 23 sys_tmp_table_size
4438: 085fff06 1 OBJECT GLOBAL DEFAULT 24 innobase_file_per_table
5450: 085fc680 32 OBJECT GLOBAL DEFAULT 24 sys_table_cache_size
6605: 084f81c0 32 OBJECT GLOBAL DEFAULT 23 sys_updatable_views_with_
6857: 08600220 52 OBJECT GLOBAL DEFAULT 24 replicate_ignore_table
6995: 084ff000 672 OBJECT GLOBAL DEFAULT 23 tables_fields_info
7029: 08602624 4 OBJECT GLOBAL DEFAULT 24 fil_n_pending_tablespace_
7135: 086001f5 1 OBJECT GLOBAL DEFAULT 24 do_table_inited
7139: 086025cc 4 OBJECT GLOBAL DEFAULT 24 trx_sys_multiple_tablespa
7179: 08600440 412 OBJECT GLOBAL DEFAULT 24 fake_time_zone_tables_lis
7295: 085fc700 28 OBJECT GLOBAL DEFAULT 24 sys_table_type
7555: 086001f4 1 OBJECT GLOBAL DEFAULT 24 ignore_table_inited
8405: 086007c4 4 OBJECT GLOBAL DEFAULT 24 srv_print_innodb_tablespa
8443: 085fc660 32 OBJECT GLOBAL DEFAULT 24 sys_table_lock_wait_timeo
8559: 086001f3 1 OBJECT GLOBAL DEFAULT 24 wild_do_table_inited
9261: 08600260 52 OBJECT GLOBAL DEFAULT 24 replicate_do_table
9340: 084fd5a0 56 OBJECT GLOBAL DEFAULT 23 sys_table_types
9481: 084ffcc8 4 OBJECT GLOBAL DEFAULT 23 srv_lock_table_size
9510: 086007f8 4 OBJECT GLOBAL DEFAULT 24 srv_mysql_table
9515: 084fd560 48 OBJECT GLOBAL DEFAULT 23 sys_table_aliases
10016: 086006f0 4 OBJECT GLOBAL DEFAULT 24 srv_file_per_table
10296: 084f8118 28 OBJECT GLOBAL DEFAULT 23 sys_innodb_table_locks
10602: 084fe300 120 OBJECT GLOBAL DEFAULT 23 table_names_fields_info
10931: 084fe4c0 168 OBJECT GLOBAL DEFAULT 23 table_constraints_fields_
11157: 084ffa60 1 OBJECT GLOBAL DEFAULT 23 mysql_proc_table_exists
11622: 084f8600 32 OBJECT GLOBAL DEFAULT 23 sys_max_heap_table_size
12384: 086007c8 4 OBJECT GLOBAL DEFAULT 24 srv_print_innodb_table_mo
12386: 085fd9d4 4 OBJECT GLOBAL DEFAULT 24 unused_tables
12601: 086001f2 1 OBJECT GLOBAL DEFAULT 24 wild_ignore_table_inited
12604: 085fc1b4 4 OBJECT GLOBAL DEFAULT 24 slave_open_temp_tables
12935: 084fe640 168 OBJECT GLOBAL DEFAULT 23 table_privileges_fields_i
7444: 084ff7e0 16 OBJECT GLOBAL DEFAULT 23 updatable_views_with_limi
7587: 085fc1f4 4 OBJECT GLOBAL DEFAULT 24 lower_case_table_names
7799: 085faaf4 4 OBJECT GLOBAL DEFAULT 24 table_alias_charset
7867: 084f1244 2 OBJECT GLOBAL DEFAULT 23 internal_table_name
7909: 086001f1 1 OBJECT GLOBAL DEFAULT 24 table_rules_on
8229: 084fdd40 756 OBJECT GLOBAL DEFAULT 23 schema_tables
8394: 085fc208 4 OBJECT GLOBAL DEFAULT 24 dropping_tables
8481: 086006d8 4 OBJECT GLOBAL DEFAULT 24 srv_lower_case_table_name
9110: 084ff7f0 12 OBJECT GLOBAL DEFAULT 23 updatable_views_with_limi
9402: 084ffed0 4 OBJECT GLOBAL DEFAULT 23 myisam_quick_table_bits
9971: 0860020c 20 OBJECT GLOBAL DEFAULT 24 replicate_wild_do_table
10046: 085fa4b0 4 OBJECT GLOBAL DEFAULT 24 unknown_table_name
10303: 08604d44 4 OBJECT GLOBAL DEFAULT 24 table_lock_wait_timeout
10334: 085fc1c8 4 OBJECT GLOBAL DEFAULT 24 table_cache_size
10490: 084fe280 120 OBJECT GLOBAL DEFAULT 23 open_tables_fields_info
11217: 084f8500 32 OBJECT GLOBAL DEFAULT 23 sys_max_tmp_tables
11315: 084f8160 32 OBJECT GLOBAL DEFAULT 23 sys_tmp_table_size
11866: 085fff06 1 OBJECT GLOBAL DEFAULT 24 innobase_file_per_table
12878: 085fc680 32 OBJECT GLOBAL DEFAULT 24 sys_table_cache_size
14033: 084f81c0 32 OBJECT GLOBAL DEFAULT 23 sys_updatable_views_with_
14285: 08600220 52 OBJECT GLOBAL DEFAULT 24 replicate_ignore_table
14423: 084ff000 672 OBJECT GLOBAL DEFAULT 23 tables_fields_info
14457: 08602624 4 OBJECT GLOBAL DEFAULT 24 fil_n_pending_tablespace_
14563: 086001f5 1 OBJECT GLOBAL DEFAULT 24 do_table_inited
14567: 086025cc 4 OBJECT GLOBAL DEFAULT 24 trx_sys_multiple_tablespa
14607: 08600440 412 OBJECT GLOBAL DEFAULT 24 fake_time_zone_tables_lis
14723: 085fc700 28 OBJECT GLOBAL DEFAULT 24 sys_table_type
14983: 086001f4 1 OBJECT GLOBAL DEFAULT 24 ignore_table_inited
15833: 086007c4 4 OBJECT GLOBAL DEFAULT 24 srv_print_innodb_tablespa
15871: 085fc660 32 OBJECT GLOBAL DEFAULT 24 sys_table_lock_wait_timeo
15987: 086001f3 1 OBJECT GLOBAL DEFAULT 24 wild_do_table_inited
16689: 08600260 52 OBJECT GLOBAL DEFAULT 24 replicate_do_table
16768: 084fd5a0 56 OBJECT GLOBAL DEFAULT 23 sys_table_types
16909: 084ffcc8 4 OBJECT GLOBAL DEFAULT 23 srv_lock_table_size
16938: 086007f8 4 OBJECT GLOBAL DEFAULT 24 srv_mysql_table
16943: 084fd560 48 OBJECT GLOBAL DEFAULT 23 sys_table_aliases
17444: 086006f0 4 OBJECT GLOBAL DEFAULT 24 srv_file_per_table
17724: 084f8118 28 OBJECT GLOBAL DEFAULT 23 sys_innodb_table_locks
18030: 084fe300 120 OBJECT GLOBAL DEFAULT 23 table_names_fields_info
18359: 084fe4c0 168 OBJECT GLOBAL DEFAULT 23 table_constraints_fields_
18585: 084ffa60 1 OBJECT GLOBAL DEFAULT 23 mysql_proc_table_exists
19050: 084f8600 32 OBJECT GLOBAL DEFAULT 23 sys_max_heap_table_size
19812: 086007c8 4 OBJECT GLOBAL DEFAULT 24 srv_print_innodb_table_mo
19814: 085fd9d4 4 OBJECT GLOBAL DEFAULT 24 unused_tables
20029: 086001f2 1 OBJECT GLOBAL DEFAULT 24 wild_ignore_table_inited
20032: 085fc1b4 4 OBJECT GLOBAL DEFAULT 24 slave_open_temp_tables
20363: 084fe640 168 OBJECT GLOBAL DEFAULT 23 table_privileges_fields_iたぶんこれでmysqldからグローバル変数名を拾って来れている筈。間違えていたら有識者の方、突っ込みお願いします。
で、ここで出てきたシンボル名でさらにetagsとかcscopeとかで探して見たものの、決定打は見付からず。。。(泣
しかしget_all_tablesという当たりっぽい関数が見付かったので、、、地道にいくことにしました。接続時のDB選択で発生する"SHOW TABLES"らしき処理のbacktrace。
#0 get_all_tables (thd=0x8ae91f8, tables=0x8b08878, cond=0x0) at sql_show.cc:2112
#1 0x08291e89 in get_schema_tables_result (join=0x8b08da0) at sql_show.cc:3992
#2 0x08203886 in JOIN::exec (this=0x8b08da0) at sql_select.cc:1421
#3 0x08204d10 in mysql_select (thd=0x8ae91f8, rref_pointer_array=0x8ae95e8, tables=0x8b08878, wild_num=0, fields=@0x8ae954c,
conds=0x0, og_num=0, order=0x0, group=0x0, having=0x0, proc_param=0x0, select_options=2693024256, result=0x8b08d90, unit=0x8ae9298,
select_lex=0x8ae94c0) at sql_select.cc:1988
#4 0x08204fa1 in handle_select (thd=0x8ae91f8, lex=0x8ae9234, result=0x8b08d90, setup_tables_done_option=0) at sql_select.cc:254
#5 0x081abf1e in mysql_execute_command (thd=0x8ae91f8) at sql_parse.cc:2587
#6 0x081b3e9e in mysql_parse (thd=0x8ae91f8, inBuf=0x8b08730 "show tables", length=11) at sql_parse.cc:5878
#7 0x081b47fd in dispatch_command (command=COM_QUERY, thd=0x8ae91f8, packet=0x8b00701 "show tables", packet_length=12)
at sql_parse.cc:1766
#8 0x081b5b29 in do_command (thd=0x8ae91f8) at sql_parse.cc:1550
#9 0x081b5ee7 in handle_one_connection (arg=0x8ae91f8) at sql_parse.cc:1181
#10 0xb7c3a341 in start_thread () from /lib/tls/i686/cmov/libpthread.so.0
#11 0xb7b6a4ee in clone () from /lib/tls/i686/cmov/libc.so.6なるほどね。第3引数は0でもいいけど、やはり第2引数はちゃんと設定済みのポインタをあたえないといかんのね。
というわけで、今日はここで撃沈・・・.
P.S.
寝る前にinternals-listの過去ログを漁ってみたら、よさげなスレッドを発見!
http://lists.mysql.com/internals/34118
とりあえず寝る。