MySQL 8.4.2
Source Code Documentation
default_values.h
Go to the documentation of this file.
1/* Copyright (c) 2015, 2024, Oracle and/or its affiliates.
2
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License, version 2.0,
5 as published by the Free Software Foundation.
6
7 This program is designed to work with certain software (including
8 but not limited to OpenSSL) that is licensed under separate terms,
9 as designated in a particular file or component or in included license
10 documentation. The authors of MySQL hereby grant you an additional
11 permission to link the program and your derivative works with the
12 separately licensed software that they have either included with
13 the program or referenced in the documentation.
14
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License, version 2.0, for more details.
19
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
23
24#ifndef DEFAULT_VALUES_INCLUDED
25#define DEFAULT_VALUES_INCLUDED
26
27#include <stddef.h>
28
29#include "my_inttypes.h"
30
31/** Forward declarations. */
32
33class Create_field;
34class THD;
35template <class T>
36class List;
37
38namespace dd {
39class Column;
40class Table;
41} // namespace dd
42struct TABLE;
43struct TABLE_SHARE;
44
45/**
46 Find the largest field among a list of create fields.
47
48 Iterates over the list of create fields and find the largest one, i.e.
49 the field with largest pack length.
50
51 @param create_fields List of create fields.
52 @return Size of the largest field, as number of bytes.
53*/
54
55size_t max_pack_length(const List<Create_field> &create_fields);
56
57/**
58 Prepare the default value of a single column.
59
60 This function creates a fake field using the submitted fake table
61 object, which also has assigned a fake table share. The field is
62 create in order to use existing code to store the default value. The
63 value is stored into the submitted buffer, which has been allocated
64 in advance (and will be deleted afterwards). The fake table and
65 share are required by the field infrastructure.
66
67 After storing the default value into the buffer, the value is read back
68 and copied into the column object's default value field. For bit fields
69 with leftover bits in the preamble, these bits are copied and appended
70 onto the default value as the last byte.
71
72 @param thd Thread context.
73 @param buf Buffer to store the default value into. The buffer
74 size must be at least two bytes.
75 @param table Fake table to use when storing the default value.
76 @param field Create_field corresponding to the column object.
77 @param [in,out] col_obj Column for which to prepare the default value.
78
79 @retval true Failure.
80 @retval false Success.
81*/
82
84 const Create_field &field, dd::Column *col_obj);
85
86/**
87 Prepare the default value buffer for an empty record.
88
89 This function prepares the buffer based on the objects retrieved from the
90 data dictionary. The function will scan the columns of the submitted table
91 objects and calculate the length of the record, the number of null bits,
92 etc. The empty buffer is allocated, and all bits are set to 0, including
93 used null bits, the actual field values, etc. Afterwards, the unused bits
94 in the preamble, up to the next full byte border, are set to 1. Finally,
95 the buffer is assigned to the 'TABLE_SHARE::default_values' field.
96
97 @note This function does not fill in the actual default values, it just
98 allocates and prepares the buffer.
99
100 @param thd Thread context.
101 @param table Table for which the default value buffer should
102 be prepared.
103 @param [in,out] share Table share for the table. The default value
104 buffer is assigned to the appropriate table
105 share field.
106
107 @retval true Failure.
108 @retval false Success.
109*/
110
112 const dd::Table &table,
113 TABLE_SHARE *share);
114
115#endif /* DEFAULT_VALUES_INCLUDED */
Create_field is a description a field/column that may or may not exists in a table.
Definition: create_field.h:51
Definition: sql_list.h:467
For each client connection we create a separate thread with THD serving as a thread/connection descri...
Definition: sql_lexer_thd.h:36
Definition: column.h:87
Definition: table.h:47
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.
Definition: default_values.cc:189
size_t max_pack_length(const List< Create_field > &create_fields)
Find the largest field among a list of create fields.
Definition: default_values.cc:180
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.
Definition: default_values.cc:263
Some integer typedefs for easier portability.
unsigned char uchar
Definition: my_inttypes.h:52
static PFS_engine_table_share_proxy table
Definition: pfs.cc:61
Definition: buf0block_hint.cc:30
The version of the current data dictionary table definitions.
Definition: dictionary_client.h:43
This structure is shared between different table objects.
Definition: table.h:701
Field ** field
Definition: table.h:749
Definition: table.h:1406