MySQL  8.0.27
Source Code Documentation
user_var_entry Class Reference

#include <item_func.h>

Public Member Functions

 user_var_entry ()=default
 
THDowner_session () const
 
bool store (const void *ptr, size_t length, Item_result type, const CHARSET_INFO *cs, Derivation dv, bool unsigned_arg)
 Set value to user variable. More...
 
void set_type (Item_result type)
 Set type of to the given value. More...
 
void set_null_value (Item_result type)
 Set value to NULL. More...
 
void set_used_query_id (query_id_t query_id)
 
query_id_t used_query_id () const
 
void destroy ()
 Free all memory used by a user_var_entry instance previously created by create(). More...
 
void lock ()
 
void unlock ()
 
const char * ptr () const
 
size_t length () const
 
Item_result type () const
 
double val_real (bool *null_value) const
 Get the value of a variable as a double. More...
 
longlong val_int (bool *null_value) const
 Get the value of a variable as an integer. More...
 
Stringval_str (bool *null_value, String *str, uint decimals) const
 Get the value of a variable as a string. More...
 
my_decimalval_decimal (bool *null_value, my_decimal *result) const
 Get the value of a variable as a decimal. More...
 

Static Public Member Functions

static user_var_entrycreate (THD *thd, const Name_string &name, const CHARSET_INFO *cs)
 Allocates and initializes a user variable instance. More...
 

Public Attributes

Simple_cstring entry_name
 
DTCollation collation
 
bool unsigned_flag
 

Private Member Functions

void reset_value ()
 
void set_value (char *value, size_t length)
 
char * internal_buffer_ptr ()
 Position inside a user_var_entry where small values are stored: double values, longlong values and string values with length up to extra_size (should be 8 bytes on all platforms). More...
 
char * name_ptr ()
 Position inside a user_var_entry where a null-terminates array of characters representing the variable name is stored. More...
 
bool mem_realloc (size_t length)
 Initialize m_ptr to the internal buffer (if the value is small enough), or allocate a separate buffer. More...
 
bool alloced ()
 Check if m_ptr point to an external buffer previously alloced by realloc(). More...
 
void free_value ()
 Free the external value buffer, if it's allocated. More...
 
void copy_name (const Simple_cstring &name)
 Copy the array of characters from the given name into the internal name buffer and initialize entry_name to point to it. More...
 
void init (THD *thd, const Simple_cstring &name, const CHARSET_INFO *cs)
 Initialize all members. More...
 
bool store (const void *from, size_t length, Item_result type)
 Store a value of the given type into a user_var_entry instance. More...
 
void assert_locked () const
 Assert the user variable is locked. More...
 

Private Attributes

char * m_ptr
 Value. More...
 
size_t m_length
 Value length. More...
 
Item_result m_type
 Value type. More...
 
THDm_owner
 
query_id_t m_used_query_id
 Set to the id of the most recent query that has used the variable. More...
 

Static Private Attributes

static const size_t extra_size = sizeof(double)
 

Constructor & Destructor Documentation

◆ user_var_entry()

user_var_entry::user_var_entry ( )
default

Member Function Documentation

◆ alloced()

bool user_var_entry::alloced ( )
inlineprivate

Check if m_ptr point to an external buffer previously alloced by realloc().

Return values
true- an external buffer is alloced.
false- m_ptr is null, or points to the internal buffer.

◆ assert_locked()

void user_var_entry::assert_locked ( ) const
private

Assert the user variable is locked.

This is debug code only. The thread LOCK_thd_data mutex protects:

  • the thd->user_vars hash itself
  • the values in the user variable itself. The protection is required for monitoring, as a different thread can inspect this session user variables, on a live session.

◆ copy_name()

void user_var_entry::copy_name ( const Simple_cstring name)
inlineprivate

Copy the array of characters from the given name into the internal name buffer and initialize entry_name to point to it.

◆ create()

user_var_entry * user_var_entry::create ( THD thd,
const Name_string name,
const CHARSET_INFO cs 
)
static

Allocates and initializes a user variable instance.

Parameters
thdCurrent session.
nameName of the variable.
csCharset of the variable.
Returns
Address of the allocated and initialized user_var_entry instance.
Return values
NULLOn allocation error.

◆ destroy()

void user_var_entry::destroy ( )
inline

Free all memory used by a user_var_entry instance previously created by create().

◆ free_value()

void user_var_entry::free_value ( )
inlineprivate

Free the external value buffer, if it's allocated.

◆ init()

