summaryrefslogtreecommitdiff
path: root/sql
diff options
context:
space:
mode:
authorOleksandr Byelkin <sanja@mariadb.com>2018-08-30 15:18:35 +0200
committerOleksandr Byelkin <sanja@mariadb.com>2018-08-31 17:07:43 +0200
commit796d54df115a0e5485a7df0835088a51dd0f9e77 (patch)
tree5769259f7df0b2ba6519f93de58c19598b7b84ea /sql
parent42f09adab68f80fb99d6da0413cd4983ec13f5ab (diff)
downloadmariadb-git-796d54df115a0e5485a7df0835088a51dd0f9e77.tar.gz
MDEV-16957: Server crashes in Field_iterator_natural_join::next upon 2nd execution of SP
The problem was that join_columns creation was not finished due to error of notfound column in USING, but next execution tried to use join_columns lists. Solution is cleanup the lists on error. It can eat memory in statement MEM_ROOT but it is an error and error will be fixed or statement/procedure removed/altered.
Diffstat (limited to 'sql')
-rw-r--r--sql/sql_base.cc14
-rw-r--r--sql/table.h10
2 files changed, 23 insertions, 1 deletions
diff --git a/sql/sql_base.cc b/sql/sql_base.cc
index 8ffb7bc118b..272aa11977d 100644
--- a/sql/sql_base.cc
+++ b/sql/sql_base.cc
@@ -7764,10 +7764,22 @@ store_natural_using_join_columns(THD *thd, TABLE_LIST *natural_using_join,
result= FALSE;
-err:
if (arena)
thd->restore_active_arena(arena, &backup);
DBUG_RETURN(result);
+
+err:
+ /*
+ Actually we failed to build join columns list, so we have to
+ clear it to avoid problems with half-build join on next run.
+ The list was created in mark_common_columns().
+ */
+ table_ref_1->remove_join_columns();
+ table_ref_2->remove_join_columns();
+
+ if (arena)
+ thd->restore_active_arena(arena, &backup);
+ DBUG_RETURN(TRUE);
}
diff --git a/sql/table.h b/sql/table.h
index 1d4a1d9a2d2..4725eb96432 100644
--- a/sql/table.h
+++ b/sql/table.h
@@ -2184,6 +2184,16 @@ struct TABLE_LIST
}
void set_lock_type(THD* thd, enum thr_lock_type lock);
+ void remove_join_columns()
+ {
+ if (join_columns)
+ {
+ join_columns->empty();
+ join_columns= NULL;
+ is_join_columns_complete= FALSE;
+ }
+ }
+
private:
bool prep_check_option(THD *thd, uint8 check_opt_type);
bool prep_where(THD *thd, Item **conds, bool no_where_clause);