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