Skip to content

Commit 67b320b

Browse files
MDEV-36483: store ddls in the optimizer trace
This feature stores the ddls of the tables/views that are used in a query, to the optimizer trace. It is currently controlled by a system variable store_ddls_in_optimizer_trace, and is not enabled by default. All the ddls will be stored in a single json array, with each element having table/view name, and the associated create definition of the table/view. The approach taken is to read global query_tables from the thd->lex, and read them in reverse. Create a record with table_name, ddl of the table and add the table_name to the hash, along with dumping the information to the trace. dbName_plus_tableName is used as a key, and the duplicate entries are not added to the hash. The main suite tests are also run with the feature enabled, and they all succeed.
1 parent 823a3a2 commit 67b320b

15 files changed

+1159
-5
lines changed

libmysqld/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ SET(SQL_EMBEDDED_SOURCES emb_qcache.cc libmysqld.c lib_sql.cc
161161
../sql/opt_hints_parser.cc ../sql/opt_hints_parser.h
162162
../sql/scan_char.h
163163
../sql/opt_hints.cc ../sql/opt_hints.h
164+
../sql/opt_trace_ddl_info.cc ../sql/opt_trace_ddl_info.h
164165
${GEN_SOURCES}
165166
${MYSYS_LIBWRAP_SOURCE}
166167
)

mysql-test/main/mysqld--help.result

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -858,6 +858,9 @@ The following specify which files/extra groups are read (specified before remain
858858
heuristic, thus perform exhaustive search: 1 - prune
859859
plans based on cost and number of retrieved rows eq_ref:
860860
2 - prune also if we find an eq_ref chain
861+
--optimizer-record-context
862+
Controls storing of optmizer context of all the tables
863+
that are referenced in a query
861864
--optimizer-row-copy-cost=#
862865
Cost of copying a row from the engine or the join cache
863866
to the SQL layer
@@ -1891,6 +1894,7 @@ optimizer-key-next-find-cost 0.082347
18911894
optimizer-max-sel-arg-weight 32000
18921895
optimizer-max-sel-args 16000
18931896
optimizer-prune-level 2
1897+
optimizer-record-context FALSE
18941898
optimizer-row-copy-cost 0.060866
18951899
optimizer-row-lookup-cost 0.130839
18961900
optimizer-row-next-find-cost 0.045916

0 commit comments

Comments
 (0)