MySQL 9.1.0
Source Code Documentation
default_values.cc File Reference
#include "sql/default_values.h"
#include <assert.h>
#include <string.h>
#include <sys/types.h>
#include <algorithm>
#include "my_alloc.h"
#include "my_base.h"
#include "my_compare.h"
#include "my_macros.h"
#include "my_pointer_arithmetic.h"
#include "my_sys.h"
#include "mysql/strings/dtoa.h"
#include "mysql_com.h"
#include "mysqld_error.h"
#include "sql/create_field.h"
#include "sql/dd/properties.h"
#include "sql/dd/string_type.h"
#include "sql/dd/types/column.h"
#include "sql/dd/types/table.h"
#include "sql/dd_table_share.h"
#include "sql/field.h"
#include "sql/gis/srid.h"
#include "sql/handler.h"
#include "sql/item.h"
#include "sql/sql_class.h"
#include "sql/sql_list.h"
#include "sql/table.h"

Functions

static size_t column_pack_length (const dd::Column &col_obj)
 Calculate the length of the in-memory representation of the column from its dd::Column object. More...
 
static bool find_record_length (const dd::Table &table, size_t min_length, TABLE_SHARE *share)
 Find the required length of an empty record. More...
 
static void set_pack_record_and_unused_preamble_bits (bool pack_record, ulong preamble_bits, uchar *default_values)
 Set the unused bits in the preamble of a default value buffer. More...
 
size_t max_pack_length (const List< Create_field > &create_fields)
 Find the largest field among a list of create fields. More...
 
bool prepare_default_value (THD *thd, uchar *buf, TABLE *table, const Create_field &field, dd::Column *col_obj)
 Prepare the default value of a single column. More...
 
bool prepare_default_value_buffer_and_table_share (THD *thd, const dd::Table &table, TABLE_SHARE *share)
 Prepare the default value buffer for an empty record. More...
 

Function Documentation

◆ column_pack_length()

static size_t column_pack_length ( const dd::Column col_obj)
static

Calculate the length of the in-memory representation of the column from its dd::Column object.

This function calculates the amount of memory necessary to store values of the submitted column. The function is used when preparing the default values for the columns of a table, and for determining the size of an empty record for the table which the column is a part of.

Parameters
col_objThe column object for which we calculate the in-memory length.
Returns
In-memory length of values of the submitted column.

◆ find_record_length()

static bool find_record_length ( const dd::Table table,
size_t  min_length,
TABLE_SHARE share 
)
static

Find the required length of an empty record.

This function iterates over the columns of the table, finds the required number of null bits and leftover bits, and adds up the total length of an empty record. Various length related fields in the table share parameter are assigned.

Parameters
tableA single table, with column data members.
min_lengthThe minimum length of a record.
[out]shareTable share with various length fields assigned.
Return values
trueFailure.
falseSuccess.

◆ max_pack_length()

size_t max_pack_length ( const List< Create_field > &  create_fields)

Find the largest field among a list of create fields.

Iterates over the list of create fields and find the largest one, i.e. the field with largest pack length.

Parameters
create_fieldsList of create fields.
Returns
Size of the largest field, as number of bytes.

◆ prepare_default_value()

bool prepare_default_value ( THD thd,
uchar buf,
TABLE table,
const Create_field field,
dd::Column col_obj 
)

Prepare the default value of a single column.

This function creates a fake field using the submitted fake table object, which also has assigned a fake table share. The field is create in order to use existing code to store the default value. The value is stored into the submitted buffer, which has been allocated in advance (and will be deleted afterwards). The fake table and share are required by the field infrastructure.

After storing the default value into the buffer, the value is read back and copied into the column object's default value field. For bit fields with leftover bits in the preamble, these bits are copied and appended onto the default value as the last byte.

Parameters
thdThread context.
bufBuffer to store the default value into. The buffer size must be at least two bytes.
tableFake table to use when storing the default value.
fieldCreate_field corresponding to the column object.
[in,out]col_objColumn for which to prepare the default value.
Return values
trueFailure.
falseSuccess.

◆ prepare_default_value_buffer_and_table_share()

bool prepare_default_value_buffer_and_table_share ( THD thd,
const dd::Table table,
TABLE_SHARE share 
)

Prepare the default value buffer for an empty record.

This function prepares the buffer based on the objects retrieved from the data dictionary. The function will scan the columns of the submitted table objects and calculate the length of the record, the number of null bits, etc. The empty buffer is allocated, and all bits are set to 0, including used null bits, the actual field values, etc. Afterwards, the unused bits in the preamble, up to the next full byte border, are set to 1. Finally, the buffer is assigned to the 'TABLE_SHARE::default_values' field.

Note
This function does not fill in the actual default values, it just allocates and prepares the buffer.
Parameters
thdThread context.
tableTable for which the default value buffer should be prepared.
[in,out]shareTable share for the table. The default value buffer is assigned to the appropriate table share field.
Return values
trueFailure.
falseSuccess.

◆ set_pack_record_and_unused_preamble_bits()

static void set_pack_record_and_unused_preamble_bits ( bool  pack_record,
ulong  preamble_bits,
uchar default_values 
)
static

Set the unused bits in the preamble of a default value buffer.

This function will set the unused bits, after the preamble bits and up to the first byte border, to 1. It will also set the 'pack record' bit (the first bit in the preamble).

The number of null bits here is assumed to include the number of bit field bits that do not fit into a whole byte (i.e., number of bits modulo 8) for storage engines that store bits like this in the preamble.

Parameters
pack_recordIf the HA_OPTION_PACK_RECORD is set.
preamble_bitsNumber of null bits and leftover bits.
[in,out]default_valuesThe default value buffer.