Skip to content

Commit b959816

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.
1 parent 491ded1 commit b959816

20 files changed

+3298
-114
lines changed

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -886,6 +886,8 @@ The following specify which files/extra groups are read (specified before remain
886886
--optimizer-selectivity-sampling-limit=#
887887
Controls number of record samples to check condition
888888
selectivity
889+
--optimizer-stored-context=name
890+
The context for a query that is stored in JSON format
889891
--optimizer-switch=name
890892
Fine-tune the optimizer behavior. Takes a comma-separated
891893
list of option=value pairs, where value is on, off, or
@@ -1903,6 +1905,7 @@ optimizer-rowid-copy-cost 0.002653
19031905
optimizer-scan-setup-cost 10
19041906
optimizer-search-depth 62
19051907
optimizer-selectivity-sampling-limit 100
1908+
optimizer-stored-context
19061909
optimizer-switch index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_merge_sort_intersection=off,index_condition_pushdown=on,derived_merge=on,derived_with_keys=on,firstmatch=on,loosescan=on,duplicateweedout=on,materialization=on,in_to_exists=on,semijoin=on,partial_match_rowid_merge=on,partial_match_table_scan=on,subquery_cache=on,mrr=off,mrr_cost_based=off,mrr_sort_keys=off,outer_join_with_cache=on,semijoin_with_cache=on,join_cache_incremental=on,join_cache_hashed=on,join_cache_bka=on,optimize_join_buffer_size=on,table_elimination=on,extended_keys=on,exists_to_in=on,orderby_uses_equalities=on,condition_pushdown_for_derived=on,split_materialized=on,condition_pushdown_for_subquery=on,rowid_filter=on,condition_pushdown_from_having=on,not_null_range_scan=off,hash_join_cardinality=on,cset_narrowing=on,sargable_casefold=on
19071910
optimizer-trace
19081911
optimizer-trace-max-mem-size 1048576

0 commit comments

Comments
 (0)