mirror of
https://github.com/MariaDB/server.git
synced 2025-08-08 11:22:35 +03:00
Merge branch '10.6' into 10.11
This commit is contained in:
@@ -19,6 +19,7 @@
|
||||
|
||||
#include "mariadb.h"
|
||||
#include "sql_base.h" // setup_table_map
|
||||
#include "sql_list.h"
|
||||
#include "sql_priv.h"
|
||||
#include "unireg.h"
|
||||
#include "debug_sync.h"
|
||||
@@ -1175,7 +1176,6 @@ TABLE_LIST* find_dup_table(THD *thd, TABLE_LIST *table, TABLE_LIST *table_list,
|
||||
t_name= &table->table_name;
|
||||
t_alias= &table->alias;
|
||||
|
||||
retry:
|
||||
DBUG_PRINT("info", ("real table: %s.%s", d_name->str, t_name->str));
|
||||
for (TABLE_LIST *tl= table_list; tl ; tl= tl->next_global, res= 0)
|
||||
{
|
||||
@@ -1237,28 +1237,53 @@ retry:
|
||||
DBUG_PRINT("info",
|
||||
("found same copy of table or table which we should skip"));
|
||||
}
|
||||
if (res && res->belong_to_derived)
|
||||
{
|
||||
/*
|
||||
We come here for queries of type:
|
||||
INSERT INTO t1 (SELECT tmp.a FROM (select * FROM t1) as tmp);
|
||||
|
||||
Try to fix by materializing the derived table
|
||||
*/
|
||||
TABLE_LIST *derived= res->belong_to_derived;
|
||||
if (derived->is_merged_derived() && !derived->derived->is_excluded())
|
||||
{
|
||||
DBUG_PRINT("info",
|
||||
("convert merged to materialization to resolve the conflict"));
|
||||
derived->change_refs_to_fields();
|
||||
derived->set_materialized_derived();
|
||||
goto retry;
|
||||
}
|
||||
}
|
||||
DBUG_RETURN(res);
|
||||
}
|
||||
|
||||
|
||||
TABLE_LIST* unique_table_in_select_list(THD *thd, TABLE_LIST *table, SELECT_LEX *sel)
|
||||
{
|
||||
subselect_table_finder_param param= {thd, table, NULL};
|
||||
List_iterator_fast<Item> it(sel->item_list);
|
||||
Item *item;
|
||||
while ((item= it++))
|
||||
{
|
||||
if (item->walk(&Item::subselect_table_finder_processor, FALSE, ¶m))
|
||||
{
|
||||
if (param.dup == NULL)
|
||||
return ERROR_TABLE;
|
||||
return param.dup;
|
||||
}
|
||||
DBUG_ASSERT(param.dup == NULL);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
typedef TABLE_LIST* (*find_table_callback)(THD *thd, TABLE_LIST *table,
|
||||
TABLE_LIST *table_list,
|
||||
uint check_flag, SELECT_LEX *sel);
|
||||
|
||||
static
|
||||
TABLE_LIST*
|
||||
find_table(THD *thd, TABLE_LIST *table, TABLE_LIST *table_list,
|
||||
uint check_flag, SELECT_LEX *sel, find_table_callback callback );
|
||||
|
||||
TABLE_LIST* unique_table_callback(THD *thd, TABLE_LIST *table,
|
||||
TABLE_LIST *table_list,
|
||||
uint check_flag, SELECT_LEX *sel)
|
||||
{
|
||||
return find_dup_table(thd, table, table_list, check_flag);
|
||||
}
|
||||
|
||||
|
||||
TABLE_LIST* unique_in_sel_table_callback(THD *thd, TABLE_LIST *table,
|
||||
TABLE_LIST *table_list,
|
||||
uint check_flag, SELECT_LEX *sel)
|
||||
{
|
||||
return unique_table_in_select_list(thd, table, sel);
|
||||
}
|
||||
|
||||
/**
|
||||
Test that the subject table of INSERT/UPDATE/DELETE/CREATE
|
||||
or (in case of MyISAMMRG) one of its children are not used later
|
||||
@@ -1277,6 +1302,25 @@ retry:
|
||||
TABLE_LIST*
|
||||
unique_table(THD *thd, TABLE_LIST *table, TABLE_LIST *table_list,
|
||||
uint check_flag)
|
||||
{
|
||||
return find_table(thd, table, table_list, check_flag, NULL,
|
||||
&unique_table_callback);
|
||||
}
|
||||
|
||||
|
||||
TABLE_LIST*
|
||||
unique_table_in_insert_returning_subselect(THD *thd, TABLE_LIST *table, SELECT_LEX *sel)
|
||||
{
|
||||
return find_table(thd, table, NULL, 0, sel,
|
||||
&unique_in_sel_table_callback);
|
||||
|
||||
}
|
||||
|
||||
|
||||
static
|
||||
TABLE_LIST*
|
||||
find_table(THD *thd, TABLE_LIST *table, TABLE_LIST *table_list,
|
||||
uint check_flag, SELECT_LEX *sel, find_table_callback callback )
|
||||
{
|
||||
TABLE_LIST *dup;
|
||||
|
||||
@@ -1308,12 +1352,12 @@ unique_table(THD *thd, TABLE_LIST *table, TABLE_LIST *table_list,
|
||||
if (!tmp_parent)
|
||||
break;
|
||||
|
||||
if ((dup= find_dup_table(thd, child, child->next_global, check_flag)))
|
||||
if ((dup= (*callback)(thd, child, child->next_global, check_flag, sel)))
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
dup= find_dup_table(thd, table, table_list, check_flag);
|
||||
dup= (*callback)(thd, table, table_list, check_flag, sel);
|
||||
return dup;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user