1
0
mirror of https://github.com/MariaDB/server.git synced 2025-08-07 00:04:31 +03:00

Fixed error handling to be able do not interrupt update (907) (SCRUM)

fixed bug of current select pointer in subselect execution
fixed layuot


mysql-test/r/subselect.result:
  test of update with IGNORE option and error in subselect
mysql-test/t/subselect.test:
  test of update with IGNORE option and error in subselect
sql/item_subselect.cc:
  fixed bug of current select pointer
sql/mysqld.cc:
  error converting to warnings if hd->lex.current_select->no_error id true
  layout fixed
sql/sql_lex.cc:
  initialization
sql/sql_lex.h:
  flag which force converting errors to warnings
sql/sql_select.cc:
  switch on error convering to warnings in select executing if IGNORE option present
This commit is contained in:
unknown
2003-06-25 01:19:09 +03:00
parent 3eaf8865ec
commit cd01f7cda0
7 changed files with 54 additions and 11 deletions

View File

@@ -1151,3 +1151,16 @@ INSERT INTO t1 VALUES (1,0,NULL,NULL),(2,0,NULL,NULL);
SELECT DISTINCT REF_ID FROM t1 WHERE ID= (SELECT DISTINCT REF_ID FROM t1 WHERE ID=2); SELECT DISTINCT REF_ID FROM t1 WHERE ID= (SELECT DISTINCT REF_ID FROM t1 WHERE ID=2);
REF_ID REF_ID
DROP TABLE t1; DROP TABLE t1;
create table t1 (a int, b int);
create table t2 (a int, b int);
insert into t1 values (1,0), (2,0), (3,0);
insert into t2 values (1,1), (2,1), (3,1), (2,2);
update ignore t1 set b=(select b from t2 where t1.a=t2.a);
Warnings:
Error 1240 Subselect returns more than 1 record
select * from t1;
a b
1 1
2 NULL
3 1
drop table t1, t2;

View File

@@ -732,3 +732,17 @@ CREATE TABLE t1 (
INSERT INTO t1 VALUES (1,0,NULL,NULL),(2,0,NULL,NULL); INSERT INTO t1 VALUES (1,0,NULL,NULL),(2,0,NULL,NULL);
SELECT DISTINCT REF_ID FROM t1 WHERE ID= (SELECT DISTINCT REF_ID FROM t1 WHERE ID=2); SELECT DISTINCT REF_ID FROM t1 WHERE ID= (SELECT DISTINCT REF_ID FROM t1 WHERE ID=2);
DROP TABLE t1; DROP TABLE t1;
#
# uninterruptable update
#
create table t1 (a int, b int);
create table t2 (a int, b int);
insert into t1 values (1,0), (2,0), (3,0);
insert into t2 values (1,1), (2,1), (3,1), (2,2);
update ignore t1 set b=(select b from t2 where t1.a=t2.a);
select * from t1;
drop table t1, t2;

View File

@@ -824,6 +824,8 @@ int subselect_single_select_engine::exec()
{ {
DBUG_ENTER("subselect_single_select_engine::exec"); DBUG_ENTER("subselect_single_select_engine::exec");
char const *save_where= join->thd->where; char const *save_where= join->thd->where;
SELECT_LEX_NODE *save_select= join->thd->lex.current_select;
join->thd->lex.current_select= select_lex;
if (!optimized) if (!optimized)
{ {
optimized=1; optimized=1;
@@ -831,6 +833,7 @@ int subselect_single_select_engine::exec()
{ {
join->thd->where= save_where; join->thd->where= save_where;
executed= 1; executed= 1;
join->thd->lex.current_select= save_select;
DBUG_RETURN(join->error?join->error:1); DBUG_RETURN(join->error?join->error:1);
} }
} }
@@ -839,6 +842,7 @@ int subselect_single_select_engine::exec()
if (join->reinit()) if (join->reinit())
{ {
join->thd->where= save_where; join->thd->where= save_where;
join->thd->lex.current_select= save_select;
DBUG_RETURN(1); DBUG_RETURN(1);
} }
item->reset(); item->reset();
@@ -846,15 +850,14 @@ int subselect_single_select_engine::exec()
} }
if (!executed) if (!executed)
{ {
SELECT_LEX_NODE *save_select= join->thd->lex.current_select;
join->thd->lex.current_select= select_lex;
join->exec(); join->exec();
join->thd->lex.current_select= save_select;
executed= 1; executed= 1;
join->thd->where= save_where; join->thd->where= save_where;
join->thd->lex.current_select= save_select;
DBUG_RETURN(join->error||thd->is_fatal_error); DBUG_RETURN(join->error||thd->is_fatal_error);
} }
join->thd->where= save_where; join->thd->where= save_where;
join->thd->lex.current_select= save_select;
DBUG_RETURN(0); DBUG_RETURN(0);
} }

