MySQL 8.0.29
Source Code Documentation
Opt_trace_stmt Class Reference

The trace of one statement. More...

Public Member Functions

 Opt_trace_stmt (Opt_trace_context *ctx_arg)
 Constructor, starts a trace for information_schema and dbug. More...
 
void end ()
 Ends a trace; destruction may not be possible immediately as we may have to keep the trace in case the user later reads it from I_S. More...
 
bool has_ended () const
 
void set_allowed_mem_size (size_t size)
 Sets the quantity of allowed memory for this trace. More...
 
void set_query (const char *query, size_t length, const CHARSET_INFO *charset)
 
bool open_struct (const char *key, Opt_trace_struct *ots, bool wants_disable_I_S, char opening_bracket)
 When creating an Opt_trace_struct: adds a key and the opening bracket to the trace buffer, updates current_struct. More...
 
void close_struct (const char *saved_key, bool has_disabled_I_S, char closing_bracket)
 When closing an Opt_trace_struct: More...
 
void separator ()
 Put optional comma, newline and indentation. More...
 
void next_line ()
 Put newline and indentation. More...
 
void add (const char *key, const char *val, size_t val_length, bool quotes, bool escape)
 Adds a key/value pair to the trace buffer. More...
 
void fill_info (Opt_trace_info *info) const
 Fills user-level information. More...
 
const char * trace_buffer_tail (size_t size)
 
size_t alloced_length () const
 
void assert_current_struct (const Opt_trace_struct *s) const
 
void missing_privilege ()
 
bool support_I_S () const
 
void disable_I_S ()
 Temporarily disables I_S output for this statement. More...
 
void restore_I_S ()
 Restores I_S support to what it was before the previous call to disable_I_S(). More...
 
const char * make_unknown_key ()
 Generate a dummy unique key, and return pointer to it. More...
 

Private Attributes

bool ended
 Whether end() has been called on this instance. More...
 
int I_S_disabled
 0 <=> this trace should be in information_schema. More...
 
bool missing_priv
 whether user lacks privilege to see this trace More...
 
Opt_trace_contextctx
 context More...
 
Opt_trace_structcurrent_struct
 current open structure More...
 
Prealloced_array< Opt_trace_struct *, 16 > stack_of_current_structs
 Same logic as Opt_trace_context::stack_of_current_stmts. More...
 
Buffer trace_buffer
 Where the trace is accumulated. More...
 
Buffer query_buffer
 Where the original query is put. More...
 
uint unknown_key_count
 Counter which serves to have unique autogenerated keys, needed if we autogenerate more than one key in a single object. More...
 
char unknown_key [24]
 Space for last autogenerated key. More...
 

Detailed Description

The trace of one statement.

For example, executing a stored procedure containing 3 sub-statements will produce 4 traces (one for the CALL statement, one for each sub-statement), so 4 Opt_trace_stmt linked together into Opt_trace_context's lists.

Constructor & Destructor Documentation

◆ Opt_trace_stmt()

Opt_trace_stmt::Opt_trace_stmt ( Opt_trace_context ctx_arg)

Constructor, starts a trace for information_schema and dbug.

Parameters
ctx_argcontext

Member Function Documentation

◆ add()

void Opt_trace_stmt::add ( const char *  key,
const char *  val,
size_t  val_length,
bool  quotes,
bool  escape 
)

Adds a key/value pair to the trace buffer.

Parameters
keykey or NULL
valrepresentation of value as string
val_lengthlength of value
quotesshould value be delimited with '"' (false when the value is the representation of a number, boolean or null)
escapedoes value need escaping (has special characters)
Note
Structures prepare a string representation of their value-to-add and call this function.

◆ alloced_length()

size_t Opt_trace_stmt::alloced_length ( ) const
inline
Returns
total memory used by this trace

◆ assert_current_struct()

void Opt_trace_stmt::assert_current_struct ( const Opt_trace_struct s) const
inline

◆ close_struct()

void Opt_trace_stmt::close_struct ( const char *  saved_key,
bool  has_disabled_I_S,
char  closing_bracket 
)

When closing an Opt_trace_struct:

  • adds the closing bracket and optionally the key to the trace buffer
  • re-enables I_S output if the dying structure had disabled it
  • updates current_struct.
    Parameters
    saved_keykey or NULL
    has_disabled_I_Swhether structure had disabled I_S output
    closing_bracketclosing bracket to use

