MySQL 8.0.39
Source Code Documentation
sql_load.h
Go to the documentation of this file.
1/* Copyright (c) 2006, 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 SQL_LOAD_INCLUDED
25#define SQL_LOAD_INCLUDED
26
27#include <assert.h>
28#include <sys/types.h>
29
30#include "lex_string.h"
31#include "m_ctype.h"
32
33#include "my_sqlcommand.h"
34#include "sql/current_thd.h"
35#include "sql/sql_cmd.h" /* Sql_cmd */
36#include "sql/sql_data_change.h" /* enum_duplicates */
37#include "sql/sql_exchange.h" /* sql_exchange */
38#include "sql/sql_lex.h"
39#include "sql/sql_list.h"
40#include "sql_string.h"
41
42class Item;
43class READ_INFO;
44class THD;
45class Table_ref;
46
47class Sql_cmd_load_table final : public Sql_cmd {
48 public:
49 Sql_cmd_load_table(enum_filetype filetype, bool is_local_file,
50 const LEX_STRING &filename, On_duplicate on_duplicate,
51 Table_ident *table, List<String> *opt_partitions,
52 const CHARSET_INFO *opt_charset,
53 String *opt_xml_rows_identified_by,
54 const Field_separators &field_separators,
55 const Line_separators &line_separators, ulong skip_lines,
56 mem_root_deque<Item *> *opt_fields_or_vars,
57 mem_root_deque<Item *> *opt_set_fields,
58 mem_root_deque<Item *> *opt_set_exprs,
59 List<String> *opt_set_expr_strings)
60 : m_exchange(filename.str, false, filetype),
61 m_is_local_file(is_local_file),
62 m_on_duplicate(on_duplicate),
63 m_table(table),
64 m_opt_partitions(opt_partitions),
68 m_opt_set_expr_strings(opt_set_expr_strings) {
69 if (opt_fields_or_vars)
70 m_opt_fields_or_vars = std::move(*opt_fields_or_vars);
71 assert((opt_set_fields == nullptr) ^ (opt_set_exprs != nullptr));
72 if (opt_set_fields) {
73 assert(opt_set_fields->size() == opt_set_exprs->size());
74 m_opt_set_fields = std::move(*opt_set_fields);
75 m_opt_set_exprs = std::move(*opt_set_exprs);
76 }
77
78 m_exchange.cs = opt_charset;
79
80 if (opt_xml_rows_identified_by != nullptr)
81 m_exchange.line.line_term = opt_xml_rows_identified_by;
82
83 m_exchange.field.merge_field_separators(field_separators);
84 m_exchange.line.merge_line_separators(line_separators);
85 m_exchange.skip_lines = skip_lines;
86 }
87
88 enum_sql_command sql_command_code() const override { return SQLCOM_LOAD; }
89
90 bool execute(THD *thd) override;
91
92 public:
94 const bool m_is_local_file;
101
102 /**
103 A list of strings is maintained to store the SET clause command user strings
104 which are specified in load data operation. This list will be used
105 during the reconstruction of "load data" statement at the time of writing
106 to binary log.
107 */
109
110 private:
111 bool execute_inner(THD *thd, enum enum_duplicates handle_duplicates);
112
113 bool read_fixed_length(THD *thd, COPY_INFO &info, Table_ref *table_list,
114 READ_INFO &read_info, ulong skip_lines);
115
116 bool read_sep_field(THD *thd, COPY_INFO &info, Table_ref *table_list,
117 READ_INFO &read_info, const String &enclosed,
118 ulong skip_lines);
119
120 bool read_xml_field(THD *thd, COPY_INFO &info, Table_ref *table_list,
121 READ_INFO &read_info, ulong skip_lines);
122
124 THD *thd, const char *db, const char *table_name, bool is_concurrent,
125 enum enum_duplicates duplicates, bool transactional_table, int errocode);
126};
127
128#endif /* SQL_LOAD_INCLUDED */
This class encapsulates a data change operation.
Definition: sql_data_change.h:74
Base class that is used to represent any kind of expression in a relational query.
Definition: item.h:853
Definition: sql_list.h:434
Definition: sql_load.cc:118
Definition: sql_load.h:47
sql_exchange m_exchange
Definition: sql_load.h:93
const On_duplicate m_on_duplicate
Definition: sql_load.h:95
mem_root_deque< Item * > m_opt_set_fields
Definition: sql_load.h:99
enum_sql_command sql_command_code() const override
Return the command code for this statement.
Definition: sql_load.h:88
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:927
bool execute_inner(THD *thd, enum enum_duplicates handle_duplicates)
Execute LOAD DATA query.
Definition: sql_load.cc:202
const bool m_is_local_file
Definition: sql_load.h:94
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:764
mem_root_deque< Item * > m_opt_set_exprs
Definition: sql_load.h:100
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:1144
Sql_cmd_load_table(enum_filetype filetype, bool is_local_file, const LEX_STRING &filename, 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)
Definition: sql_load.h:49
List< String > *const m_opt_partitions
Definition: sql_load.h:97
Table_ident *const m_table
Definition: sql_load.h:96
mem_root_deque< Item * > m_opt_fields_or_vars
Definition: sql_load.h:98
bool execute(THD *thd) override
Execute this SQL statement.
Definition: sql_load.cc:2120
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:108
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:693
Representation of an SQL command.
Definition: sql_cmd.h:65
Using this class is fraught with peril, and you need to be very careful when doing so.
Definition: sql_string.h:168
For each client connection we create a separate thread with THD serving as a thread/connection descri...
Definition: sql_lexer_thd.h:34
Definition: sql_lex.h:294
Definition: table.h:2791
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:79
Field_separators field
Definition: sql_exchange.h:81
const CHARSET_INFO * cs
Definition: sql_exchange.h:87
unsigned long skip_lines
Definition: sql_exchange.h:86
Line_separators line
Definition: sql_exchange.h:82
A better implementation of the UNIX ctype(3) library.
enum_sql_command
Definition: my_sqlcommand.h:46
@ SQLCOM_LOAD
Definition: my_sqlcommand.h:77
Log info(cout, "NOTE")
thread_local MEM_ROOT ** THR_MALLOC
Definition: mysqld.cc:1560
static char * enclosed
Definition: mysqldump.cc:139
std::string str(const mysqlrouter::ConfigGenerator::Options::Endpoint &ep)
Definition: config_generator.cc:1052
const char * table_name
Definition: rules_table_service.cc:56
On_duplicate
Definition: parser_yystype.h:242
const char * filename
Definition: pfs_example_component_population.cc:67
Representation of an SQL command.
Contains classes representing SQL-data change statements.
enum_duplicates
Definition: sql_data_change.h:48
enum_filetype
Definition: sql_exchange.h:32
Our own string classes, used pervasively throughout the executor.
Definition: m_ctype.h:385
Helper for the sql_exchange class.
Definition: sql_exchange.h:53
void merge_field_separators(const Field_separators &s)
Definition: sql_exchange.h:63
Helper for the sql_exchange class.
Definition: sql_exchange.h:38
void merge_line_separators(const Line_separators &s)
Definition: sql_exchange.h:43
const String * line_term
Definition: sql_exchange.h:39
Definition: mysql_lex_string.h:35