摘要:
分析mysql的语法解析过程
MySQL: LEX Struct Reference
MySQL :: MySQL Internals Manual :: 12.4 Structure Of Complex Select
MySQL :: MySQL Internals Manual :: 10.1 The Item Class
MySQL :: MySQL Internals Manual :: 10 Important Algorithms and Structures
设计:
动态时序图:
函数调用堆栈:
parse_sql
(gdb) bt
#0 parse_sql (thd=thd@entry=0x7efba8013cb0, parser_state=parser_state@entry=0x7eff5fe82fe0, creation_ctx=creation_ctx@entry=0x0)
at /data2/jenkins/workspace/stonedb5.7-zsl-centos7.9-30-238/sql/sql_:7120
#1 0x0000000000ec1d24 in mysql_parse (thd=thd@entry=0x7efba8013cb0, parser_state=parser_state@entry=0x7eff5fe82fe0)
at /data2/jenkins/workspace/stonedb5.7-zsl-centos7.9-30-238/sql/sql_:5501
#2 0x0000000000ec2a04 in dispatch_command (thd=thd@entry=0x7efba8013cb0, com_data=com_data@entry=0x7eff5fe83640, command=COM_QUERY)
at /data2/jenkins/workspace/stonedb5.7-zsl-centos7.9-30-238/sql/sql_:1495
#3 0x0000000000ec4450 in do_command (thd=thd@entry=0x7efba8013cb0) at /data2/jenkins/workspace/stonedb5.7-zsl-centos7.9-30-238/sql/sql_:1034
#4 0x0000000000f85270 in handle_connection (arg=arg@entry=0x62e2480) at /data2/jenkins/workspace/stonedb5.7-zsl-centos7.9-30-238/sql/conn_handler/connection_handler_per_:313
#5 0x000000000144f224 in pfs_spawn_thread (arg=0x62faeb0) at /data2/jenkins/workspace/stonedb5.7-zsl-centos7.9-30-238/storage/perfschema/:2197
#6 0x00007effaaeb3ea5 in start_thread (arg=0x7eff5fe84700) at pthread_create.c:307
#7 0x00007effa83fcb0d in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:111
MYSQLparse
(gdb) bt
#0 MYSQLparse (YYTHD=YYTHD@entry=0x7efba8013cb0) at /data2/jenkins/workspace/stonedb5.7-zsl-centos7.9-30-238/build/build_only/sql/sql_:18452
#1 0x0000000000ec17b1 in parse_sql (thd=thd@entry=0x7efba8013cb0, parser_state=parser_state@entry=0x7eff5fe82fe0, creation_ctx=creation_ctx@entry=0x0)
at /data2/jenkins/workspace/stonedb5.7-zsl-centos7.9-30-238/sql/sql_:7178
#2 0x0000000000ec1d24 in mysql_parse (thd=thd@entry=0x7efba8013cb0, parser_state=parser_state@entry=0x7eff5fe82fe0)
at /data2/jenkins/workspace/stonedb5.7-zsl-centos7.9-30-238/sql/sql_:5501
#3 0x0000000000ec2a04 in dispatch_command (thd=thd@entry=0x7efba8013cb0, com_data=com_data@entry=0x7eff5fe83640, command=COM_QUERY)
at /data2/jenkins/workspace/stonedb5.7-zsl-centos7.9-30-238/sql/sql_:1495
#4 0x0000000000ec4450 in do_command (thd=thd@entry=0x7efba8013cb0) at /data2/jenkins/workspace/stonedb5.7-zsl-centos7.9-30-238/sql/sql_:1034
#5 0x0000000000f85270 in handle_connection (arg=arg@entry=0x62e2480) at /data2/jenkins/workspace/stonedb5.7-zsl-centos7.9-30-238/sql/conn_handler/connection_handler_per_:313
#6 0x000000000144f224 in pfs_spawn_thread (arg=0x62faeb0) at /data2/jenkins/workspace/stonedb5.7-zsl-centos7.9-30-238/storage/perfschema/:2197
#7 0x00007effaaeb3ea5 in start_thread (arg=0x7eff5fe84700) at pthread_create.c:307
#8 0x00007effa83fcb0d in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:111
MYSQLlex
(gdb) bt
#0 MYSQLlex (yylval=yylval@entry=0x7eff5fe80df0, yylloc=yylloc@entry=0x7eff5fe80db0, thd=thd@entry=0x7efba8013cb0)
at /data2/jenkins/workspace/stonedb5.7-zsl-centos7.9-30-238/sql/sql_:1312
#1 0x0000000000f9cadc in MYSQLparse (YYTHD=YYTHD@entry=0x7efba8013cb0) at /data2/jenkins/workspace/stonedb5.7-zsl-centos7.9-30-238/build/build_only/sql/sql_:18568
#2 0x0000000000ec17b1 in parse_sql (thd=thd@entry=0x7efba8013cb0, parser_state=parser_state@entry=0x7eff5fe82fe0, creation_ctx=creation_ctx@entry=0x0)
at /data2/jenkins/workspace/stonedb5.7-zsl-centos7.9-30-238/sql/sql_:7178
#3 0x0000000000ec1d24 in mysql_parse (thd=thd@entry=0x7efba8013cb0, parser_state=parser_state@entry=0x7eff5fe82fe0)
at /data2/jenkins/workspace/stonedb5.7-zsl-centos7.9-30-238/sql/sql_:5501
#4 0x0000000000ec2a04 in dispatch_command (thd=thd@entry=0x7efba8013cb0, com_data=com_data@entry=0x7eff5fe83640, command=COM_QUERY)
at /data2/jenkins/workspace/stonedb5.7-zsl-centos7.9-30-238/sql/sql_:1495
#5 0x0000000000ec4450 in do_command (thd=thd@entry=0x7efba8013cb0) at /data2/jenkins/workspace/stonedb5.7-zsl-centos7.9-30-238/sql/sql_:1034
#6 0x0000000000f85270 in handle_connection (arg=arg@entry=0x62e2480) at /data2/jenkins/workspace/stonedb5.7-zsl-centos7.9-30-238/sql/conn_handler/connection_handler_per_:313
#7 0x000000000144f224 in pfs_spawn_thread (arg=0x62faeb0) at /data2/jenkins/workspace/stonedb5.7-zsl-centos7.9-30-238/storage/perfschema/:2197
#8 0x00007effaaeb3ea5 in start_thread (arg=0x7eff5fe84700) at pthread_create.c:307
#9 0x00007effa83fcb0d in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:111
mysql_execute_command
(gdb) bt
#0 mysql_execute_command (thd=thd@entry=0x7efba8013cb0, first_level=first_level@entry=true) at /data2/jenkins/workspace/stonedb5.7-zsl-centos7.9-30-238/sql/sql_:2461
#1 0x0000000000ec1f05 in mysql_parse (thd=thd@entry=0x7efba8013cb0, parser_state=parser_state@entry=0x7eff5fe82fe0)
at /data2/jenkins/workspace/stonedb5.7-zsl-centos7.9-30-238/sql/sql_:5621
#2 0x0000000000ec2a04 in dispatch_command (thd=thd@entry=0x7efba8013cb0, com_data=com_data@entry=0x7eff5fe83640, command=COM_QUERY)
at /data2/jenkins/workspace/stonedb5.7-zsl-centos7.9-30-238/sql/sql_:1495
#3 0x0000000000ec4450 in do_command (thd=thd@entry=0x7efba8013cb0) at /data2/jenkins/workspace/stonedb5.7-zsl-centos7.9-30-238/sql/sql_:1034
#4 0x0000000000f85270 in handle_connection (arg=arg@entry=0x62e2480) at /data2/jenkins/workspace/stonedb5.7-zsl-centos7.9-30-238/sql/conn_handler/connection_handler_per_:313
#5 0x000000000144f224 in pfs_spawn_thread (arg=0x62faeb0) at /data2/jenkins/workspace/stonedb5.7-zsl-centos7.9-30-238/storage/perfschema/:2197
#6 0x00007effaaeb3ea5 in start_thread (arg=0x7eff5fe84700) at pthread_create.c:307
#7 0x00007effa83fcb0d in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:111
JOIN::optimize
(gdb) bt
#0 JOIN::optimize (this=0x7efba800ae78, part=part@entry=1 '\001') at /data2/jenkins/workspace/stonedb5.7-zsl-centos7.9-30-238/sql/sql_:158
#1 0x00000000014d5a8a in Tianmu::core::optimize_select (thd=thd@entry=0x7efba8013cb0, select_options=<optimized out>, result=<optimized out>, select_lex=select_lex@entry=0x7efba80094a0,
optimize_after_tianmu=@0x7eff5fe820e4: 1, free_join=@0x7eff5fe820e0: 1) at /data2/jenkins/workspace/stonedb5.7-zsl-centos7.9-30-238/storage/tianmu/core/engine_execute.cpp:352
#2 0x00000000014da6fb in Tianmu::core::Engine::HandleSelect (this=<optimized out>, thd=0x7efba8013cb0, lex=lex@entry=0x7efba8015e28, result=<optimized out>,
setup_tables_done_option=<optimized out>, res=@0x7eff5fe820dc: 32507, optimize_after_tianmu=<optimized out>, tianmu_free_join=<optimized out>, with_insert=<optimized out>)
at /data2/jenkins/workspace/stonedb5.7-zsl-centos7.9-30-238/storage/tianmu/core/engine_execute.cpp:225
#3 0x0000000001578ac5 in Tianmu::dbhandler::TIANMU_HandleSelect (thd=<optimized out>, lex=0x7efba8015e28, result=<optimized out>, setup_tables_done_option=<optimized out>,
res=<optimized out>, optimize_after_tianmu=<optimized out>, tianmu_free_join=@0x7eff5fe820e0: 1, with_insert=0)
at /data2/jenkins/workspace/stonedb5.7-zsl-centos7.9-30-238/storage/tianmu/handler/ha_rcengine.cpp:82
#4 0x00000000009166da in execute_sqlcom_select (thd=thd@entry=0x7efba8013cb0, all_tables=<optimized out>) at /data2/jenkins/workspace/stonedb5.7-zsl-centos7.9-30-238/sql/sql_:5182
#5 0x0000000000ebfbc3 in mysql_execute_command (thd=thd@entry=0x7efba8013cb0, first_level=first_level@entry=true)
at /data2/jenkins/workspace/stonedb5.7-zsl-centos7.9-30-238/sql/sql_:2831
#6 0x0000000000ec1f05 in mysql_parse (thd=thd@entry=0x7efba8013cb0, parser_state=parser_state@entry=0x7eff5fe82fe0)
at /data2/jenkins/workspace/stonedb5.7-zsl-centos7.9-30-238/sql/sql_:5621
#7 0x0000000000ec2a04 in dispatch_command (thd=thd@entry=0x7efba8013cb0, com_data=com_data@entry=0x7eff5fe83640, command=COM_QUERY)
at /data2/jenkins/workspace/stonedb5.7-zsl-centos7.9-30-238/sql/sql_:1495
#8 0x0000000000ec4450 in do_command (thd=thd@entry=0x7efba8013cb0) at /data2/jenkins/workspace/stonedb5.7-zsl-centos7.9-30-238/sql/sql_:1034
#9 0x0000000000f85270 in handle_connection (arg=arg@entry=0x62e2480) at /data2/jenkins/workspace/stonedb5.7-zsl-centos7.9-30-238/sql/conn_handler/connection_handler_per_:313
#10 0x000000000144f224 in pfs_spawn_thread (arg=0x62faeb0) at /data2/jenkins/workspace/stonedb5.7-zsl-centos7.9-30-238/storage/perfschema/:2197
#11 0x00007effaaeb3ea5 in start_thread (arg=0x7eff5fe84700) at pthread_create.c:307
#12 0x00007effa83fcb0d in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:111