void user_var_entry::init ( THD thd,
const Simple_cstring name,
const CHARSET_INFO cs 
)
private

Initialize all members.

Parameters
thdCurrent session.
nameName of the user_var_entry instance.
cscharset information of the user_var_entry instance.

◆ internal_buffer_ptr()

char* user_var_entry::internal_buffer_ptr ( )
inlineprivate

Position inside a user_var_entry where small values are stored: double values, longlong values and string values with length up to extra_size (should be 8 bytes on all platforms).

String values with length longer than 8 are stored in a separate memory buffer, which is allocated when needed using the method realloc().

◆ length()

size_t user_var_entry::length ( ) const
inline

◆ lock()

void user_var_entry::lock ( )

◆ mem_realloc()

bool user_var_entry::mem_realloc ( size_t  length)
private

Initialize m_ptr to the internal buffer (if the value is small enough), or allocate a separate buffer.

Parameters
length- length of the value to be stored.

◆ name_ptr()

char* user_var_entry::name_ptr ( )
inlineprivate

Position inside a user_var_entry where a null-terminates array of characters representing the variable name is stored.

◆ owner_session()

THD* user_var_entry::owner_session ( ) const
inline

◆ ptr()

const char* user_var_entry::ptr ( ) const
inline

◆ reset_value()

void user_var_entry::reset_value ( )
inlineprivate

◆ set_null_value()

void user_var_entry::set_null_value ( Item_result  type)
inline

Set value to NULL.

Parameters
typeData type.

◆ set_type()

void user_var_entry::set_type ( Item_result  type)
inline

Set type of to the given value.

Parameters
typeData type.

◆ set_used_query_id()

void user_var_entry::set_used_query_id ( query_id_t  query_id)
inline

◆ set_value()

void user_var_entry::set_value ( char *  value,
size_t  length 
)
inlineprivate

◆ store() [1/2]

bool user_var_entry::store ( const void *  from,
size_t  length,
Item_result  type 
)
private

Store a value of the given type into a user_var_entry instance.

Parameters
fromValue
lengthSize of the value
typetype
Return values
falseon success
trueon memory allocation error

◆ store() [2/2]

bool user_var_entry::store ( const void *  ptr,
size_t  length,
Item_result  type,
const CHARSET_INFO cs,
Derivation  dv,
bool  unsigned_arg 
)

Set value to user variable.

Parameters
ptrpointer to buffer with new value
lengthlength of new value
typetype of new value
cscharset info for new value
dvderivation for new value
unsigned_argindiates if a value of type INT_RESULT is unsigned
Note
Sets error and fatal error if allocation fails.
Return values
falsesuccess
truefailure

◆ type()

Item_result user_var_entry::type ( ) const
inline

◆ unlock()

void user_var_entry::unlock ( )

◆ used_query_id()

query_id_t user_var_entry::used_query_id ( ) const
inline

◆ val_decimal()

my_decimal * user_var_entry::val_decimal ( bool *  null_value,
my_decimal result 
) const

Get the value of a variable as a decimal.

◆ val_int()

longlong user_var_entry::val_int ( bool *  null_value) const

Get the value of a variable as an integer.

◆ val_real()

double user_var_entry::val_real ( bool *  null_value) const

Get the value of a variable as a double.

◆ val_str()

String * user_var_entry::val_str ( bool *  null_value,
String str,
uint  decimals 
) const

Get the value of a variable as a string.

Member Data Documentation

◆ collation

DTCollation user_var_entry::collation

◆ entry_name

Simple_cstring user_var_entry::entry_name

◆ extra_size

const size_t user_var_entry::extra_size = sizeof(double)
staticprivate

◆ m_length

size_t user_var_entry::m_length
private

Value length.

◆ m_owner

THD* user_var_entry::m_owner
private

◆ m_ptr

char* user_var_entry::m_ptr
private

Value.

◆ m_type

Item_result user_var_entry::m_type
private

Value type.

◆ m_used_query_id

query_id_t user_var_entry::m_used_query_id
private

Set to the id of the most recent query that has used the variable.

Used in binlogging: When set, there is no need to add a reference to this variable to the binlog. Imagine it is this:

INSERT INTO t SELECT @a:=10, @a:=@a+1.

Then we have a Item_func_get_user_var (because of the @a+1) so we think we have to write the value of @a to the binlog. But before that, we have a Item_func_set_user_var to create @a (@a:=10), in this we mark the variable as "already logged" so that it won't be logged by Item_func_get_user_var (because that's not necessary).

◆ unsigned_flag

bool user_var_entry::unsigned_flag

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