summaryrefslogtreecommitdiff
path: root/sql/sql_base.cc
diff options
context:
space:
mode:
authorSergei Golubchik <sergii@pisem.net>2014-02-03 15:22:39 +0100
committerSergei Golubchik <sergii@pisem.net>2014-02-03 15:22:39 +0100
commit72c20282db820b0b0818aea160a485bdca897eec (patch)
tree3089e022d958990fc0a405a38ba43ae00c87103c /sql/sql_base.cc
parent5e1d5d9bc0bf9ea776bffe6c4914a84be920c0b2 (diff)
parent2acc01b3cfa27074f93016b893cda20fa0a3497f (diff)
downloadmariadb-git-72c20282db820b0b0818aea160a485bdca897eec.tar.gz
10.0-base merge
Diffstat (limited to 'sql/sql_base.cc')
-rw-r--r--sql/sql_base.cc70
1 files changed, 40 insertions, 30 deletions
diff --git a/sql/sql_base.cc b/sql/sql_base.cc
index e3ce2adf862..44d68f35ab2 100644
--- a/sql/sql_base.cc
+++ b/sql/sql_base.cc
@@ -2494,6 +2494,7 @@ retry_share:
err_lock:
tdc_release_share(share);
+ DBUG_PRINT("exit", ("failed"));
DBUG_RETURN(TRUE);
}
@@ -6456,7 +6457,7 @@ find_field_in_tables(THD *thd, Item_ident *item,
*/
if (db)
return cur_field;
-
+
if (found)
{
if (report_error == REPORT_ALL_ERRORS ||
@@ -6471,7 +6472,7 @@ find_field_in_tables(THD *thd, Item_ident *item,
if (found)
return found;
-
+
/*
If the field was qualified and there were no tables to search, issue
an error that an unknown table was given. The situation is detected
@@ -7398,10 +7399,16 @@ err:
order, thus when we iterate over it, we are moving from the right
to the left in the FROM clause.
+ NOTES
+ We can't run this many times as the first_name_resolution_table would
+ be different for subsequent runs when sub queries has been optimized
+ away.
+
RETURN
TRUE Error
FALSE OK
*/
+
static bool setup_natural_join_row_types(THD *thd,
List<TABLE_LIST> *from_clause,
Name_resolution_context *context)
@@ -7411,6 +7418,19 @@ static bool setup_natural_join_row_types(THD *thd,
if (from_clause->elements == 0)
DBUG_RETURN(false); /* We come here in the case of UNIONs. */
+ /*
+ Do not redo work if already done:
+ 1) for stored procedures,
+ 2) for multitable update after lock failure and table reopening.
+ */
+ if (!context->select_lex->first_natural_join_processing)
+ {
+ context->first_name_resolution_table= context->natural_join_first_table;
+ DBUG_PRINT("info", ("using cached setup_natural_join_row_types"));
+ DBUG_RETURN(false);
+ }
+ context->select_lex->first_natural_join_processing= false;
+
List_iterator_fast<TABLE_LIST> table_ref_it(*from_clause);
TABLE_LIST *table_ref; /* Current table reference. */
/* Table reference to the left of the current. */
@@ -7427,22 +7447,15 @@ static bool setup_natural_join_row_types(THD *thd,
left_neighbor= table_ref_it++;
}
while (left_neighbor && left_neighbor->sj_subq_pred);
- /*
- Do not redo work if already done:
- 1) for stored procedures,
- 2) for multitable update after lock failure and table reopening.
- */
- if (context->select_lex->first_natural_join_processing)
+
+ if (store_top_level_join_columns(thd, table_ref,
+ left_neighbor, right_neighbor))
+ DBUG_RETURN(true);
+ if (left_neighbor)
{
- if (store_top_level_join_columns(thd, table_ref,
- left_neighbor, right_neighbor))
- DBUG_RETURN(true);
- if (left_neighbor)
- {
- TABLE_LIST *first_leaf_on_the_right;
- first_leaf_on_the_right= table_ref->first_leaf_for_name_resolution();
- left_neighbor->next_name_resolution_table= first_leaf_on_the_right;
- }
+ TABLE_LIST *first_leaf_on_the_right;
+ first_leaf_on_the_right= table_ref->first_leaf_for_name_resolution();
+ left_neighbor->next_name_resolution_table= first_leaf_on_the_right;
}
right_neighbor= table_ref;
}
@@ -7456,8 +7469,11 @@ static bool setup_natural_join_row_types(THD *thd,
DBUG_ASSERT(right_neighbor);
context->first_name_resolution_table=
right_neighbor->first_leaf_for_name_resolution();
- context->select_lex->first_natural_join_processing= false;
-
+ /*
+ This is only to ensure that first_name_resolution_table doesn't
+ change on re-execution
+ */
+ context->natural_join_first_table= context->first_name_resolution_table;
DBUG_RETURN (false);
}
@@ -7803,12 +7819,9 @@ bool setup_tables(THD *thd, Name_resolution_context *context,
if (table_list->merge_underlying_list)
{
DBUG_ASSERT(table_list->is_merged_derived());
- Query_arena *arena= thd->stmt_arena, backup;
+ Query_arena *arena, backup;
+ arena= thd->activate_stmt_arena_if_needed(&backup);
bool res;
- if (arena->is_conventional())
- arena= 0; // For easier test
- else
- thd->set_n_backup_active_arena(arena, &backup);
res= table_list->setup_underlying(thd);
if (arena)
thd->restore_active_arena(arena, &backup);
@@ -8059,7 +8072,7 @@ insert_fields(THD *thd, Name_resolution_context *context, const char *db_name,
if (!(item= field_iterator.create_item(thd)))
DBUG_RETURN(TRUE);
-// DBUG_ASSERT(item->fixed);
+
/* cache the table for the Item_fields inserted by expanding stars */
if (item->type() == Item::FIELD_ITEM && tables->cacheable_table)
((Item_field *)item)->cached_table= tables;
@@ -8187,11 +8200,8 @@ void wrap_ident(THD *thd, Item **conds)
{
Item_direct_ref_to_ident *wrapper;
DBUG_ASSERT((*conds)->type() == Item::FIELD_ITEM || (*conds)->type() == Item::REF_ITEM);
- Query_arena *arena= thd->stmt_arena, backup;
- if (arena->is_conventional())
- arena= 0;
- else
- thd->set_n_backup_active_arena(arena, &backup);
+ Query_arena *arena, backup;
+ arena= thd->activate_stmt_arena_if_needed(&backup);
if ((wrapper= new Item_direct_ref_to_ident((Item_ident *)(*conds))))
(*conds)= (Item*) wrapper;
if (arena)