MySQL 9.1.0
Source Code Documentation
|
#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... | |
|
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.
col_obj | The column object for which we calculate the in-memory length. |
|
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.
table | A single table, with column data members. | |
min_length | The minimum length of a record. | |
[out] | share | Table share with various length fields assigned. |
true | Failure. |
false | Success. |
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.
create_fields | List of create fields. |
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.
thd | Thread context. | |
buf | Buffer to store the default value into. The buffer size must be at least two bytes. | |
table | Fake table to use when storing the default value. | |
field | Create_field corresponding to the column object. | |
[in,out] | col_obj | Column for which to prepare the default value. |
true | Failure. |
false | Success. |
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.
thd | Thread context. | |
table | Table for which the default value buffer should be prepared. | |
[in,out] | share | Table share for the table. The default value buffer is assigned to the appropriate table share field. |
true | Failure. |
false | Success. |
|
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.
pack_record | If the HA_OPTION_PACK_RECORD is set. | |
preamble_bits | Number of null bits and leftover bits. | |
[in,out] | default_values | The default value buffer. |