MySQL 9.1.0
Source Code Documentation
rpl_utility.cc File Reference
#include "sql/rpl_utility.h"
#include <string.h>
#include <iterator>
#include <new>
#include <regex>
#include <utility>
#include "lex_string.h"
#include "my_byteorder.h"
#include "my_dbug.h"
#include "my_sys.h"
#include "mysql/binlog/event/export/binary_log_funcs.h"
#include "mysql/components/services/log_builtins.h"
#include "mysql/my_loglevel.h"
#include "mysql/service_mysql_alloc.h"
#include "sql/thr_malloc.h"
#include <algorithm>
#include "m_string.h"
#include "my_base.h"
#include "my_bitmap.h"
#include "mysql/binlog/event/binlog_event.h"
#include "mysql/psi/psi_memory.h"
#include "mysql/strings/m_ctype.h"
#include "mysqld_error.h"
#include "sql-common/my_decimal.h"
#include "sql/changestreams/misc/replicated_columns_view_factory.h"
#include "sql/create_field.h"
#include "sql/dd/dd.h"
#include "sql/dd/dictionary.h"
#include "sql/derror.h"
#include "sql/field.h"
#include "sql/log.h"
#include "sql/log_event.h"
#include "sql/mysqld.h"
#include "sql/psi_memory_key.h"
#include "sql/rpl_replica.h"
#include "sql/rpl_rli.h"
#include "sql/sql_class.h"
#include "sql/sql_const.h"
#include "sql/sql_gipk.h"
#include "sql/sql_lex.h"
#include "sql/sql_list.h"
#include "sql/sql_plugin_ref.h"
#include "sql/sql_tmp_table.h"
#include "sql_show.h"
#include "sql_string.h"
#include "template_utils.h"
#include "typelib.h"

Macros

#define HASH_ROWS_POS_SEARCH_INVALID   -1
 

Functions

static int compare (size_t a, size_t b)
 Function to compare two size_t integers for their relative order. More...
 
static int compare_lengths (Field *field, enum_field_types source_type, uint16 metadata)
 
static bool is_conversion_ok (int order)
 Check the order variable and print errors if the order is not acceptable according to the current settings. More...
 
bool timestamp_cross_check (enum_field_types type1, enum_field_types type2)
 Check if the types are criss cross means type1 is MYSQL_TYPE_TIMESTAMP and type2 as MYSQL_TYPE_TIMESTAMP2 or vice versa. More...
 
bool datetime_cross_check (enum_field_types type1, enum_field_types type2)
 Check if the types are criss cross means type1 is MYSQL_TYPE_DATETIME and type2 as MYSQL_TYPE_DATETIME or vice versa. More...
 
bool time_cross_check (enum_field_types type1, enum_field_types type2)
 Check if the types are criss cross means type1 is MYSQL_TYPE_TIME and type2 as MYSQL_TYPE_TIME2 or vice versa. More...
 
static bool can_convert_field_to (Field *field, enum_field_types source_type, uint metadata, bool is_array, Relay_log_info *rli, uint16 mflags, unsigned int vector_dimensionality, int *order_var)
 Can a type potentially be converted to another type? More...
 
std::pair< my_off_t, std::pair< uint, bool > > read_field_metadata (const uchar *buffer, enum_field_types binlog_type)
 Decode field metadata from a char buffer (serialized form) into an int (packed form). More...
 
std::string replace_all_in_str (std::string from, std::string find, std::string replace)
 Replaces every occurrence of the string find by the string replace, within the string from and return the resulting string. More...
 
bool is_require_row_format_violation (const THD *thd)
 This method shall evaluate if a command being executed goes against any of the restrictions of server variable session.require_row_format. More...
 
bool is_immediate_server_gipk_ready (THD &thd)
 Checks if the immediate_server_version supports GIPKs or not. More...
 
bool does_source_table_contain_gipk (Relay_log_info const *rli, TABLE *table)
 Returns if the replicated table contains a GIPK or not. More...
 
std::string decimal_numeric_version_to_string (uint32 version)
 Returns a string representation for a given version. More...
 

Variables

PSI_memory_key key_memory_table_def_memory
 

Macro Definition Documentation

◆ HASH_ROWS_POS_SEARCH_INVALID

#define HASH_ROWS_POS_SEARCH_INVALID   -1

Function Documentation

◆ can_convert_field_to()

static bool can_convert_field_to ( Field field,
enum_field_types  source_type,
uint  metadata,
bool  is_array,
Relay_log_info rli,
uint16  mflags,
unsigned int  vector_dimensionality,
int *  order_var 
)
static

Can a type potentially be converted to another type?

This function check if the types are convertible and what conversion is required.

If conversion is not possible, and error is printed.

If conversion is possible:

  • *order will be set to -1 if source type is smaller than target type and a non-lossy conversion can be required. This includes the case where the field types are different but types could actually be converted in either direction.
  • *order will be set to 0 if no conversion is required.
  • *order will be set to 1 if the source type is strictly larger than the target type and that conversion is potentially lossy.
Parameters
[in]fieldTarget field
[in]source_typeSource field type
[in]metadataSource field metadata
[in]is_arrayWhether the source field is a typed array
[in]rliRelay log info (for error reporting)
[in]mflagsFlags from the table map event
[in]vector_dimensionalityDimensionality of vector column
[out]order_varOrder between source field and target field
Returns
true if conversion is possible according to the current settings, false if conversion is not possible according to the current setting.

◆ compare()

static int compare ( size_t  a,
size_t  b 
)
static

Function to compare two size_t integers for their relative order.

Used below.

◆ compare_lengths()

static int compare_lengths ( Field field,
enum_field_types  source_type,
uint16  metadata 
)
static

◆ datetime_cross_check()

bool datetime_cross_check ( enum_field_types  type1,
enum_field_types  type2 
)
inline

Check if the types are criss cross means type1 is MYSQL_TYPE_DATETIME and type2 as MYSQL_TYPE_DATETIME or vice versa.

◆ decimal_numeric_version_to_string()

std::string decimal_numeric_version_to_string ( uint32  version)

Returns a string representation for a given version.

Parameters
versiona version represented using a integer
Returns
a string for the given version or "unknown" if version is undefined or unknown.

◆ does_source_table_contain_gipk()

bool does_source_table_contain_gipk ( Relay_log_info const *  rli,
TABLE table 
)

Returns if the replicated table contains a GIPK or not.

Note
for servers of older versions that do not fully support GIPK, this method returns a guess based on available information replication has.
Parameters
rliThe relay log object associated to the channel
tableThe table to check for the GIPK
Returns
true if we believe the table has a GIPK, false otherwise.

◆ is_conversion_ok()

static bool is_conversion_ok ( int  order)
static

Check the order variable and print errors if the order is not acceptable according to the current settings.

Parameters
orderThe computed order of the conversion needed.

◆ is_immediate_server_gipk_ready()

bool is_immediate_server_gipk_ready ( THD thd)

Checks if the immediate_server_version supports GIPKs or not.

Parameters
thdThe THD context to check the version
Returns
true if the source server supports GIPK, false otherwise

◆ is_require_row_format_violation()

bool is_require_row_format_violation ( const THD thd)

This method shall evaluate if a command being executed goes against any of the restrictions of server variable session.require_row_format.

Parameters
thdThe thread associated to the command
Returns
true if it violates any restrictions false otherwise

◆ read_field_metadata()

std::pair< my_off_t, std::pair< uint, bool > > read_field_metadata ( const uchar buffer,
enum_field_types  binlog_type 
)

Decode field metadata from a char buffer (serialized form) into an int (packed form).

Note
On little-endian platforms (e.g Intel) this function effectively inverts order of bytes compared to what Field::save_field_metadata() writes. E.g for MYSQL_TYPE_NEWDECIMAL save_field_metadata writes precision into the first byte and decimals into the second, this function puts precision into the second byte and decimals into the first. This layout is expected by replication code that reads metadata in the uint form. Due to this design feature show_sql_type() can't correctly print immediate output of save_field_metadata(), this function have to be used as translator.
Parameters
bufferField metadata, in the character stream form produced by save_field_metadata.
binlog_typeThe type of the field, in the form returned by Field::binlog_type and stored in Table_map_log_event.
Return values
pairwhere:
  • the first component is the length of the metadata within 'buffer', i.e., how much the buffer pointer should move forward in order to skip it.
  • the second component is pair containing:
    • the metadata, encoded as an 'uint', in the form required by e.g. show_sql_type.
    • bool indicating whether the field is array (true) or a scalar (false)

◆ replace_all_in_str()

std::string replace_all_in_str ( std::string  from,
std::string  find,
std::string  replace 
)

Replaces every occurrence of the string find by the string replace, within the string from and return the resulting string.

The original string from remains untouched.

Parameters
fromthe string to search within.
findthe string to search for.
replacethe string to replace every occurrence of from
Returns
a new string, holding the result of the search and replace operation.

◆ time_cross_check()

bool time_cross_check ( enum_field_types  type1,
enum_field_types  type2 
)
inline

Check if the types are criss cross means type1 is MYSQL_TYPE_TIME and type2 as MYSQL_TYPE_TIME2 or vice versa.

◆ timestamp_cross_check()

bool timestamp_cross_check ( enum_field_types  type1,
enum_field_types  type2 
)
inline

Check if the types are criss cross means type1 is MYSQL_TYPE_TIMESTAMP and type2 as MYSQL_TYPE_TIMESTAMP2 or vice versa.

Variable Documentation

◆ key_memory_table_def_memory

PSI_memory_key key_memory_table_def_memory