View File

@@ -1820,6 +1820,13 @@ extern "C" int my_message_sql(uint error, const char *str,
DBUG_ENTER("my_message_sql"); DBUG_ENTER("my_message_sql");
DBUG_PRINT("error", ("Message: '%s'", str)); DBUG_PRINT("error", ("Message: '%s'", str));
if ((thd= current_thd)) if ((thd= current_thd))
{
if (thd->lex.current_select->no_error && !thd->is_fatal_error)
{
DBUG_PRINT("error", ("above error converted to warning"));
push_warning(thd, MYSQL_ERROR::WARN_LEVEL_ERROR, error, str);
}
else
{ {
NET *net= &thd->net; NET *net= &thd->net;
net->report_error= 1; net->report_error= 1;
@@ -1829,6 +1836,7 @@ extern "C" int my_message_sql(uint error, const char *str,
net->last_errno= error ? error : ER_UNKNOWN_ERROR; net->last_errno= error ? error : ER_UNKNOWN_ERROR;
} }
} }
}
else else
sql_print_error("%s: %s",my_progname,str); /* purecov: inspected */ sql_print_error("%s: %s",my_progname,str); /* purecov: inspected */
DBUG_RETURN(0); DBUG_RETURN(0);

View File

@@ -122,6 +122,7 @@ LEX *lex_start(THD *thd, uchar *buf,uint length)
lex->yacc_yyss=lex->yacc_yyvs=0; lex->yacc_yyss=lex->yacc_yyvs=0;
lex->ignore_space=test(thd->variables.sql_mode & MODE_IGNORE_SPACE); lex->ignore_space=test(thd->variables.sql_mode & MODE_IGNORE_SPACE);
lex->sql_command=SQLCOM_END; lex->sql_command=SQLCOM_END;
lex->duplicates= DUP_ERROR;
return lex; return lex;
} }
@@ -965,7 +966,7 @@ void st_select_lex_node::init_query()
{ {
options= 0; options= 0;
linkage= UNSPECIFIED_TYPE; linkage= UNSPECIFIED_TYPE;
no_table_names_allowed= uncacheable= dependent= 0; no_error= no_table_names_allowed= uncacheable= dependent= 0;
ref_pointer_array= 0; ref_pointer_array= 0;
} }

View File

@@ -212,6 +212,7 @@ public:
bool dependent; /* dependent from outer select subselect */ bool dependent; /* dependent from outer select subselect */
bool uncacheable; /* result of this query can't be cached */ bool uncacheable; /* result of this query can't be cached */
bool no_table_names_allowed; /* used for global order by */ bool no_table_names_allowed; /* used for global order by */
bool no_error; /* suppress error message (convert it to warnings) */
static void *operator new(size_t size) static void *operator new(size_t size)
{ {

View File

@@ -436,6 +436,9 @@ JOIN::optimize()
DBUG_RETURN(0); DBUG_RETURN(0);
optimized= 1; optimized= 1;
// Ignore errors of execution if option IGNORE present
if (thd->lex.duplicates == DUP_IGNORE)
thd->lex.current_select->no_error= 1;
#ifdef HAVE_REF_TO_FIELDS // Not done yet #ifdef HAVE_REF_TO_FIELDS // Not done yet
/* Add HAVING to WHERE if possible */ /* Add HAVING to WHERE if possible */
if (having && !group_list && !sum_func_count) if (having && !group_list && !sum_func_count)