参考:詳解MySQL オライリー Sasba Pacbev著/伊藤直也、田中慎司、吉川英興 監訳/菅野良二訳
目標:
・SQLパーサー&オプティマイザ部分の理解
ビルド参考:
開発ソースツリーを使用して MySQL をインストールする
環境はAWS EC2 t1.microインスタンス
1、ソースの取得
[centos@mirage mysql-server]$ git clone https://github.com/mysql/mysql-server.git [centos@mirage mysql-server]$ git branch -r origin/5.5 origin/5.6 origin/5.7 origin/HEAD -> origin/5.7 origin/cluster-7.2 origin/cluster-7.3 origin/cluster-7.4 [centos@mirage mysql-server]$ git branch 5.6 * 5.7
2、ビルド環境の準備
動きを追うためデバッグオプションつきでビルド。
[centos@mirage mysql-server]$ cd bld_debug/ [centos@mirage bld_debug]$ cmake .. -DCMAKE_BUILD_TYPE=Debug -- Running cmake version 2.8.11 -- Found Git: /usr/bin/git (found version "1.8.3.1") -- Configuring with MAX_INDEXES = 64U -- The C compiler identification is GNU 4.8.3 -- The CXX compiler identification is GNU 4.8.3 -- Check for working C compiler: /usr/bin/cc -- Check for working C compiler: /usr/bin/cc -- works -- Detecting C compiler ABI info -- Detecting C compiler ABI info - done -- Check for working CXX compiler: /usr/bin/c++ -- Check for working CXX compiler: /usr/bin/c++ -- works -- Detecting CXX compiler ABI info -- Detecting CXX compiler ABI info - done -- Looking for SHM_HUGETLB -- Looking for SHM_HUGETLB - found -- Looking for sys/types.h -- Looking for sys/types.h - found -- Looking for stdint.h -- Looking for stdint.h - found -- Looking for stddef.h -- Looking for stddef.h - found -- Check size of void * -- Check size of void * - done -- SIZEOF_VOIDP 8 -- MySQL 5.7.7-rc -- Packaging as: mysql-5.7.7-rc-Linux-x86_64 -- Looked for boost/version.hpp in and -- BOOST_INCLUDE_DIR BOOST_INCLUDE_DIR-NOTFOUND -- LOCAL_BOOST_DIR -- LOCAL_BOOST_ZIP -- Could not find (the correct version of) boost. -- MySQL currently requires boost_1_57_0 CMake Error at cmake/boost.cmake:76 (MESSAGE): You can download it with -DDOWNLOAD_BOOST=1 -DWITH_BOOST=This CMake script will look for boost in . If it is not there, it will download and unpack it (in that directory) for you. If you are inside a firewall, you may need to use an http proxy: export http_proxy=http://example.com:80 Call Stack (most recent call first): cmake/boost.cmake:228 (COULD_NOT_FIND_BOOST) CMakeLists.txt:452 (INCLUDE) -- Configuring incomplete, errors occurred!
こけた
5.7ではboostが必要らしい
最新版にはこだわらないので5.6に切り替えてリトライ
[centos@mirage bld_debug]$ pwd /home/centos/mysql-server/bld_debug [centos@mirage bld_debug]$ cd .. [centos@mirage mysql-server]$ git checkout 5.6 Switched to branch '5.6' [centos@mirage mysql-server]$ [centos@mirage mysql-server]$ cd bld_debug/ [centos@mirage bld_debug]$ cmake .. -DCMAKE_BUILD_TYPE=Debug -- Running cmake version 2.8.11 -- Found Git: /usr/bin/git (found version "1.8.3.1") -- Configuring with MAX_INDEXES = 64U -- The C compiler identification is GNU 4.8.3 -- The CXX compiler identification is GNU 4.8.3 -- Check for working C compiler: /usr/bin/cc -- Check for working C compiler: /usr/bin/cc -- works ........................省略 -- Check size of wint_t - done -- Could NOT find Curses (missing: CURSES_LIBRARY CURSES_INCLUDE_PATH) CMake Error at cmake/readline.cmake:85 (MESSAGE): Curses library not found. Please install appropriate package, remove CMakeCache.txt and rerun cmake.On Debian/Ubuntu, package name is libncurses5-dev, on Redhat and derivates it is ncurses-devel. Call Stack (most recent call first): cmake/readline.cmake:128 (FIND_CURSES) cmake/readline.cmake:202 (MYSQL_USE_BUNDLED_EDITLINE) CMakeLists.txt:409 (MYSQL_CHECK_EDITLINE) -- Configuring incomplete, errors occurred!
こけた
cursesインストール
$ sudo yum install ncurses-devel
リトライ
[centos@mirage bld_debug]$ rm -rf * [centos@mirage bld_debug]$ cmake .. -DCMAKE_BUILD_TYPE=Debug -- Running cmake version 2.8.11 -- Found Git: /usr/bin/git (found version "1.8.3.1") -- Configuring with MAX_INDEXES = 64U -- The C compiler identification is GNU 4.8.3 -- The CXX compiler identification is GNU 4.8.3 -- Check for working C compiler: /usr/bin/cc -- Check for working C compiler: /usr/bin/cc -- works ........................省略 -- Library mysqlclient depends on OSLIBS -lpthread;m;dl -- Googlemock was not found. gtest-based unit tests will be disabled. You can run cmake . -DENABLE_DOWNLOADS=1 to automatically download and build required components from source. -- If you are inside a firewall, you may need to use an http proxy: export http_proxy=http://example.com:80 -- Library mysqlserver depends on OSLIBS -lpthread;m;crypt;dl -- CMAKE_BUILD_TYPE: Debug -- COMPILE_DEFINITIONS: HAVE_CONFIG_H -- CMAKE_C_FLAGS: -Wall -Wextra -Wformat-security -Wvla -Wwrite-strings -Wdeclaration-after-statement -Werror -- CMAKE_CXX_FLAGS: -Wall -Wextra -Wformat-security -Wvla -Woverloaded-virtual -Wno-unused-parameter -Werror -- CMAKE_C_FLAGS_DEBUG: -g -fabi-version=2 -fno-omit-frame-pointer -fno-strict-aliasing -DENABLED_DEBUG_SYNC -- CMAKE_CXX_FLAGS_DEBUG: -g -fabi-version=2 -fno-omit-frame-pointer -fno-strict-aliasing -DENABLED_DEBUG_SYNC -- Configuring done -- Generating done -- Build files have been written to: /home/centos/mysql-server/bld_debug
できた
3、ビルド実行
[centos@mirage bld_debug]$ make Scanning dependencies of target INFO_BIN [ 0%] Built target INFO_BIN Scanning dependencies of target INFO_SRC [ 0%] Built target INFO_SRC Scanning dependencies of target abi_check [ 0%] Built target abi_check Scanning dependencies of target zlib [ 0%] Building C object zlib/CMakeFiles/zlib.dir/adler32.c.o [ 0%] Building C object zlib/CMakeFiles/zlib.dir/compress.c.o [ 0%] Building C object zlib/CMakeFiles/zlib.dir/crc32.c.o [ 0%] Building C object zlib/CMakeFiles/zlib.dir/deflate.c.o [ 0%] Building C object zlib/CMakeFiles/zlib.dir/gzio.c.o [ 0%] Building C object zlib/CMakeFiles/zlib.dir/infback.c.o [ 0%] Building C object zlib/CMakeFiles/zlib.dir/inffast.c.o [ 0%] Building C object zlib/CMakeFiles/zlib.dir/inflate.c.o ........................省略 Scanning dependencies of target mysql_client_test_embedded [ 98%] Building C object libmysqld/examples/CMakeFiles/mysql_client_test_embedded.dir/__/__/tests/mysql_client_test.c.o Linking CXX executable mysql_client_test_embedded [ 98%] Built target mysql_client_test_embedded Scanning dependencies of target mysql_embedded [ 98%] Building CXX object libmysqld/examples/CMakeFiles/mysql_embedded.dir/__/__/client/completion_hash.cc.o [ 99%] Building CXX object libmysqld/examples/CMakeFiles/mysql_embedded.dir/__/__/client/mysql.cc.o [ 99%] Building CXX object libmysqld/examples/CMakeFiles/mysql_embedded.dir/__/__/client/readline.cc.o Linking CXX executable mysql_embedded [ 99%] Built target mysql_embedded Scanning dependencies of target mysqltest_embedded [100%] Building CXX object libmysqld/examples/CMakeFiles/mysqltest_embedded.dir/__/__/client/mysqltest.cc.o Linking CXX executable mysqltest_embedded [100%] Built target mysqltest_embedded Scanning dependencies of target my_safe_process [100%] Building CXX object mysql-test/lib/My/SafeProcess/CMakeFiles/my_safe_process.dir/safe_process.cc.o Linking CXX executable my_safe_process [100%] Built target my_safe_process
できた
大体7~8分程度 10分はかかってないと思う
4、テスト
[centos@mirage bld_debug]$ make test Running tests... Test project /home/centos/mysql-server/bld_debug Start 1: hp_test1 1/21 Test #1: hp_test1 ......................... Passed 0.01 sec Start 2: hp_test2 2/21 Test #2: hp_test2 ......................... Passed 0.53 sec Start 3: pfs_instr_class 3/21 Test #3: pfs_instr_class .................. Passed 0.01 sec Start 4: pfs_instr_class-oom 4/21 Test #4: pfs_instr_class-oom .............. Passed 0.01 sec Start 5: pfs_instr 5/21 Test #5: pfs_instr ........................ Passed 0.01 sec Start 6: pfs_instr-oom 6/21 Test #6: pfs_instr-oom .................... Passed 0.01 sec Start 7: pfs_account-oom 7/21 Test #7: pfs_account-oom .................. Passed 0.01 sec Start 8: pfs_host-oom 8/21 Test #8: pfs_host-oom ..................... Passed 0.01 sec Start 9: pfs_user-oom 9/21 Test #9: pfs_user-oom ..................... Passed 0.01 sec Start 10: pfs 10/21 Test #10: pfs .............................. Passed 0.73 sec Start 11: pfs_connect_attr 11/21 Test #11: pfs_connect_attr ................. Passed 0.11 sec Start 12: regex1 12/21 Test #12: regex1 ........................... Passed 0.01 sec Start 13: regex2 13/21 Test #13: regex2 ........................... Passed 0.00 sec Start 14: regex3 14/21 Test #14: regex3 ........................... Passed 0.00 sec Start 15: queues_test 15/21 Test #15: queues_test ...................... Passed 0.29 sec Start 16: simple 16/21 Test #16: simple ........................... Passed 0.32 sec Start 17: skip 17/21 Test #17: skip ............................. Passed 0.00 sec Start 18: todo 18/21 Test #18: todo ............................. Passed 0.00 sec Start 19: skip_all 19/21 Test #19: skip_all ......................... Passed 0.00 sec Start 20: no_plan 20/21 Test #20: no_plan .......................... Passed 0.00 sec Start 21: basic 21/21 Test #21: basic ............................ Passed 0.00 sec 100% tests passed, 0 tests failed out of 21 Total Test time (real) = 2.14 sec [centos@mirage bld_debug]$
できた
5、デバッガインストール
動作を確認するためにデバッガを入れておく
$ sudo yum install gdb