MySQL源码阅读笔记之代码结构

代码版本:MySQL5.5.28

源代码目录布局:

下面就一些重要的源代码文件夹作一个简单的说明:

BUILD:编译配置并为所有被支持的平台制作文件,内含在各个平台、各种编译器下进行编译和链接的脚本。例如compile-pentium64-debug表示在pentium64架构上进行编译的脚本。

autorun.sh                      compile-pentium-debug-max
build_mccge.sh                  compile-pentium-debug-max-no-embedded
check-cpu                       compile-pentium-debug-max-no-ndb
cleanup                         compile-pentium-debug-openssl
cmake_configure.sh              compile-pentium-debug-yassl
compile-alpha                   compile-pentium-gcov
compile-alpha-debug             compile-pentium-gprof
compile-amd64-debug-max         compile-pentium-icc
compile-amd64-debug-max-no-ndb  compile-pentium-icc-valgrind-max
compile-amd64-gcov              compile-pentium-icc-yassl
compile-amd64-gprof             compile-pentium-max
compile-amd64-max               compile-pentium-myodbc
compile-amd64-max-sci           compile-pentium-pgcc
compile-amd64-valgrind-max      compile-pentium-valgrind-max
compile-darwin-mwcc             compile-pentium-valgrind-max-no-ndb
compile-dist                    compile-ppc
compile-hpux11-parisc2-aCC      compile-ppc-debug
compile-ia64-debug-max          compile-ppc-debug-max
compile-irix-mips64-mipspro     compile-ppc-debug-max-no-ndb
compile-ndb-autotest            compile-ppc-max
compile-pentium                 compile-solaris-amd64
compile-pentium64               compile-solaris-amd64-debug
compile-pentium64-debug         compile-solaris-amd64-forte
compile-pentium64-debug-max     compile-solaris-amd64-forte-debug
compile-pentium64-gcov          compile-solaris-sparc
compile-pentium64-gprof         compile-solaris-sparc-debug
compile-pentium64-max           compile-solaris-sparc-forte
compile-pentium64-max-sci       compile-solaris-sparc-purify
compile-pentium64-valgrind-max  FINISH.sh
compile-pentium-cybozu          SETUP.sh
compile-pentium-debug

mysysMySQL system libraryMySQL的库函数文件

array.c          mf_radix.c      my_getncpus.c        my_static.h
base64.c         mf_same.c       my_getopt.c          my_symlink2.c
ChangeLog        mf_sort.c       my_getpagesize.c     my_symlink.c
charset.c        mf_soundex.c    my_getsystime.c      my_sync.c
charset-def.c    mf_tempdir.c    my_getwd.c           mysys_priv.h
checksum.c       mf_tempfile.c   my_handler_errors.h  my_thr_init.c
CMakeLists.txt   mf_unixpath.c   my_init.c            my_timer_cycles.il
default.c        mf_wcomp.c      my_largepage.c       my_wincond.c
errors.c         mulalloc.c      my_lib.c             my_windac.c
hash.c           my_access.c     my_libwrap.c         my_winerr.c
lf_alloc-pin.c   my_aes.c        my_lock.c            my_winfile.c
lf_dynarray.c    my_alarm.c      my_lockmem.c         my_winthread.c
lf_hash.c        my_alloc.c      my_malloc.c          my_write.c
list.c           my_atomic.c     my_memmem.c          ptr_cmp.c
md5.c            my_bit.c        my_mess.c            queues.c
mf_arr_appstr.c  my_bitmap.c     my_mkdir.c           rijndael.c
mf_cache.c       my_chsize.c     my_mmap.c            sha1.c
mf_dirname.c     my_compare.c    my_new.cc            stacktrace.c
mf_fn_ext.c      my_compress.c   my_once.c            string.c
mf_format.c      my_conio.c      my_open.c            test_charset.c
mf_getdate.c     my_copy.c       my_pread.c           test_dir.c
mf_iocache2.c    my_crc32.c      my_pthread.c         testhash.c
mf_iocache.c     my_create.c     my_quick.c           test_xml.c
mf_keycache.c    my_delete.c     my_rdtsc.c           thr_alarm.c
mf_keycaches.c   my_div.c        my_read.c            thr_lock.c
mf_loadpath.c    my_error.c      my_redel.c           thr_mutex.c
mf_pack.c        my_file.c       my_rename.c          thr_rwlock.c
mf_path.c        my_fopen.c      my_seek.c            tree.c
mf_qsort2.c      my_fstream.c    my_sleep.c           typelib.c
mf_qsort.c       my_gethwaddr.c  my_static.c

stringsstring库,各种字符串处理函数。

bchange.c         ctype-latin1.c     is_prefix.c     string.doc
bmove_upp.c       ctype-mb.c         latin2.def      strmake.c
CHARSET_INFO.txt  ctype-simple.c     llstr.c         strmov.c
CMakeLists.txt    ctype-sjis.c       longlong2str.c  strnlen.c
conf_to_src.c     ctype-tis620.c     my_strchr.c     strnmov.c
ctype-big5.c      ctype-uca.c        my_strtoll10.c  strxmov.c
ctype-bin.c       ctype-ucs2.c       my_vsnprintf.c  strxnmov.c
ctype.c           ctype-ujis.c       README          t_ctype.h
ctype-cp932.c     ctype-utf8.c       str2int.c       uca-dump.c
ctype-czech.c     ctype-win1250ch.c  str_alloc.c     uctypedump.c
ctype-eucjpms.c   decimal.c          strappend.c     utr11-dump.c
ctype-euc_kr.c    do_ctype.c         strcend.c       xml.c
ctype-extra.c     dtoa.c             strcont.c
ctype-gb2312.c    dump_map.c         strend.c
ctype-gbk.c       int2str.c          strfill.c      

packaging打包工具包  

support-filesmy.cnf示例配置文件

binary-configure.sh     magic                      mysql.m4
build-tags              my-huge.cnf.sh             mysql-multi.server.sh
CMakeLists.txt          my-innodb-heavy-4G.cnf.sh  mysql.server.sh
compiler_warnings.supp  my-large.cnf.sh            mysql.server-sys5.sh
config.huge.ini.sh      my-medium.cnf.sh           MySQL-shared-compat.spec.sh
config.medium.ini.sh    my-small.cnf.sh            mysql.spec.sh
config.small.ini.sh     mysql.5.5.28.spec          ndb-config-2-node.ini.sh
dtrace                  mysqld_multi.server.sh     RHEL4-SElinux
MacOSX                  mysql-log-rotate.sh

client:客户端工具,内含mysql,mysqladmin,mysqlshow等常用命令和客户端工具的源代码:    

client_priv.h       my_readline.h   mysqlimport.c    readline.cc
CMakeLists.txt      mysqladmin.cc   mysql_plugin.c   sql_string.cc
completion_hash.cc  mysqlbinlog.cc  mysqlshow.c      sql_string.h
completion_hash.h   mysql.cc        mysqlslap.c
echo.c              mysqlcheck.c    mysqltest.cc
get_password.c      mysqldump.c     mysql_upgrade.c

pluginmysql以插件形式实现的部分工程 

audit_null  auth  daemon_example  fulltext  semisync

tests测试文件所在目录,包含测试文件和测试目录。

auto_increment.res  function.res          mysql_client_fw.c
auto_increment.tst  function.tst          mysql_client_test.c
big_record.pl       grant.pl              pmail.pl
bug25714.c          grant.res             rename_test.pl
CMakeLists.txt      index_corrupt.pl      restore-lock.smack
connect_test.c      insert_and_repair.pl  select_test.c
deadlock_test.c     insert_test.c         showdb_test.c
drop_test.pl        list_test.c           ssl_test.c
export.pl           lock_test.pl          table_types.pl
fork2_test.pl       lock_test.res         test_delayed_insert.pl
fork_big2.pl        mail_to_db.pl         thread_test.c
fork_big.pl         myisam-big-rows.tst   truncate.pl

libmysql:库文件,生产libmysqlclient.so 

authentication_win  conf_to_src.c   libmysql.c
client_settings.h   errmsg.c        libmysql.def
CMakeLists.txt      get_password.c  libmysql.ver.in 

README:说明文档

unittest:单元测试

examples  mysys  mytap  README.txt  strings  unit.pl             

regex正则表达式工具 

cclass.h        debug.c    main.ih     regerror.c   regexec.c  tests
CHANGES         debug.ih   my_regex.h  regerror.ih  regexp.c   utils.h
CMakeLists.txt  engine.c   README      regex2.h     regfree.c  WHATSNEW
cname.h         engine.ih  regcomp.c   regex.3      reginit.c
COPYRIGHT       main.c     regcomp.ih  regex.7      split.c

VERSION:版本信息          

dbug:提供一些调试用的宏定义 

CMakeLists.txt    dbug_long.h  factorial.c  remove_function_from_trace.pl
dbug_add_tags.pl  example1.c   main.c       tests.c
dbug_analyze.c    example2.c   monty.doc    tests-t.pl
dbug.c            example3.c   my_main.c    user.r

libservices:5.5.x中新加的目录,实现了打印功能 

 CMakeLists.txt  my_snprintf_service.c          thd_alloc_service.c
HOWTO           my_thread_scheduler_service.c  thd_wait_service.c

scripts提供脚本工具,如mysql_install_db 

CMakeLists.txt                 mysql_find_rows.sh
comp_sql.c                     mysql_fix_extensions.sh
dheadgen.pl                    mysqlhotcopy.sh
fill_help_tables.sql           mysql_install_db.pl.in
msql2mysql.sh                  mysql_install_db.sh
mysqlaccess.conf               mysql_secure_installation.pl.in
mysqlaccess.sh                 mysql_secure_installation.sh
mysqlbug.sh                    mysql_setpermission.sh
mysql_config.pl.in             mysql_system_tables_data.sql
mysql_config.sh                mysql_system_tables_fix.sql
mysql_convert_table_format.sh  mysql_system_tables.sql
mysqld_multi.sh                mysql_test_data_timezone.sql
mysqld_safe.sh                 mysql_zap.sh
mysqldumpslow.sh 

Docs文档库  

sqlmysql主要代码,将会生成mysqld文件。

