Skip to content

Commit d6e6962

Browse files
author
Amit Khandekar
committed
WL#15426: Implement SHOW PARSE_TREE [3/3, enable]
SHOW PARSE_TREE <select_query> returns a single column row containing the json string corresponding to the parse tree. If input SQL has syntax errors or any errors during contextualize() phase, it is aborted with error. When a new PT_* class is introduced, SHOW PARSE_TREE will show this json node along with it's PT_* children, thanks to contextualize(). If the class has members of type other than PT_* and if they are required to re-generate the SQL clause, such information is displayed using appropriate json fields using an overridden function Parse_tree_node::add_json_info(). PT_subquery is generated using a separate child Parse_context. So the corresponding json tree of the child Parse_context had to be plugged in to the json tree of the parent Parse_context. Only SELECT statement is supported. Also, 'expr' parser productions are not exhaustively covered for node-specific json fields. Will probably be done in future releases. Enabled only in Debug build; new cmake flag introduced to enable in non-debug build. Change-Id: I19c0b496bfaf8b6cf7661c8874d8118921d58201
1 parent 894f9b0 commit d6e6962

38 files changed

+3624
-98
lines changed

CMakeLists.txt

+11
Original file line numberDiff line numberDiff line change
@@ -2118,6 +2118,17 @@ OPTION(WITH_HYPERGRAPH_OPTIMIZER
21182118
${WITH_HYPERGRAPH_OPTIMIZER_DEFAULT}
21192119
)
21202120

2121+
# Allow SHOW PARSE_TREE on debug build by default.
2122+
IF(CMAKE_BUILD_TYPE_UPPER STREQUAL "DEBUG" OR WITH_DEBUG)
2123+
SET(WITH_SHOW_PARSE_TREE_DEFAULT ON)
2124+
ELSE()
2125+
SET(WITH_SHOW_PARSE_TREE_DEFAULT OFF)
2126+
ENDIF()
2127+
OPTION(WITH_SHOW_PARSE_TREE
2128+
"Allow showing the parse tree"
2129+
${WITH_SHOW_PARSE_TREE_DEFAULT}
2130+
)
2131+
21212132
# Utility target to build every executable tagged with ADD_TEST.
21222133
ADD_CUSTOM_TARGET(unittest_all)
21232134

config.h.cmake

+1
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,7 @@
220220
#cmakedefine SCRAM_LIB_CONFIGURED
221221
#cmakedefine WITH_HYPERGRAPH_OPTIMIZER
222222
#cmakedefine KERBEROS_LIB_SSPI
223+
#cmakedefine WITH_SHOW_PARSE_TREE
223224

224225
/* Lock Order */
225226
#cmakedefine WITH_LOCK_ORDER 1

include/my_sqlcommand.h

+1
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@ enum enum_sql_command {
171171
SQLCOM_SHOW_CREATE_EVENT,
172172
SQLCOM_SHOW_EVENTS,
173173
SQLCOM_SHOW_CREATE_TRIGGER,
174+
SQLCOM_SHOW_PARSE_TREE,
174175
SQLCOM_SHOW_PROFILE,
175176
SQLCOM_SHOW_PROFILES,
176177
SQLCOM_SIGNAL,

include/mysql/plugin_audit.h.pp

+1
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,7 @@
304304
SQLCOM_SHOW_CREATE_EVENT,
305305
SQLCOM_SHOW_EVENTS,
306306
SQLCOM_SHOW_CREATE_TRIGGER,
307+
SQLCOM_SHOW_PARSE_TREE,
307308
SQLCOM_SHOW_PROFILE,
308309
SQLCOM_SHOW_PROFILES,
309310
SQLCOM_SIGNAL,

mysql-test/r/information_schema_keywords.result

+1
Original file line numberDiff line numberDiff line change
@@ -442,6 +442,7 @@ OWNER 0
442442
PACK_KEYS 0
443443
PAGE 0
444444
PARSER 0
445+
PARSE_TREE 0
445446
PARTIAL 0
446447
PARTITION 1
447448
PARTITIONING 0

mysql-test/r/mysqld--help-notwin.result

+1-1
Original file line numberDiff line numberDiff line change
@@ -1926,7 +1926,7 @@ performance-schema-max-socket-classes 10
19261926
performance-schema-max-socket-instances -1
19271927
performance-schema-max-sql-text-length 1024
19281928
performance-schema-max-stage-classes 175
1929-
performance-schema-max-statement-classes 219
1929+
performance-schema-max-statement-classes 220
19301930
performance-schema-max-statement-stack 10
19311931
performance-schema-max-table-handles -1
19321932
performance-schema-max-table-instances -1

mysql-test/r/mysqld--help-win.result

+1-1
Original file line numberDiff line numberDiff line change
@@ -1938,7 +1938,7 @@ performance-schema-max-socket-classes 10
19381938
performance-schema-max-socket-instances -1
19391939
performance-schema-max-sql-text-length 1024
19401940
performance-schema-max-stage-classes 175
1941-
performance-schema-max-statement-classes 219
1941+
performance-schema-max-statement-classes 220
19421942
performance-schema-max-statement-stack 10
19431943
performance-schema-max-table-handles -1
19441944
performance-schema-max-table-instances -1

0 commit comments

Comments
 (0)