Commit 979f27ee authored by bell@sanja.is.com.ua's avatar bell@sanja.is.com.ua

fixed bug in cyclic reference refinition

parent b724f02c
......@@ -10,6 +10,8 @@ SELECT (SELECT (SELECT 0 UNION SELECT 0));
0
SELECT (SELECT 1 FROM (SELECT 1) HAVING a=1) as a;
Cyclic reference on subqueries
SELECT (SELECT 1 FROM (SELECT 1) HAVING b=1) as a,(SELECT 1 FROM (SELECT 1) HAVING a=1) as b;
Cyclic reference on subqueries
drop table if exists t1,t2,t3,t4,t5,attend,clinic,inscrit;
create table t1 (a int);
create table t2 (a int, b int);
......
......@@ -3,6 +3,8 @@ SELECT (SELECT 1) UNION SELECT (SELECT 2);
SELECT (SELECT (SELECT 0 UNION SELECT 0));
-- error 1243
SELECT (SELECT 1 FROM (SELECT 1) HAVING a=1) as a;
-- error 1243
SELECT (SELECT 1 FROM (SELECT 1) HAVING b=1) as a,(SELECT 1 FROM (SELECT 1) HAVING a=1) as b;
drop table if exists t1,t2,t3,t4,t5,attend,clinic,inscrit;
create table t1 (a int);
create table t2 (a int, b int);
......
......@@ -876,11 +876,7 @@ bool Item_ref::fix_fields(THD *thd,TABLE_LIST *tables, Item **reference)
{
depended_from= last;
thd->lex.current_select->mark_as_dependent(last);
if (check_loop(thd->check_loops_counter++))
{
my_message(ER_CYCLIC_REFERENCE, ER(ER_CYCLIC_REFERENCE), MYF(0));
return 1;
}
thd->add_possible_loop(this);
}
}
else if (!ref)
......
......@@ -434,6 +434,15 @@ void THD::close_active_vio()
}
#endif
void THD::add_possible_loop (Item *item)
{
if (!possible_loops)
{
possible_loops= new List<Item>;
}
possible_loops->push_back(item);
}
/*****************************************************************************
** Functions to provide a interface to select results
*****************************************************************************/
......
......@@ -482,6 +482,7 @@ public:
USER_CONN *user_connect;
CHARSET_INFO *db_charset;
CHARSET_INFO *thd_charset;
List<Item> *possible_loops; // Items that may cause loops in subselects
List <MYSQL_ERROR> warn_list;
uint warn_count[(uint) MYSQL_ERROR::WARN_LEVEL_END];
uint total_warn_count, old_total_warn_count;
......@@ -632,6 +633,7 @@ public:
net.last_errno= 0;
net.report_error= 0;
}
void add_possible_loop(Item *);
};
/*
......
......@@ -2862,7 +2862,8 @@ mysql_init_query(THD *thd)
lex->select_lex.init_query();
lex->value_list.empty();
lex->param_list.empty();
lex->unit.global_parameters= lex->unit.slave= lex->current_select= &lex->select_lex;
lex->unit.global_parameters= lex->unit.slave= lex->current_select=
&lex->select_lex;
lex->select_lex.master= &lex->unit;
lex->select_lex.prev= &lex->unit.slave;
lex->olap=lex->describe=0;
......@@ -2875,6 +2876,7 @@ mysql_init_query(THD *thd)
thd->sent_row_count= thd->examined_row_count= 0;
thd->fatal_error= thd->rand_used=0;
thd->safe_to_cache_query= 1;
thd->possible_loops= 0;
DBUG_VOID_RETURN;
}
......
......@@ -1087,6 +1087,23 @@ mysql_select(THD *thd, TABLE_LIST *tables, List<Item> &fields, COND *conds,
{
DBUG_RETURN(-1);
}
if (thd->possible_loops)
{
Item *item;
while(thd->possible_loops->elements)
{
item= thd->possible_loops->pop();
if (item->check_loop(thd->check_loops_counter++))
{
delete thd->possible_loops;
thd->possible_loops= 0;
my_message(ER_CYCLIC_REFERENCE, ER(ER_CYCLIC_REFERENCE), MYF(0));
return 1;
}
}
delete thd->possible_loops;
thd->possible_loops= 0;
}
}
switch (join->optimize())
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment