MySQL 9.1.0
Source Code Documentation
|
Object and array are both "structured data" and have lots in common, so the Opt_trace_struct is a base class for them. More...
#include <opt_trace.h>
Public Member Functions | |
void | end () |
The exception to RAII: this function is an explicit way of ending a structure before it goes out of scope. More... | |
Opt_trace_struct & | add_alnum (const char *key, const char *value) |
Adds a value (of string type) to the structure. More... | |
Opt_trace_struct & | add_alnum (const char *value) |
Adds a value (of string type) to the structure. More... | |
Opt_trace_struct & | add_utf8 (const char *key, const char *value, size_t val_length) |
Like add_alnum() but supports any UTF8 characters in 'value'. More... | |
Opt_trace_struct & | add_utf8 (const char *value, size_t val_length) |
Variant of add_utf8() for adding to an array (no key) More... | |
Opt_trace_struct & | add_utf8 (const char *key, const char *value) |
Variant of add_utf8() where 'value' is 0-terminated. More... | |
Opt_trace_struct & | add_utf8 (const char *value) |
Variant of add_utf8() where 'value' is 0-terminated. More... | |
Opt_trace_struct & | add (const char *key, const Item *item) |
Add a value (of Item type) to the structure. More... | |
Opt_trace_struct & | add (const Item *item) |
Opt_trace_struct & | add (const char *key, bool value) |
Opt_trace_struct & | add (bool value) |
Opt_trace_struct & | add (const char *key, int value) |
Opt_trace_struct & | add (int value) |
Opt_trace_struct & | add (const char *key, uint value) |
Opt_trace_struct & | add (uint value) |
Opt_trace_struct & | add (const char *key, ulong value) |
Opt_trace_struct & | add (ulong value) |
Opt_trace_struct & | add (const char *key, longlong value) |
Opt_trace_struct & | add (longlong value) |
Opt_trace_struct & | add (const char *key, ulonglong value) |
Opt_trace_struct & | add (ulonglong value) |
Opt_trace_struct & | add (const char *key, double value) |
Opt_trace_struct & | add (double value) |
Opt_trace_struct & | add_null (const char *key) |
Adds a JSON null object (==Python's "None") More... | |
Opt_trace_struct & | add_utf8_table (const Table_ref *tab) |
Helper to put the database/table name in an object. More... | |
Opt_trace_struct & | add_select_number (uint select_number) |
Helper to put the number of query_block in an object. More... | |
Opt_trace_struct & | add (const char *key, const Cost_estimate &cost) |
Add a value to the structure. More... | |
bool | set_not_empty () |
Informs this structure that we are adding data (scalars, structures) to it. More... | |
const char * | check_key (const char *key) |
Validates the key about to be added. More... | |
Protected Member Functions | |
Opt_trace_struct (Opt_trace_context *ctx_arg, bool requires_key_arg, const char *key, Opt_trace_context::feature_value feature) | |
~Opt_trace_struct () | |
Private Member Functions | |
Opt_trace_struct & | add (const char *key, const char *value) |
Not implemented, use add_alnum() instead. More... | |
Opt_trace_struct & | add (const char *key) |
void | do_construct (Opt_trace_context *ctx, bool requires_key, const char *key, Opt_trace_context::feature_value feature) |
Full initialization. More... | |
void | do_destruct () |
Really does destruction. More... | |
Opt_trace_struct & | do_add (const char *key, const char *value, size_t val_length, bool escape) |
Really adds to the object. More... | |
Opt_trace_struct & | do_add (const char *key, const Item *item) |
Opt_trace_struct & | do_add (const char *key, bool value) |
Opt_trace_struct & | do_add (const char *key, longlong value) |
Opt_trace_struct & | do_add (const char *key, ulonglong value) |
Opt_trace_struct & | do_add (const char *key, double value) |
Opt_trace_struct & | do_add_null (const char *key) |
Opt_trace_struct & | do_add_utf8_table (const Table_ref *tab) |
Opt_trace_struct & | do_add (const char *key, const Cost_estimate &value) |
Opt_trace_struct (const Opt_trace_struct &) | |
not defined More... | |
Opt_trace_struct & | operator= (const Opt_trace_struct &) |
not defined More... | |
Private Attributes | |
bool | started |
Whether the structure does tracing or is dummy. More... | |
bool | requires_key |
Whether the structure requires/forbids keys for values inside it. More... | |
bool | has_disabled_I_S |
Whether this structure caused tracing to be disabled in this statement because belonging to a not-traced optimizer feature, in accordance with the value of @@optimizer_trace_features. More... | |
bool | empty |
Opt_trace_stmt * | stmt |
Trace owning the structure. More... | |
const char * | saved_key |
Key if the structure is the value of a key/value pair, NULL otherwise. More... | |
char | previous_key [25] |
Fixed-length prefix of previous key in this structure, if this structure is an object. More... | |
Object and array are both "structured data" and have lots in common, so the Opt_trace_struct is a base class for them.
When you want to add a structure to the trace, you create an instance of Opt_trace_object or Opt_trace_array, then you add information to it with add(), then the destructor closes the structure (we use RAII, Resource Acquisition Is Initialization).
|
inlineprotected |
ctx_arg | Optimizer trace context for this structure |
requires_key_arg | whether this structure requires/forbids keys for values put inside it (an object requires them, an array forbids them) |
key | key if this structure is the value of a key/value pair, NULL otherwise. This pointer must remain constant and valid until the object is destroyed (to support saved_key). |
feature | optimizer feature to which this structure belongs |
This constructor is never called directly, only from subclasses.
|
inlineprotected |
|
private |
not defined
|
inline |
|
private |
|
inline |
|
private |
Not implemented, use add_alnum() instead.
|
inline |
Add a value to the structure.
key | key |
cost | the value of Cost_estimate |
|
inline |
Add a value (of Item type) to the structure.
The Item should be a condition (like a WHERE clause) which will be pretty-printed into the trace. This is useful for showing condition transformations (equality propagation etc).
key | key |
item | the Item |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
Adds a value (of string type) to the structure.
A key is specified, so it adds the key/value pair (the structure must thus be an object).
There are two "add_*" variants to add a string value. If the value is 0-terminated and each character
key | key |
value | value |
add(x,y).add(z,t).add(u,v)
String-related add() variants are named add_[something]():
|
inline |
Adds a value (of string type) to the structure.
No key is specified, so it adds only the value (the structure must thus be an array).
value | value |
|
inline |
Adds a JSON null object (==Python's "None")
|
inline |
Helper to put the number of query_block in an object.
select_number | number of query_block |
|
inline |
Variant of add_utf8() where 'value' is 0-terminated.
|
inline |
Like add_alnum() but supports any UTF8 characters in 'value'.
Will "escape" 'value' to be JSON-compliant.
key | key |
value | value |
val_length | length of string 'value' |
|
inline |
Variant of add_utf8() where 'value' is 0-terminated.
|
inline |
Variant of add_utf8() for adding to an array (no key)
|
inline |
Helper to put the database/table name in an object.
tab | TABLE* pointer |
const char * Opt_trace_struct::check_key | ( | const char * | key | ) |
Validates the key about to be added.
When adding a value (or array or object) to an array, or a key/value pair to an object, we need to know this outer array or object.
It would be possible, when trying to add a key to an array, which is wrong in JSON, or similarly when trying to add a value without any key to an object, to catch it at compilation time, if the adder received, as function parameter, the type of the structure (like Opt_trace_array*
). Then the add(key,val)
call would not compile as Opt_trace_array wouldn't feature it.
But as explained in comment of class Opt_trace_context we cannot pass down the object, have to maintain a "current object or array" in the Opt_trace_context context (pointer to an instance of Opt_trace_struct), and the adder grabs it from the context.
As this current structure is of type "object or array", we cannot do compile-time checks that only suitable functions are used. A call to add(key,value)
is necessarily legal for the compiler as the structure may be an object, though it will be wrong in case the structure is actually an array at run-time. Thus we have the risk of an untested particular situation where the current structure is not an object (but an array) though the code expected it to be one. This happens in practice, because subqueries are evaluated in many possible places of code, not all of them being known. Same happens, to a lesser extent, with calls to the range optimizer. So at run-time, in check_key(), we detect wrong usage, like adding a value to an object without specifying a key, and then remove the unnecessary key, or add an autogenerated key.
|
private |
|
private |
Really adds to the object.
key | key |
value | value |
val_length | length of string 'value' |
escape | do JSON-compliant escaping of 'value'. If 'escape' is false, 'value' should be ASCII. Otherwise, should be UTF8. |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
Full initialization.
|
private |
Really does destruction.
|
inline |
The exception to RAII: this function is an explicit way of ending a structure before it goes out of scope.
Don't use it unless RAII mandates a new scope which mandates re-indenting lots of code lines.
|
private |
not defined
|
inline |
Informs this structure that we are adding data (scalars, structures) to it.
This is used only if sending to I_S.
|
private |
|
private |
Whether this structure caused tracing to be disabled in this statement because belonging to a not-traced optimizer feature, in accordance with the value of @@optimizer_trace_features.
|
private |
Fixed-length prefix of previous key in this structure, if this structure is an object.
Serves to detect when adding two same consecutive keys to an object, which would be wrong.
|
private |
Whether the structure requires/forbids keys for values inside it.
true: this is an object. false: this is an array.
|
private |
Key if the structure is the value of a key/value pair, NULL otherwise.
|
private |
Whether the structure does tracing or is dummy.
|
private |
Trace owning the structure.