Skip to content

Commit 07a2641

Browse files
MDEV-36523: Load basic stats from trace into optimizer
This task loads the stats of the tables that are used in a query, from the trace into the optimizer. This feature is also controlled by optimizer_record_context, and is not enabled by default. The stats such as num_of_records present in the table, indexes if present, their names, along with the average number of records_per_key with in each index are loaded from the trace. Additionally, stats from range analysis i.e. ranges, and the corresponding number of records are also loaded from the trace. The trace context which is in JSON format is firstly set into the session variable optimizer_trace_stored_context. Later, when a user issues a query, the contents of this variable is parsed and an in memory representation is built using the class Optimizer_context_replay. This class is then used by the optimizer to update and save original values of the tables, indexes, and range stats in the methods "set_statistics_for_table()" of sql_statistics.cc, and "check_quick_select()" of opt_range.cc. After the query gets finished, the statistics that were updated in the optimizer are restored back to the saved original values. The entry point for parsing the json structure is in "mysql_execute_command()" of sql_parse.cc, and similarly exit point i.e. to restore the saved stats of the optimizer is at the end of the same method. Two new warning/error messages are introduced: ER_JSON_OPTIMIZER_REPLAY_CONTEXT_PARSE_FAILED, and ER_JSON_OPTIMIZER_REPLAY_CONTEXT_MATCH_FAILED
1 parent 491ded1 commit 07a2641

27 files changed

+3640
-137
lines changed

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -861,6 +861,9 @@ The following specify which files/extra groups are read (specified before remain
861861
--optimizer-record-context
862862
Controls storing of optmizer context of all the tables
863863
that are referenced in a query
864+
--optimizer-replay-context=name
865+
The context for a query that is in JSON format for
866+
reusing the stored stats
864867
--optimizer-row-copy-cost=#
865868
Cost of copying a row from the engine or the join cache
866869
to the SQL layer
@@ -1895,6 +1898,7 @@ optimizer-max-sel-arg-weight 32000
18951898
optimizer-max-sel-args 16000
18961899
optimizer-prune-level 2
18971900
optimizer-record-context FALSE
1901+
optimizer-replay-context
18981902
optimizer-row-copy-cost 0.060866
18991903
optimizer-row-lookup-cost 0.130839
19001904
optimizer-row-next-find-cost 0.045916

0 commit comments

Comments
 (0)