MySQL 8.3.0
Source Code Documentation
sql_load.h
Go to the documentation of this file.
1/* Copyright (c) 2006, 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 SQL_LOAD_INCLUDED
24#define SQL_LOAD_INCLUDED
25
26#include <assert.h>
27#include <sys/types.h>
28
29#include "lex_string.h"
30
31#include "my_sqlcommand.h"
33#include "sql/current_thd.h"
34#include "sql/sql_cmd.h" /* Sql_cmd */
35#include "sql/sql_data_change.h" /* enum_duplicates */
36#include "sql/sql_exchange.h" /* sql_exchange */
37#include "sql/sql_lex.h"
38#include "sql/sql_list.h"
39#include "sql_string.h"
40
41class Item;
42class READ_INFO;
43class THD;
44class Table_ref;
45
46class Sql_cmd_load_table final : public Sql_cmd {
47 public:
48 Sql_cmd_load_table(enum_filetype filetype, bool is_local_file,
49 enum_source_type source_type, const LEX_STRING &filename,
50 ulong file_count, bool in_key_order,
51 On_duplicate on_duplicate, Table_ident *table,
52 List<String> *opt_partitions,
53 const CHARSET_INFO *opt_charset,
54 String *opt_xml_rows_identified_by,
55 const Field_separators &field_separators,
56 const Line_separators &line_separators, ulong skip_lines,
57 mem_root_deque<Item *> *opt_fields_or_vars,
58 mem_root_deque<Item *> *opt_set_fields,
59 mem_root_deque<Item *> *opt_set_exprs,
60 List<String> *opt_set_expr_strings, ulong concurrency,
61 ulonglong memory_size, bool is_bulk_operation)
62 : m_exchange(filename.str, false, filetype),
63 m_is_local_file(is_local_file),
64 m_bulk_source(source_type),
65 m_file_count(file_count),
66 m_ordered_data(in_key_order),
68 m_memory_size(memory_size),
69 m_on_duplicate(on_duplicate),
71 m_opt_partitions(opt_partitions),
75 m_opt_set_expr_strings(opt_set_expr_strings),
76 m_is_bulk_operation(is_bulk_operation) {
77 if (opt_fields_or_vars)
78 m_opt_fields_or_vars = std::move(*opt_fields_or_vars);
79 assert((opt_set_fields == nullptr) ^ (opt_set_exprs != nullptr));
80 if (opt_set_fields) {
81 assert(opt_set_fields->size() == opt_set_exprs->size());
82 m_opt_set_fields = std::move(*opt_set_fields);
83 m_opt_set_exprs = std::move(*opt_set_exprs);
84 }
85
86 m_exchange.cs = opt_charset;
87
88 if (opt_xml_rows_identified_by != nullptr)
89 m_exchange.line.line_term = opt_xml_rows_identified_by;
90
91 m_exchange.field.merge_field_separators(field_separators);
92 m_exchange.line.merge_line_separators(line_separators);
93 m_exchange.skip_lines = skip_lines;
94 }
95
96 enum_sql_command sql_command_code() const override { return SQLCOM_LOAD; }
97
98 bool execute(THD *thd) override;
99
100 bool is_bulk_load() const override { return m_is_bulk_operation; }
101
102 public:
104 const bool m_is_local_file;
105
106 private:
107 /// Source for bulk data.
109
110 /// Number of input files.
112
113 /// true if input data is in order of Primary Key.
115
116 /// Number of concurrent loaders to use
118
119 /// Maximum memory size to be used in bytes
121
122 public:
129
130 /**
131 A list of strings is maintained to store the SET clause command user strings
132 which are specified in load data operation. This list will be used
133 during the reconstruction of "load data" statement at the time of writing
134 to binary log.
135 */
137
138 private:
139 bool execute_inner(THD *thd, enum enum_duplicates handle_duplicates);
140
141 bool execute_bulk(THD *thd);
142
143 bool truncate_table_for_bulk_load(THD *thd, Table_ref *const table_ref,
145
147
148 bool validate_table_for_bulk_load(THD *thd, Table_ref *const table_ref,
150
151 bool bulk_driver_service(THD *thd, const TABLE *table, size_t &affected_rows);
152
153 bool read_fixed_length(THD *thd, COPY_INFO &info, Table_ref *table_list,
154 READ_INFO &read_info, ulong skip_lines);
155
156 bool read_sep_field(THD *thd, COPY_INFO &info, Table_ref *table_list,
157 READ_INFO &read_info, const String &enclosed,
158 ulong skip_lines);
159
160 bool read_xml_field(THD *thd, COPY_INFO &info, Table_ref *table_list,
161 READ_INFO &read_info, ulong skip_lines);
162
164 THD *thd, const char *db, const char *table_name, bool is_concurrent,
165 enum enum_duplicates duplicates, bool transactional_table, int errocode);
166
167 private:
168 /// true if BULK LOAD.
170};
171
172#endif /* SQL_LOAD_INCLUDED */
This class encapsulates a data change operation.
Definition: sql_data_change.h:73
Base class that is used to represent any kind of expression in a relational query.
Definition: item.h:933
Definition: sql_list.h:434
Definition: sql_load.cc:131
Definition: sql_load.h:46
sql_exchange m_exchange
Definition: sql_load.h:103
const On_duplicate m_on_duplicate
Definition: sql_load.h:123
bool check_bulk_load_parameters(THD *thd)
Check bulk load parameters for limits.
Definition: sql_load.cc:238
bool is_bulk_load() const override
Definition: sql_load.h:100
mem_root_deque< Item * > m_opt_set_fields
Definition: sql_load.h:127
enum_sql_command sql_command_code() const override
Return the command code for this statement.
Definition: sql_load.h:96
bool read_sep_field(THD *thd, COPY_INFO &info, Table_ref *table_list, READ_INFO &read_info, const String &enclosed, ulong skip_lines)
Read rows in delimiter-separated formats.
Definition: sql_load.cc:1331
bool execute_inner(THD *thd, enum enum_duplicates handle_duplicates)
Execute LOAD DATA query.
Definition: sql_load.cc:602
const bool m_is_local_file
Definition: sql_load.h:104
bool execute_bulk(THD *thd)
Execute BULK LOAD DATA.
Definition: sql_load.cc:354
bool read_fixed_length(THD *thd, COPY_INFO &info, Table_ref *table_list, READ_INFO &read_info, ulong skip_lines)
Read of rows of fixed size + optional garbage + optional newline.
Definition: sql_load.cc:1166
ulong m_concurrency
Number of concurrent loaders to use.
Definition: sql_load.h:117
bool m_ordered_data
true if input data is in order of Primary Key.
Definition: sql_load.h:114
bool truncate_table_for_bulk_load(THD *thd, Table_ref *const table_ref, dd::Table *table_def)
Truncate to create a new table for BULK LOAD.
Definition: sql_load.cc:215
enum_source_type m_bulk_source
Source for bulk data.
Definition: sql_load.h:108
mem_root_deque< Item * > m_opt_set_exprs
Definition: sql_load.h:128
bool read_xml_field(THD *thd, COPY_INFO &info, Table_ref *table_list, READ_INFO &read_info, ulong skip_lines)
Read rows in xml format.
Definition: sql_load.cc:1550
ulong m_file_count
Number of input files.
Definition: sql_load.h:111
bool bulk_driver_service(THD *thd, const TABLE *table, size_t &affected_rows)
Definition: sql_load.cc:478
List< String > *const m_opt_partitions
Definition: sql_load.h:125
Table_ident *const m_table
Definition: sql_load.h:124
ulonglong m_memory_size
Maximum memory size to be used in bytes.
Definition: sql_load.h:120
Sql_cmd_load_table(enum_filetype filetype, bool is_local_file, enum_source_type source_type, const LEX_STRING &filename, ulong file_count, bool in_key_order, On_duplicate on_duplicate, Table_ident *table, List< String > *opt_partitions, const CHARSET_INFO *opt_charset, String *opt_xml_rows_identified_by, const Field_separators &field_separators, const Line_separators &line_separators, ulong skip_lines, mem_root_deque< Item * > *opt_fields_or_vars, mem_root_deque< Item * > *opt_set_fields, mem_root_deque< Item * > *opt_set_exprs, List< String > *opt_set_expr_strings, ulong concurrency, ulonglong memory_size, bool is_bulk_operation)
Definition: sql_load.h:48
mem_root_deque< Item * > m_opt_fields_or_vars
Definition: sql_load.h:126
bool execute(THD *thd) override
Execute this SQL statement.
Definition: sql_load.cc:2528
List< String > *const m_opt_set_expr_strings
A list of strings is maintained to store the SET clause command user strings which are specified in l...
Definition: sql_load.h:136
bool validate_table_for_bulk_load(THD *thd, Table_ref *const table_ref, dd::Table *table_def, handlerton **hton)
Validate table for bulk load operation.
Definition: sql_load.cc:297
bool m_is_bulk_operation
true if BULK LOAD.
Definition: sql_load.h:169
bool write_execute_load_query_log_event(THD *thd, const char *db, const char *table_name, bool is_concurrent, enum enum_duplicates duplicates, bool transactional_table, int errocode)
Definition: sql_load.cc:1095
Representation of an SQL command.
Definition: sql_cmd.h:82
Using this class is fraught with peril, and you need to be very careful when doing so.
Definition: sql_string.h:166
For each client connection we create a separate thread with THD serving as a thread/connection descri...
Definition: sql_lexer_thd.h:35
Definition: sql_lex.h:295
Definition: table.h:2853
Definition: table.h:46
A (partial) implementation of std::deque allocating its blocks on a MEM_ROOT.
Definition: mem_root_deque.h:110
size_t size() const
Definition: mem_root_deque.h:459
Used to hold information about file and file structure in exchange via non-DB file (....
Definition: sql_exchange.h:78
Field_separators field
Definition: sql_exchange.h:80
const CHARSET_INFO * cs
Definition: sql_exchange.h:86
unsigned long skip_lines
Definition: sql_exchange.h:85
Line_separators line
Definition: sql_exchange.h:81
A table definition from the master.
Definition: rpl_utility.h:247
A better implementation of the UNIX ctype(3) library.
unsigned long long int ulonglong
Definition: my_inttypes.h:55
enum_sql_command
Definition: my_sqlcommand.h:45
@ SQLCOM_LOAD
Definition: my_sqlcommand.h:76
thread_local MEM_ROOT ** THR_MALLOC
Definition: mysqld.cc:1571
static char * enclosed
Definition: mysqldump.cc:150
uint * concurrency
Definition: mysqlslap.cc:201
std::string str(const mysqlrouter::ConfigGenerator::Options::Endpoint &ep)
Definition: config_generator.cc:1065
static PFS_engine_table_share_proxy table
Definition: pfs.cc:60
const char * table_name
Definition: rules_table_service.cc:55
On_duplicate
Definition: parser_yystype.h:240
const char * filename
Definition: pfs_example_component_population.cc:66
Representation of an SQL command.
Contains classes representing SQL-data change statements.
enum_duplicates
Definition: sql_data_change.h:47
enum_filetype
Definition: sql_exchange.h:31
enum_source_type
Definition: sql_exchange.h:29
Our own string classes, used pervasively throughout the executor.
Definition: m_ctype.h:422
Helper for the sql_exchange class.
Definition: sql_exchange.h:52
void merge_field_separators(const Field_separators &s)
Definition: sql_exchange.h:62
Helper for the sql_exchange class.
Definition: sql_exchange.h:37
void merge_line_separators(const Line_separators &s)
Definition: sql_exchange.h:42
const String * line_term
Definition: sql_exchange.h:38
Definition: mysql_lex_string.h:34
Definition: table.h:1403
handlerton is a singleton structure - one instance per storage engine - to provide access to storage ...
Definition: handler.h:2718