summaryrefslogtreecommitdiff
path: root/sql/sql_load.cc
diff options
context:
space:
mode:
Diffstat (limited to 'sql/sql_load.cc')
-rw-r--r--sql/sql_load.cc72
1 files changed, 38 insertions, 34 deletions
diff --git a/sql/sql_load.cc b/sql/sql_load.cc
index e2dbbdb6782..09af120e6cf 100644
--- a/sql/sql_load.cc
+++ b/sql/sql_load.cc
@@ -19,7 +19,7 @@
/* Copy data from a textfile to table */
/* 2006-12 Erik Wetterberg : LOAD XML added */
-#include <my_global.h>
+#include "mariadb.h"
#include "sql_priv.h"
#include "unireg.h"
#include "sql_load.h"
@@ -298,7 +298,7 @@ static int read_xml_field(THD *thd, COPY_INFO &info, TABLE_LIST *table_list,
bool ignore_check_option_errors);
#ifndef EMBEDDED_LIBRARY
-static bool write_execute_load_query_log_event(THD *, sql_exchange*, const
+static bool write_execute_load_query_log_event(THD *, const sql_exchange*, const
char*, const char*, bool, enum enum_duplicates, bool, bool, int);
#endif /* EMBEDDED_LIBRARY */
@@ -348,7 +348,7 @@ bool Load_data_param::add_outvar_user_var(THD *thd)
TRUE - error / FALSE - success
*/
-int mysql_load(THD *thd,sql_exchange *ex,TABLE_LIST *table_list,
+int mysql_load(THD *thd, const sql_exchange *ex, TABLE_LIST *table_list,
List<Item> &fields_vars, List<Item> &set_fields,
List<Item> &set_values,
enum enum_duplicates handle_duplicates, bool ignore,
@@ -363,13 +363,13 @@ int mysql_load(THD *thd,sql_exchange *ex,TABLE_LIST *table_list,
killed_state killed_status;
bool is_concurrent;
#endif
- char *db = table_list->db; // This is never null
+ const char *db= table_list->db.str; // This is never null
/*
If path for file is not defined, we will use the current database.
If this is not set, we will use the directory where the table to be
loaded is located
*/
- char *tdb= thd->db ? thd->db : db; // Result is never null
+ const char *tdb= thd->db.str ? thd->db.str : db; // Result is never null
ulong skip_lines= ex->skip_lines;
bool transactional_table __attribute__((unused));
DBUG_ENTER("mysql_load");
@@ -421,7 +421,7 @@ int mysql_load(THD *thd,sql_exchange *ex,TABLE_LIST *table_list,
!table_list->single_table_updatable() || // and derived tables
check_key_in_view(thd, table_list))
{
- my_error(ER_NON_UPDATABLE_TABLE, MYF(0), table_list->alias, "LOAD");
+ my_error(ER_NON_UPDATABLE_TABLE, MYF(0), table_list->alias.str, "LOAD");
DBUG_RETURN(TRUE);
}
if (table_list->is_multitable())
@@ -434,7 +434,7 @@ int mysql_load(THD *thd,sql_exchange *ex,TABLE_LIST *table_list,
{
DBUG_RETURN(TRUE);
}
- thd_proc_info(thd, "executing");
+ thd_proc_info(thd, "Executing");
/*
Let us emit an error if we are loading data to table which is used
in subselect in SET clause like we do it for INSERT.
@@ -445,7 +445,7 @@ int mysql_load(THD *thd,sql_exchange *ex,TABLE_LIST *table_list,
*/
if (unique_table(thd, table_list, table_list->next_global, 0))
{
- my_error(ER_UPDATE_TABLE_USED, MYF(0), table_list->table_name,
+ my_error(ER_UPDATE_TABLE_USED, MYF(0), table_list->table_name.str,
"LOAD DATA");
DBUG_RETURN(TRUE);
}
@@ -462,6 +462,9 @@ int mysql_load(THD *thd,sql_exchange *ex,TABLE_LIST *table_list,
field_iterator.set(table_list);
for (; !field_iterator.end_of_fields(); field_iterator.next())
{
+ if (field_iterator.field() &&
+ field_iterator.field()->invisible > VISIBLE)
+ continue;
Item *item;
if (!(item= field_iterator.create_item(thd)))
DBUG_RETURN(TRUE);
@@ -611,7 +614,7 @@ int mysql_load(THD *thd,sql_exchange *ex,TABLE_LIST *table_list,
*ex->field_term, *ex->line_start,
*ex->line_term, *ex->enclosed,
info.escape_char, read_file_from_client, is_fifo);
- if (read_info.error)
+ if (unlikely(read_info.error))
{
if (file >= 0)
mysql_file_close(file, MYF(0)); // no files in net reading
@@ -642,8 +645,8 @@ int mysql_load(THD *thd,sql_exchange *ex,TABLE_LIST *table_list,
}
}
- thd_proc_info(thd, "reading file");
- if (!(error= MY_TEST(read_info.error)))
+ thd_proc_info(thd, "Reading file");
+ if (likely(!(error= MY_TEST(read_info.error))))
{
table->reset_default_fields();
table->next_number_field=table->found_next_number_field;
@@ -687,7 +690,7 @@ int mysql_load(THD *thd,sql_exchange *ex,TABLE_LIST *table_list,
table_list->table->file->ha_rnd_end();
thd_proc_info(thd, "End bulk insert");
- if (!error)
+ if (likely(!error))
thd_progress_next_stage(thd);
if (thd->locked_tables_mode <= LTM_LOCK_TABLES &&
table->file->ha_end_bulk_insert() && !error)
@@ -746,8 +749,8 @@ int mysql_load(THD *thd,sql_exchange *ex,TABLE_LIST *table_list,
writing binary log will be ignored */
if (thd->transaction.stmt.modified_non_trans_table)
(void) write_execute_load_query_log_event(thd, ex,
- table_list->db,
- table_list->table_name,
+ table_list->db.str,
+ table_list->table_name.str,
is_concurrent,
handle_duplicates, ignore,
transactional_table,
@@ -797,7 +800,8 @@ int mysql_load(THD *thd,sql_exchange *ex,TABLE_LIST *table_list,
{
int errcode= query_error_code(thd, killed_status == NOT_KILLED);
error= write_execute_load_query_log_event(thd, ex,
- table_list->db, table_list->table_name,
+ table_list->db.str,
+ table_list->table_name.str,
is_concurrent,
handle_duplicates, ignore,
transactional_table,
@@ -811,7 +815,7 @@ int mysql_load(THD *thd,sql_exchange *ex,TABLE_LIST *table_list,
*/
error= error || mysql_bin_log.get_log_file()->error;
}
- if (error)
+ if (unlikely(error))
goto err;
}
#endif /*!EMBEDDED_LIBRARY*/
@@ -831,7 +835,7 @@ err:
#ifndef EMBEDDED_LIBRARY
/* Not a very useful function; just to avoid duplication of code */
-static bool write_execute_load_query_log_event(THD *thd, sql_exchange* ex,
+static bool write_execute_load_query_log_event(THD *thd, const sql_exchange* ex,
const char* db_arg, /* table's database */
const char* table_name_arg,
bool is_concurrent,
@@ -846,7 +850,7 @@ static bool write_execute_load_query_log_event(THD *thd, sql_exchange* ex,
List<Item> fv;
Item *item, *val;
int n;
- const char *tdb= (thd->db != NULL ? thd->db : db_arg);
+ const char *tdb= (thd->db.str != NULL ? thd->db.str : db_arg);
const char *qualify_db= NULL;
char command_buffer[1024];
String query_str(command_buffer, sizeof(command_buffer),
@@ -862,7 +866,7 @@ static bool write_execute_load_query_log_event(THD *thd, sql_exchange* ex,
lle.set_fname_outside_temp_buf(ex->file_name, strlen(ex->file_name));
query_str.length(0);
- if (!thd->db || strcmp(db_arg, thd->db))
+ if (!thd->db.str || strcmp(db_arg, thd->db.str))
{
/*
If used database differs from table's database,
@@ -908,8 +912,8 @@ static bool write_execute_load_query_log_event(THD *thd, sql_exchange* ex,
val= lv++;
if (n++)
query_str.append(STRING_WITH_LEN(", "));
- append_identifier(thd, &query_str, item->name, strlen(item->name));
- query_str.append(val->name);
+ append_identifier(thd, &query_str, &item->name);
+ query_str.append(&val->name);
}
}
@@ -1131,11 +1135,11 @@ read_sep_field(THD *thd, COPY_INFO &info, TABLE_LIST *table_list,
}
}
- if (thd->is_error())
+ if (unlikely(thd->is_error()))
read_info.error= 1;
-
- if (read_info.error)
+ if (unlikely(read_info.error))
break;
+
if (skip_lines)
{
skip_lines--;
@@ -1155,11 +1159,11 @@ read_sep_field(THD *thd, COPY_INFO &info, TABLE_LIST *table_list,
}
}
- if (thd->killed ||
- fill_record_n_invoke_before_triggers(thd, table, set_fields,
- set_values,
- ignore_check_option_errors,
- TRG_EVENT_INSERT))
+ if (unlikely(thd->killed) ||
+ unlikely(fill_record_n_invoke_before_triggers(thd, table, set_fields,
+ set_values,
+ ignore_check_option_errors,
+ TRG_EVENT_INSERT)))
DBUG_RETURN(1);
switch (table_list->view_check_option(thd,
@@ -1253,7 +1257,7 @@ read_xml_field(THD *thd, COPY_INFO &info, TABLE_LIST *table_list,
xmlit.rewind();
tag= xmlit++;
- while(tag && strcmp(tag->field.c_ptr(), item->name) != 0)
+ while(tag && strcmp(tag->field.c_ptr(), item->name.str) != 0)
tag= xmlit++;
Load_data_outvar *dst= item->get_load_data_outvar_or_error();
@@ -1265,7 +1269,7 @@ read_xml_field(THD *thd, COPY_INFO &info, TABLE_LIST *table_list,
DBUG_RETURN(1);
}
- if (read_info.error)
+ if (unlikely(read_info.error))
break;
if (skip_lines)
@@ -2027,8 +2031,8 @@ int READ_INFO::read_xml(THD *thd)
case '=': /* attribute name end - read the value */
//check for tag field and attribute name
- if(!memcmp(tag.c_ptr_safe(), STRING_WITH_LEN("field")) &&
- !memcmp(attribute.c_ptr_safe(), STRING_WITH_LEN("name")))
+ if(!strcmp(tag.c_ptr_safe(), "field") &&
+ !strcmp(attribute.c_ptr_safe(), "name"))
{
/*
this is format <field name="xx">xx</field>
@@ -2059,7 +2063,7 @@ int READ_INFO::read_xml(THD *thd)
chr= read_value(delim, &value);
if (attribute.length() > 0 && value.length() > 0)
{
- DBUG_PRINT("read_xml", ("lev:%i att:%s val:%s\n",
+ DBUG_PRINT("read_xml", ("lev:%i att:%s val:%s",
level + 1,
attribute.c_ptr_safe(),
value.c_ptr_safe()));