add_errmsg               MSG00001.bin         sql_delete.cc
authors.h                my_decimal.cc        sql_delete.h
client_settings.h        my_decimal.h         sql_derived.cc
CMakeLists.txt           mysqld.cc            sql_derived.h
contributors.h           mysqld.h             sql_do.cc
custom_conf.h            mysqld_suffix.h      sql_do.h
datadict.cc              net_serv.cc          sql_error.cc
datadict.h               nt_servc.cc          sql_error.h
debug_sync.cc            nt_servc.h           sql_handler.cc
debug_sync.h             opt_range.cc         sql_handler.h
derror.cc                opt_range.h          sql_help.cc
derror.h                 opt_sum.cc           sql_help.h
des_key_file.cc          parse_file.cc        sql_hset.h
des_key_file.h           parse_file.h         sql_insert.cc
discover.cc              partition_element.h  sql_insert.h
discover.h               partition_info.cc    sql_lex.cc
event_data_objects.cc    partition_info.h     sql_lex.h
event_data_objects.h     password.c           sql_list.cc
event_db_repository.cc   procedure.cc         sql_list.h
event_db_repository.h    procedure.h          sql_load.cc
event_parse_data.cc      protocol.cc          sql_load.h
event_parse_data.h       protocol.h           sql_locale.cc
event_queue.cc           records.cc           sql_locale.h
event_queue.h            records.h            sql_manager.cc
events.cc                repl_failsafe.cc     sql_manager.h
event_scheduler.cc       repl_failsafe.h      sql_parse.cc
event_scheduler.h        replication.h        sql_parse.h
events.h                 rpl_constants.h      sql_partition_admin.cc
examples                 rpl_filter.cc        sql_partition_admin.h
field.cc                 rpl_filter.h         sql_partition.cc
field_conv.cc            rpl_handler.cc       sql_partition.h
field.h                  rpl_handler.h        sql_plist.h
filesort.cc              rpl_injector.cc      sql_plugin.cc
filesort.h               rpl_injector.h       sql_plugin.h
frm_crypt.cc             rpl_mi.cc            sql_plugin_services.h
frm_crypt.h              rpl_mi.h             sql_prepare.cc
gen_lex_hash.cc          rpl_record.cc        sql_prepare.h
gstream.cc               rpl_record.h         sql_priv.h
gstream.h                rpl_record_old.cc    sql_profile.cc
ha_ndbcluster_binlog.cc  rpl_record_old.h     sql_profile.h
ha_ndbcluster_binlog.h   rpl_reporting.cc     sql_reload.cc
ha_ndbcluster.cc         rpl_reporting.h      sql_reload.h
ha_ndbcluster_cond.cc    rpl_rli.cc           sql_rename.cc
ha_ndbcluster_cond.h     rpl_rli.h            sql_rename.h
ha_ndbcluster.h          rpl_tblmap.cc        sql_repl.cc
ha_ndbcluster_tables.h   rpl_tblmap.h         sql_repl.h
handler.cc               rpl_utility.cc       sql_select.cc
handler.h                rpl_utility.h        sql_select.h
ha_partition.cc          scheduler.cc         sql_servers.cc
ha_partition.h           scheduler.h          sql_servers.h
hash_filo.cc             set_var.cc           sql_show.cc
hash_filo.h              set_var.h            sql_show.h
hostname.cc              sha2.cc              sql_signal.cc
hostname.h               share                sql_signal.h
init.cc                  signal_handler.cc    sql_sort.h
init.h                   slave.cc             sql_state.c
item_buff.cc             slave.h              sql_string.cc
item.cc                  spatial.cc           sql_string.h
item_cmpfunc.cc          spatial.h            sql_table.cc
item_cmpfunc.h           sp_cache.cc          sql_table.h
item_create.cc           sp_cache.h           sql_tablespace.cc
item_create.h            sp.cc                sql_tablespace.h
item_func.cc             sp.h                 sql_test.cc
item_func.h              sp_head.cc           sql_test.h
item_geofunc.cc          sp_head.h            sql_time.cc
item_geofunc.h           sp_pcontext.cc       sql_time.h
item.h                   sp_pcontext.h        sql_trigger.cc
item_row.cc              sp_rcontext.cc       sql_trigger.h
item_row.h               sp_rcontext.h        sql_truncate.cc
item_strfunc.cc          sql_acl.cc           sql_truncate.h
item_strfunc.h           sql_acl.h            sql_udf.cc
item_subselect.cc        sql_admin.cc         sql_udf.h
item_subselect.h         sql_admin.h          sql_union.cc
item_sum.cc              sql_alter.cc         sql_union.h
item_sum.h               sql_alter.h          sql_update.cc
item_timefunc.cc         sql_analyse.cc       sql_update.h
item_timefunc.h          sql_analyse.h        sql_view.cc
item_xmlfunc.cc          sql_array.h          sql_view.h
item_xmlfunc.h           sql_audit.cc         sql_yacc.cc
keycaches.cc             sql_audit.h          sql_yacc.h
keycaches.h              sql_base.cc          sql_yacc.yy
key.cc                   sql_base.h           strfunc.cc
key.h                    sql_binlog.cc        strfunc.h
lex.h                    sql_binlog.h         structs.h
lex_symbol.h             sql_bitmap.h         sys_vars.cc
lock.cc                  sql_builtin.cc.in    sys_vars.h
lock.h                   sql_cache.cc         sys_vars_shared.h
log.cc                   sql_cache.h          table.cc
log_event.cc             sql_callback.h       table.h
log_event.h              sql_class.cc         thr_malloc.cc
log_event_old.cc         sql_class.h          thr_malloc.h
log_event_old.h          sql_client.cc        transaction.cc
log.h                    sql_connect.cc       transaction.h
main.cc                  sql_connect.h        tzfile.h
mdl.cc                   sql_const.h          tztime.cc
mdl.h                    sql_crypt.cc         tztime.h
mem_root_array.h         sql_crypt.h          udf_example.c
message.h                sql_cursor.cc        udf_example.def
message.mc               sql_cursor.h         uniques.cc
message.rc               sql_db.cc            unireg.cc
mf_iocache.cc            sql_db.h             unireg.h

viovirtual io系统,是对network io的封装

CMakeLists.txt    test-sslserver.c  viossl.c           viotest-sslconnect.cc
docs              vio.c             viosslfactories.c
test-ssl.c        vio_priv.h        viotest.cc
test-sslclient.c  viosocket.c       viotest-ssl.c 

extra:提供innochecksum,resolveip等额外的小工具

 charset2html.c  innochecksum.c       perror.c     resolve_stack_dump.c
CMakeLists.txt  my_print_defaults.c  replace.c    yassl
comp_err.c      mysql_waitpid.c      resolveip.c
             

sql-bench:一些测评代码 

 as3ap.sh                 graph-compare-results.sh  server-cfg.sh
bench-count-distinct.sh  innotest1a.sh             test-alter-table.sh
bench-init.pl.sh         innotest1b.sh             test-ATIS.sh
CMakeLists.txt           innotest1.sh              test-big-tables.sh
Comments                 innotest2a.sh             test-connect.sh
compare-results.sh       innotest2b.sh             test-create.sh
copy-db.sh               innotest2.sh              test-insert.sh
crash-me.sh              limits                    test-select.sh
Data                     pwd.bat                   test-transactions.sh
example                  README                    test-wisconsin.sh
example.bat              run-all-tests.sh          uname.bat

winwindows平台提供的编译环境

cmd-line-utilsreadline,libedit工具

libedit  readline  

include包含的头文件

 atomic          my_bit.h       mysql                probes_mysql_nodtrace.h
base64.h        my_bitmap.h    mysql_com.h          queues.h
CMakeLists.txt  my_compare.h   mysql_embed.h        rijndael.h
decimal.h       my_compiler.h  mysql.h              service_versions.h
errmsg.h        my_dbug.h      mysql.h.pp           sha1.h
ft_global.h     my_dir.h       mysql_time.h         sha2.h
hash.h          my_getopt.h    mysql_version.h.in   sql_common.h
heap.h          my_global.h    my_stacktrace.h      sslopt-case.h
keycache.h      myisam.h       mysys_err.h          sslopt-longopts.h
lf.h            myisammrg.h    my_sys.h             sslopt-vars.h
m_ctype.h       myisampack.h   my_time.h            t_ctype.h
m_string.h      my_libwrap.h   my_tree.h            thr_alarm.h
my_aes.h        my_list.h      my_uctype.h          thr_lock.h
my_alarm.h      my_md5.h       my_user.h            typelib.h
my_alloc.h      my_net.h       my_xml.h             violite.h
my_atomic.h     my_nosys.h     password.h           welcome_copyright_notice.h
my_attribute.h  my_pthread.h   probes_mysql.d.base
my_base.h       my_rdtsc.h     probes_mysql.h          

man手册页

sql-common存放部分服务器端和客户端都会用到的代码 

 client.c  client_plugin.c  my_time.c  my_user.c  pack.c

zlibzip库工具

adler32.c       crc32.c    gzio.c     inffixed.h  README        zconf.h
algorithm.txt   crc32.h    INDEX      inflate.c   README.MySQL  zlib.3
ChangeLog       deflate.c  infback.c  inflate.h   trees.c       zlib.h
CMakeLists.txt  deflate.h  inffast.c  inftrees.c  trees.h       zutil.c
compress.c      FAQ        inffast.h  inftrees.h  uncompr.c     zutil.h

mysql-testmysqld的测试工具箱

CMakeLists.txt  lib                   purify.supp  README.stress  valgrind.supp
collections     mtr.out-of-source     r            std_data
extra           mysql-stress-test.pl  README       suite
include         mysql-test-run.pl     README.gcov  t

storage存储引擎目录,各类存储引擎代码都在这个大目录中。

archive    csv      federated  innobase  myisammrg  perfschema
blackhole  example  heap       myisam    ndb

 

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值