summaryrefslogtreecommitdiff
path: root/sql
diff options
context:
space:
mode:
authorSergei Golubchik <serg@mariadb.org>2021-09-15 15:54:49 +0200
committerSergei Golubchik <serg@mariadb.org>2021-09-16 13:38:48 +0200
commitd552e092c9f3e20da078d1b62b976f629f73d3a4 (patch)
tree1ad8172027bcd1d5c06fe2dd3d6acb2aa4fcb99c /sql
parent0ff8976e129a0e1f3f17a6ed278ddc4851b4535d (diff)
downloadmariadb-git-d552e092c9f3e20da078d1b62b976f629f73d3a4.tar.gz
MDEV-10075: Provide index of error causing error in array INSERT
use existing Warning_info::m_current_row_for_warning instead of a newly introduced counter. But use m_current_row_for_warning to count rows also in the parser and during prepare.
Diffstat (limited to 'sql')
-rw-r--r--sql/lex.h2
-rw-r--r--sql/sp_rcontext.cc3
-rw-r--r--sql/sql_class.cc6
-rw-r--r--sql/sql_class.h23
-rw-r--r--sql/sql_error.cc2
-rw-r--r--sql/sql_error.h24
-rw-r--r--sql/sql_get_diagnostics.cc2
-rw-r--r--sql/sql_insert.cc14
-rw-r--r--sql/sql_parse.cc1
-rw-r--r--sql/sql_prepare.cc9
-rw-r--r--sql/sql_signal.cc3
-rw-r--r--sql/sql_yacc.yy12
12 files changed, 31 insertions, 70 deletions
diff --git a/sql/lex.h b/sql/lex.h
index 57d8d807909..6255cb1a35b 100644
--- a/sql/lex.h
+++ b/sql/lex.h
@@ -222,7 +222,7 @@ SYMBOL symbols[] = {
{ "ENUM", SYM(ENUM)},
{ "ERROR", SYM(ERROR_SYM)},
{ "ERRORS", SYM(ERRORS)},
- { "ERROR_INDEX", SYM(ERROR_INDEX_SYM)},
+ { "ERROR_INDEX", SYM(ERROR_INDEX_SYM)},
{ "ESCAPE", SYM(ESCAPE_SYM)},
{ "ESCAPED", SYM(ESCAPED)},
{ "EVENT", SYM(EVENT_SYM)},
diff --git a/sql/sp_rcontext.cc b/sql/sp_rcontext.cc
index 7170018c995..619218f3b68 100644
--- a/sql/sp_rcontext.cc
+++ b/sql/sp_rcontext.cc
@@ -518,7 +518,8 @@ bool sp_rcontext::handle_sql_condition(THD *thd,
found_condition=
new (callers_arena->mem_root) Sql_condition(callers_arena->mem_root,
da->get_error_condition_identity(),
- da->message(), 0);
+ da->message(),
+ da->current_row_for_warning());
}
}
else if (da->current_statement_warn_count())
diff --git a/sql/sql_class.cc b/sql/sql_class.cc
index 34d220aa27e..c88bfc4c484 100644
--- a/sql/sql_class.cc
+++ b/sql/sql_class.cc
@@ -908,7 +908,6 @@ THD::THD(my_thread_id id, bool is_wsrep_applier)
org_charset= 0;
/* Restore THR_THD */
set_current_thd(old_THR_THD);
- current_insert_index= 0;
}
@@ -1056,8 +1055,6 @@ Sql_condition* THD::raise_condition(uint sql_errno,
{
Diagnostics_area *da= get_stmt_da();
Sql_condition *cond= NULL;
- ulonglong saved_error_index;
-
DBUG_ENTER("THD::raise_condition");
DBUG_ASSERT(level < Sql_condition::WARN_LEVEL_END);
@@ -1152,10 +1149,7 @@ Sql_condition* THD::raise_condition(uint sql_errno,
if (likely(!(is_fatal_error && (sql_errno == EE_OUTOFMEMORY ||
sql_errno == ER_OUTOFMEMORY))))
{
- saved_error_index= this->current_insert_index;
- this->current_insert_index= this->correct_error_index(sql_errno);
cond= da->push_warning(this, sql_errno, sqlstate, level, ucid, msg);
- this->current_insert_index= saved_error_index;
}
DBUG_RETURN(cond);
}
diff --git a/sql/sql_class.h b/sql/sql_class.h
index 791e67b4f59..e569fcd32d6 100644
--- a/sql/sql_class.h
+++ b/sql/sql_class.h
@@ -5502,29 +5502,6 @@ public:
{
lex= backup_lex;
}
-
- /*
- Stores the the processed record during INSERT/REPLACE. Used for assigning
- value of error_index in case of warning or error.
- */
- ulonglong current_insert_index;
-
- /*
- Error may take place in prepare phase and it might not be because of
- rows/values we are inserting into the table, it could be because of say
- something like wrong field name. In such case we want to return 0
- for error index.
- */
- ulonglong correct_error_index(uint error_no)
- {
- if (error_no == ER_FIELD_SPECIFIED_TWICE ||
- error_no == ER_BAD_FIELD_ERROR ||
- error_no == ER_VIEW_NO_INSERT_FIELD_LIST ||
- error_no == ER_VIEW_MULTIUPDATE)
- return 0;
-
- return current_insert_index;
- }
};
diff --git a/sql/sql_error.cc b/sql/sql_error.cc
index 6961f1b258e..7b6e6a83d2f 100644
--- a/sql/sql_error.cc
+++ b/sql/sql_error.cc
@@ -673,7 +673,7 @@ Sql_condition *Warning_info::push_warning(THD *thd,
m_warn_list.elements() < thd->variables.max_error_count)
{
cond= new (& m_warn_root) Sql_condition(& m_warn_root, *value, msg,
- thd->current_insert_index);
+ m_current_row_for_warning);
if (cond)
m_warn_list.push_back(cond);
}
diff --git a/sql/sql_error.h b/sql/sql_error.h
index 113b51454c6..b6ed7f5061a 100644
--- a/sql/sql_error.h
+++ b/sql/sql_error.h
@@ -306,6 +306,8 @@ protected:
/** SQL CURSOR_NAME condition item. */
String m_cursor_name;
+ ulong m_error_index;
+
Sql_condition_items()
:m_class_origin((const char*) NULL, 0, & my_charset_utf8mb3_bin),
m_subclass_origin((const char*) NULL, 0, & my_charset_utf8mb3_bin),
@@ -316,7 +318,8 @@ protected:
m_schema_name((const char*) NULL, 0, & my_charset_utf8mb3_bin),
m_table_name((const char*) NULL, 0, & my_charset_utf8mb3_bin),
m_column_name((const char*) NULL, 0, & my_charset_utf8mb3_bin),
- m_cursor_name((const char*) NULL, 0, & my_charset_utf8mb3_bin)
+ m_cursor_name((const char*) NULL, 0, & my_charset_utf8mb3_bin),
+ m_error_index(0)
{ }
void clear()
@@ -331,6 +334,7 @@ protected:
m_table_name.length(0);
m_column_name.length(0);
m_cursor_name.length(0);
+ m_error_index= 0;
}
};
@@ -396,7 +400,7 @@ private:
*/
Sql_condition()
:m_mem_root(NULL)
- { error_index= 0; }
+ { }
/**
Complete the Sql_condition initialisation.
@@ -419,7 +423,6 @@ private:
:m_mem_root(mem_root)
{
DBUG_ASSERT(mem_root != NULL);
- error_index= 0;
}
Sql_condition(MEM_ROOT *mem_root, const Sql_user_condition_identity &ucid)
@@ -427,7 +430,6 @@ private:
m_mem_root(mem_root)
{
DBUG_ASSERT(mem_root != NULL);
- error_index= 0;
}
/**
Constructor for a fixed message text.
@@ -436,18 +438,15 @@ private:
@param level - the error level for this condition
@param msg - the message text for this condition
*/
- Sql_condition(MEM_ROOT *mem_root,
- const Sql_condition_identity &value,
- const char *msg,
- ulonglong current_error_index)
- :Sql_condition_identity(value),
- m_mem_root(mem_root)
+ Sql_condition(MEM_ROOT *mem_root, const Sql_condition_identity &value,
+ const char *msg, ulong current_row_for_warning)
+ : Sql_condition_identity(value), m_mem_root(mem_root)
{
DBUG_ASSERT(mem_root != NULL);
DBUG_ASSERT(value.get_sql_errno() != 0);
DBUG_ASSERT(msg != NULL);
set_builtin_message_text(msg);
- error_index= current_error_index;
+ m_error_index= current_row_for_warning;
}
/** Destructor. */
@@ -501,9 +500,6 @@ private:
/** Memory root to use to hold condition item values. */
MEM_ROOT *m_mem_root;
-
- /* Index of error for INSERT/REPLACE statement. */
- ulonglong error_index;
};
///////////////////////////////////////////////////////////////////////////
diff --git a/sql/sql_get_diagnostics.cc b/sql/sql_get_diagnostics.cc
index 0de1cde3c49..6a479726df1 100644
--- a/sql/sql_get_diagnostics.cc
+++ b/sql/sql_get_diagnostics.cc
@@ -339,7 +339,7 @@ Condition_information_item::get_value(THD *thd, const Sql_condition *cond)
value= make_utf8_string_item(thd, &str);
break;
case ERROR_INDEX:
- value= new (thd->mem_root) Item_uint(thd, cond->error_index);
+ value= new (thd->mem_root) Item_uint(thd, cond->m_error_index);
}
DBUG_RETURN(value);
diff --git a/sql/sql_insert.cc b/sql/sql_insert.cc
index 7b2b820752c..bd4ca508a9e 100644
--- a/sql/sql_insert.cc
+++ b/sql/sql_insert.cc
@@ -699,7 +699,6 @@ bool mysql_insert(THD *thd, TABLE_LIST *table_list,
const bool was_insert_delayed= (table_list->lock_type == TL_WRITE_DELAYED);
bool using_bulk_insert= 0;
uint value_count;
- ulong counter = 1;
/* counter of iteration in bulk PS operation*/
ulonglong iteration= 0;
ulonglong id;
@@ -711,7 +710,6 @@ bool mysql_insert(THD *thd, TABLE_LIST *table_list,
Name_resolution_context_state ctx_state;
SELECT_LEX *returning= thd->lex->has_returning() ? thd->lex->returning() : 0;
unsigned char *readbuff= NULL;
- thd->current_insert_index= 0;
#ifndef EMBEDDED_LIBRARY
char *query= thd->query();
@@ -831,10 +829,11 @@ bool mysql_insert(THD *thd, TABLE_LIST *table_list,
while ((values= its++))
{
- thd->current_insert_index= ++counter;
+ thd->get_stmt_da()->inc_current_row_for_warning();
if (values->elements != value_count)
{
- my_error(ER_WRONG_VALUE_COUNT_ON_ROW, MYF(0), counter);
+ my_error(ER_WRONG_VALUE_COUNT_ON_ROW, MYF(0),
+ thd->get_stmt_da()->current_row_for_warning());
goto abort;
}
if (setup_fields(thd, Ref_ptr_array(),
@@ -843,7 +842,7 @@ bool mysql_insert(THD *thd, TABLE_LIST *table_list,
switch_to_nullable_trigger_fields(*values, table);
}
its.rewind ();
- thd->current_insert_index= 0;
+ thd->get_stmt_da()->reset_current_row_for_warning();
/* Restore the current context. */
ctx_state.restore_state(context, table_list);
@@ -1010,7 +1009,6 @@ bool mysql_insert(THD *thd, TABLE_LIST *table_list,
while ((values= its++))
{
- thd->current_insert_index++;
if (fields.elements || !value_count)
{
/*
@@ -1134,7 +1132,6 @@ bool mysql_insert(THD *thd, TABLE_LIST *table_list,
} while (bulk_parameters_iterations(thd));
values_loop_end:
- thd->current_insert_index= 0;
free_underlaid_joins(thd, thd->lex->first_select_lex());
joins_freed= TRUE;
@@ -1610,8 +1607,6 @@ int mysql_prepare_insert(THD *thd, TABLE_LIST *table_list,
bool res= 0;
table_map map= 0;
TABLE *table;
- thd->current_insert_index= 1;
-
DBUG_ENTER("mysql_prepare_insert");
DBUG_PRINT("enter", ("table_list: %p view: %d",
table_list, (int) insert_into_view));
@@ -1665,7 +1660,6 @@ int mysql_prepare_insert(THD *thd, TABLE_LIST *table_list,
if (!res)
res= setup_fields(thd, Ref_ptr_array(),
update_values, MARK_COLUMNS_READ, 0, NULL, 0);
- thd->current_insert_index= 0;
if (!res && duplic == DUP_UPDATE)
{
diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc
index d853b09b354..b9d3eec5a60 100644
--- a/sql/sql_parse.cc
+++ b/sql/sql_parse.cc
@@ -7978,7 +7978,6 @@ void mysql_parse(THD *thd, char *rawbuf, uint length,
LEX *lex= thd->lex;
bool err= parse_sql(thd, parser_state, NULL, true);
- thd->current_insert_index= 0;
if (likely(!err))
{
diff --git a/sql/sql_prepare.cc b/sql/sql_prepare.cc
index 4d92d46f9c2..2391f630f50 100644
--- a/sql/sql_prepare.cc
+++ b/sql/sql_prepare.cc
@@ -1314,7 +1314,6 @@ static bool mysql_test_insert_common(Prepared_statement *stmt,
if ((values= its++))
{
uint value_count;
- ulong counter= 0;
Item *unused_conds= 0;
if (table_list->table)
@@ -1338,20 +1337,20 @@ static bool mysql_test_insert_common(Prepared_statement *stmt,
table_list->table_name.str));
goto error;
}
- thd->current_insert_index= 0;
while ((values= its++))
{
- thd->current_insert_index= ++counter;
if (values->elements != value_count)
{
- my_error(ER_WRONG_VALUE_COUNT_ON_ROW, MYF(0), counter);
+ my_error(ER_WRONG_VALUE_COUNT_ON_ROW, MYF(0),
+ thd->get_stmt_da()->current_row_for_warning());
goto error;
}
if (setup_fields(thd, Ref_ptr_array(),
*values, COLUMNS_READ, 0, NULL, 0))
goto error;
+ thd->get_stmt_da()->inc_current_row_for_warning();
}
- thd->current_insert_index= 0;
+ thd->get_stmt_da()->reset_current_row_for_warning();
}
DBUG_RETURN(FALSE);
diff --git a/sql/sql_signal.cc b/sql/sql_signal.cc
index 5a085c99de7..e023923bd1a 100644
--- a/sql/sql_signal.cc
+++ b/sql/sql_signal.cc
@@ -419,7 +419,8 @@ bool Sql_cmd_resignal::execute(THD *thd)
DBUG_RETURN(result);
}
- Sql_condition signaled_err(thd->mem_root, *signaled, signaled->message, 0);
+ Sql_condition signaled_err(thd->mem_root, *signaled, signaled->message,
+ da->current_row_for_warning());
if (m_cond)
{
diff --git a/sql/sql_yacc.yy b/sql/sql_yacc.yy
index 57201b22802..ad0f7b6c137 100644
--- a/sql/sql_yacc.yy
+++ b/sql/sql_yacc.yy
@@ -12833,6 +12833,7 @@ insert:
{
Lex->sql_command= SQLCOM_INSERT;
Lex->duplicates= DUP_ERROR;
+ thd->get_stmt_da()->opt_clear_warning_info(thd->query_id);
}
insert_start insert_lock_option opt_ignore opt_into insert_table
{
@@ -12842,6 +12843,7 @@ insert:
stmt_end
{
Lex->mark_first_table_as_inserting();
+ thd->get_stmt_da()->reset_current_row_for_warning();
}
;
@@ -12850,6 +12852,7 @@ replace:
{
Lex->sql_command = SQLCOM_REPLACE;
Lex->duplicates= DUP_REPLACE;
+ thd->get_stmt_da()->opt_clear_warning_info(thd->query_id);
}
insert_start replace_lock_option opt_into insert_table
{
@@ -12859,6 +12862,7 @@ replace:
stmt_end
{
Lex->mark_first_table_as_inserting();
+ thd->get_stmt_da()->reset_current_row_for_warning();
}
;
@@ -12918,7 +12922,6 @@ insert_table:
//lex->field_list.empty();
lex->many_values.empty();
lex->insert_list=0;
- thd->current_insert_index= lex->many_values.elements+1;
}
;
@@ -12928,14 +12931,11 @@ insert_field_spec:
| SET
{
LEX *lex=Lex;
- ulonglong saved_current_insert_index= thd->current_insert_index;
if (unlikely(!(lex->insert_list= new (thd->mem_root) List_item)) ||
unlikely(lex->many_values.push_back(lex->insert_list,
thd->mem_root)))
MYSQL_YYABORT;
lex->current_select->parsing_place= NO_MATTER;
- if (saved_current_insert_index < lex->many_values.elements)
- thd->current_insert_index++;
}
ident_eq_list
;
@@ -13013,10 +13013,10 @@ no_braces:
opt_values ')'
{
LEX *lex=Lex;
+ thd->get_stmt_da()->inc_current_row_for_warning();
if (unlikely(lex->many_values.push_back(lex->insert_list,
thd->mem_root)))
MYSQL_YYABORT;
- thd->current_insert_index++;
}
;
@@ -13029,10 +13029,10 @@ no_braces_with_names:
opt_values_with_names ')'
{
LEX *lex=Lex;
+ thd->get_stmt_da()->inc_current_row_for_warning();
if (unlikely(lex->many_values.push_back(lex->insert_list,
thd->mem_root)))
MYSQL_YYABORT;
- thd->current_insert_index++;
}
;