MySQL 9.1.0
Source Code Documentation
|
A per-session context which is always available at any point of execution, because in practice it's accessible from THD which contains: More...
#include <opt_trace_context.h>
Classes | |
class | Opt_trace_context_impl |
To have the smallest impact on THD's size, most of the implementation is moved to a separate class Opt_trace_context_impl which is instantiated on the heap when really needed. More... | |
Public Types | |
enum | { FLAG_DEFAULT = 0 , FLAG_ENABLED = 1 << 0 , FLAG_ONE_LINE = 1 << 1 } |
Flags' numeric values for @@optimizer_trace variable. More... | |
enum | feature_value { GREEDY_SEARCH = 1 << 0 , RANGE_OPTIMIZER = 1 << 1 , DYNAMIC_RANGE = 1 << 2 , REPEATED_SUBSELECT = 1 << 3 , MISC = 1 << 7 } |
Features' numeric values for @@optimizer_trace_features variable. More... | |
Public Member Functions | |
Opt_trace_context () | |
~Opt_trace_context () | |
bool | start (bool support_I_S, bool support_dbug_or_missing_priv, bool end_marker, bool one_line, long offset, long limit, ulong max_mem_size, ulonglong features) |
Starts a new trace. More... | |
void | end () |
Ends the current (=open, unfinished, being-generated) trace. More... | |
bool | is_started () const |
Returns whether there is a current trace. More... | |
bool | support_I_S () const |
void | set_query (const char *query, size_t length, const CHARSET_INFO *charset) |
Set the "original" query (not transformed, as sent by client) for the current trace. More... | |
void | reset () |
Brainwash: deletes all remembered traces and resets counters regarding OFFSET/LIMIT (so that the next statement is considered as "at offset
0"). More... | |
bool | get_end_marker () const |
bool | get_one_line () const |
void | missing_privilege () |
User lacks privileges to see the current trace. More... | |
bool | feature_enabled (feature_value f) const |
Opt_trace_stmt * | get_current_stmt_in_gen () |
Opt_trace_struct is passed Opt_trace_context*, and needs to know to which statement's trace to attach, so Opt_trace_context must provide this information. More... | |
const Opt_trace_stmt * | get_next_stmt_for_I_S (long *got_so_far) const |
void | disable_I_S_for_this_and_children () |
Temporarily disables I_S for this trace and its children. More... | |
void | restore_I_S () |
Restores I_S support to what it was before the previous call to disable_I_S_for_this_and_children(). More... | |
UnstructuredTrace * | unstructured_trace () |
void | set_unstructured_trace (UnstructuredTrace *trace) |
void | ConsumeUnstructuredTrace (THD *thd) |
Move unstructured trace text (as produced by Hypergraph) into the JSON tree. More... | |
Static Public Attributes | |
static const char * | flag_names [] |
Names of flags for @@optimizer_trace variable of sys_vars.cc : More... | |
static const char * | feature_names [] |
Features' names for @@optimizer_trace_features variable of sys_vars.cc: More... | |
static const feature_value | default_features |
Optimizer features which are traced by default. More... | |
Private Member Functions | |
void | purge_stmts (bool purge_all) |
Find and delete unneeded traces. More... | |
size_t | allowed_mem_size_for_current_stmt () const |
Compute maximum allowed memory size for current trace. More... | |
Opt_trace_context (const Opt_trace_context &) | |
Not defined copy constructor, to disallow copy. More... | |
Opt_trace_context & | operator= (const Opt_trace_context &) |
Not defined assignment operator, to disallow assignment. More... | |
Private Attributes | |
Opt_trace_context_impl * | pimpl |
int | I_S_disabled |
Dynamically allocated implementation. More... | |
A per-session context which is always available at any point of execution, because in practice it's accessible from THD which contains:
Opt_trace_context opt_trace;
It maintains properties of the session's regarding tracing: enabled/disabled state, style (all trace on one line, or not, etc), a list of all remembered traces of previous and current SQL statement (as restricted by OFFSET/LIMIT), and a pointer to the current (being-generated) trace (which itself has a pointer to its current open object/array).
Here is why the context needs to provide the current open object/array:
#0 Item_in_subselect::single_value_transformer - opens an object for key "transformation" #1 Item_in_subselect::select_in_like_transformer - does no tracing #2 Item_allany_subselect::select_transformer - does no tracing #3 Query_block::prepare - opens an object for key "join_preparation"So the object opened in #3 would have to be passed in argument to #2 and #1 in order to finally reach #0 where object "transformation" would be added to it.
anonymous enum |
Features' numeric values for @@optimizer_trace_features variable.
|
inline |
Opt_trace_context::~Opt_trace_context | ( | ) |
|
private |
Not defined copy constructor, to disallow copy.
|
private |
Compute maximum allowed memory size for current trace.
The current trace is the only one active. Other traces break down in two groups:
void Opt_trace_context::ConsumeUnstructuredTrace | ( | THD * | thd | ) |
Move unstructured trace text (as produced by Hypergraph) into the JSON tree.
Move unstructured trace text (as used by Hypergraph) into the JSON tree.
|
inline |
Temporarily disables I_S for this trace and its children.
void Opt_trace_context::end | ( | void | ) |
Ends the current (=open, unfinished, being-generated) trace.
If missing_privilege()
has been called between start() and end(), end() restores I_S support to what it was before the call to missing_privilege()
. This is the key to ensure that missing_privilege() does not disable I_S support for the rest of the connection's life!
|
inline |
f | feature |
|
inline |
Opt_trace_struct is passed Opt_trace_context*, and needs to know to which statement's trace to attach, so Opt_trace_context must provide this information.
|
inline |
const Opt_trace_stmt * Opt_trace_context::get_next_stmt_for_I_S | ( | long * | got_so_far | ) | const |
[in,out] | got_so_far | How many statements the caller got so far (by previous calls to this function); function updates this count. |
|
inline |
|
inline |
Returns whether there is a current trace.
void Opt_trace_context::missing_privilege | ( | ) |
User lacks privileges to see the current trace.
Make the trace appear empty in Opt_trace_info, and disable I_S for all its upcoming children.
Once a call to this function has been made, subsequent calls to it before end()
have no effects.
|
private |
Not defined assignment operator, to disallow assignment.
|
private |
Find and delete unneeded traces.
For example if OFFSET=-1,LIMIT=1, only the last trace is needed. When a new trace is started, the previous traces becomes unneeded and this function deletes them which frees memory.
purge_all | if true, ignore OFFSET and thus delete everything |
void Opt_trace_context::reset | ( | void | ) |
Brainwash: deletes all remembered traces and resets counters regarding OFFSET/LIMIT (so that the next statement is considered as "at offset 0").
Does not reset the @@optimizer_trace_offset/limit variables.
|
inline |
Restores I_S support to what it was before the previous call to disable_I_S_for_this_and_children().
void Opt_trace_context::set_query | ( | const char * | query, |
size_t | length, | ||
const CHARSET_INFO * | charset | ||
) |
Set the "original" query (not transformed, as sent by client) for the current trace.
query | query |
length | query's length |
charset | charset which was used to encode this query |
|
inline |
bool Opt_trace_context::start | ( | bool | support_I_S, |
bool | support_dbug_or_missing_priv, | ||
bool | end_marker, | ||
bool | one_line, | ||
long | offset, | ||
long | limit, | ||
ulong | max_mem_size, | ||
ulonglong | features | ||
) |
Starts a new trace.
support_I_S | Whether this statement should have its trace in information_schema |
support_dbug_or_missing_priv | 'true' if this statement should have its trace in the dbug log (–debug), or if missing_privilege() may be called on this trace |
end_marker | For a key/(object|array) pair, should the key be repeated in a comment when the object|array closes? like "key_foo": { multi-line blah } / * key_foo * /This is for human-readability only, not valid in JSON. Note that YAML supports #-prefixed comments (we would just need to put the next item's "," before the current item's "#"). |
one_line | Should the trace be on a single line without indentation? (More compact for network transfer to programs, less human-readable.) |
offset | Offset for restricting trace production. |
limit | Limit for restricting trace production. |
max_mem_size | Maximum allowed for cumulated size of all remembered traces. |
features | Only these optimizer features should be traced. |
false | ok |
true | error (OOM): instance is unusable, so only destructor is permitted on it; any other member function has undefined effects. |
bool Opt_trace_context::support_I_S | ( | ) | const |
|
inline |
|
static |
Optimizer features which are traced by default.
|
static |
Features' names for @@optimizer_trace_features variable of sys_vars.cc:
|
static |
Names of flags for @@optimizer_trace variable of sys_vars.cc
:
|
private |
Dynamically allocated implementation.
<>0 <=> any to-be-created statement's trace should not be in information_schema. This applies to next statements, their substatements, etc.
|
private |