◆ disable_I_S()

void Opt_trace_stmt::disable_I_S ( )
inline

Temporarily disables I_S output for this statement.

◆ end()

void Opt_trace_stmt::end ( void  )

Ends a trace; destruction may not be possible immediately as we may have to keep the trace in case the user later reads it from I_S.

◆ fill_info()

void Opt_trace_stmt::fill_info ( Opt_trace_info info) const

Fills user-level information.

See also
Opt_trace_iterator

◆ has_ended()

bool Opt_trace_stmt::has_ended ( ) const
inline
Returns
whether end() has been called on this instance.

◆ make_unknown_key()

const char * Opt_trace_stmt::make_unknown_key ( )

Generate a dummy unique key, and return pointer to it.

The pointed data has the lifetime of Opt_trace_stmt, and is overwritten by the next call to this function.

◆ missing_privilege()

void Opt_trace_stmt::missing_privilege ( )
See also
Opt_trace_context::missing_privilege()

◆ next_line()

void Opt_trace_stmt::next_line ( )

Put newline and indentation.

◆ open_struct()

bool Opt_trace_stmt::open_struct ( const char *  key,
Opt_trace_struct ots,
bool  wants_disable_I_S,
char  opening_bracket 
)

When creating an Opt_trace_struct: adds a key and the opening bracket to the trace buffer, updates current_struct.

Parameters
keykey or NULL
otsstructure being created
wants_disable_I_Swhether structure wants to disable I_S output
opening_bracketopening bracket to use
Return values
falseok
trueerror, Opt_trace_struct must set itself to dummy; trace may have been written to, will likely be invalid JSON.

◆ restore_I_S()

void Opt_trace_stmt::restore_I_S ( )
inline

Restores I_S support to what it was before the previous call to disable_I_S().

◆ separator()

void Opt_trace_stmt::separator ( )

Put optional comma, newline and indentation.

◆ set_allowed_mem_size()

void Opt_trace_stmt::set_allowed_mem_size ( size_t  size)

Sets the quantity of allowed memory for this trace.

◆ set_query()

void Opt_trace_stmt::set_query ( const char *  query,
size_t  length,
const CHARSET_INFO charset 
)
See also
Opt_trace_context::set_query()

◆ support_I_S()

bool Opt_trace_stmt::support_I_S ( ) const
inline

◆ trace_buffer_tail()

const char * Opt_trace_stmt::trace_buffer_tail ( size_t  size)
Returns
'size' last bytes of the trace buffer

Member Data Documentation

◆ ctx

Opt_trace_context* Opt_trace_stmt::ctx
private

context

◆ current_struct

Opt_trace_struct* Opt_trace_stmt::current_struct
private

current open structure

◆ ended

bool Opt_trace_stmt::ended
private

Whether end() has been called on this instance.

◆ I_S_disabled

int Opt_trace_stmt::I_S_disabled
private

0 <=> this trace should be in information_schema.

In the life of an Opt_trace_stmt, support for I_S may be temporarily disabled. Once disabled, it must stay disabled until re-enabled at the same stack frame. This: Opt_trace_object1 // disables I_S Opt_trace_object2 // re-enables I_S is impossible (the top object wins). So it is sufficient, to keep track of the current state, to have a counter incremented each time we get a request to disable I_S.

◆ missing_priv

bool Opt_trace_stmt::missing_priv
private

whether user lacks privilege to see this trace

◆ query_buffer

Buffer Opt_trace_stmt::query_buffer
private

Where the original query is put.

◆ stack_of_current_structs

Prealloced_array<Opt_trace_struct *, 16> Opt_trace_stmt::stack_of_current_structs
private

Same logic as Opt_trace_context::stack_of_current_stmts.

◆ trace_buffer

Buffer Opt_trace_stmt::trace_buffer
private

Where the trace is accumulated.

◆ unknown_key

char Opt_trace_stmt::unknown_key[24]
private

Space for last autogenerated key.

◆ unknown_key_count

uint Opt_trace_stmt::unknown_key_count
private

Counter which serves to have unique autogenerated keys, needed if we autogenerate more than one key in a single object.

See also
Opt_trace_struct::check_key() and
Opt_trace_stmt::add() .

The documentation for this class was generated from the following file: