From b4aab152723c629fb23322da4988b404ed68986d Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 28 Nov 2006 17:21:39 -0500 Subject: Bug#20836 Selecting into variables results in wrong results being returned This error is displayed anytime the SELECT statement needs a temp table to return correct results because the object (select_dumpvar) that represents variables named in the INTO clause stored the results before the temp table was considered. The problem was fixed by creating the necessary Item_func_set_user_var objects once the correct data is ready. mysql-test/r/distinct.result: Bug#20836 Selecting into variables results in wrong results being returned - Added results mysql-test/t/distinct.test: Bug#20836 Selecting into variables results in wrong results being returned - Added various Selects that use the INTO statement and a temp table. - Added Select Into Outfile variant tests also. sql/sql_class.cc: Bug#20836 Selecting into variables results in wrong results being returned - The select_dumpvar variable created a Item_func_set_user_var too early and once set, it was not possible to change. The Item_func_set_user_var is now created once the final results are available. sql/sql_class.h: Bug#20836 Selecting into variables results in wrong results being returned - Removed unnecessary object members. --- sql/sql_class.cc | 48 ++++++++++++++++++++++-------------------------- sql/sql_class.h | 3 +-- 2 files changed, 23 insertions(+), 28 deletions(-) (limited to 'sql') diff --git a/sql/sql_class.cc b/sql/sql_class.cc index fc9597cba87..cbab172a478 100644 --- a/sql/sql_class.cc +++ b/sql/sql_class.cc @@ -1372,37 +1372,20 @@ bool select_exists_subselect::send_data(List &items) int select_dumpvar::prepare(List &list, SELECT_LEX_UNIT *u) { - List_iterator_fast li(list); - List_iterator_fast gl(var_list); - Item *item; - LEX_STRING *ls; + unit= u; + if (var_list.elements != list.elements) { my_error(ER_WRONG_NUMBER_OF_COLUMNS_IN_SELECT, MYF(0)); return 1; } - unit=u; - while ((item=li++)) - { - ls= gl++; - Item_func_set_user_var *xx = new Item_func_set_user_var(*ls,item); - /* - Item_func_set_user_var can't substitute something else on its place => - 0 can be passed as last argument (reference on item) - */ - xx->fix_fields(thd,(TABLE_LIST*) thd->lex->select_lex.table_list.first, - 0); - xx->fix_length_and_dec(); - vars.push_back(xx); - } return 0; } void select_dumpvar::cleanup() { - vars.empty(); - row_count=0; + row_count= 0; } @@ -1744,12 +1727,14 @@ Statement_map::~Statement_map() bool select_dumpvar::send_data(List &items) { - List_iterator_fast li(vars); - Item_func_set_user_var *xx; + List_iterator_fast var_li(var_list); + List_iterator it(items); + Item *item; + LEX_STRING *ls; DBUG_ENTER("send_data"); if (unit->offset_limit_cnt) - { // Using limit offset,count + { // using limit offset,count unit->offset_limit_cnt--; DBUG_RETURN(0); } @@ -1758,10 +1743,21 @@ bool select_dumpvar::send_data(List &items) my_error(ER_TOO_MANY_ROWS, MYF(0)); DBUG_RETURN(1); } - while ((xx=li++)) + while ((ls= var_li++) && (item= it++)) { - xx->check(); - xx->update(); + Item_func_set_user_var *suv= new Item_func_set_user_var(*ls, item); + + /* + Item_func_set_user_var can't substitute something else on its + place => NULL may be passed as last argument (reference on + item) Item_func_set_user_var can't be fixed after creation, so + we do not check var->fixed + */ + + suv->fix_fields(thd, (TABLE_LIST *) thd->lex->select_lex.table_list.first, + 0); + suv->check(); + suv->update(); } DBUG_RETURN(0); } diff --git a/sql/sql_class.h b/sql/sql_class.h index 7cf0b474ed7..b61403e4b0a 100644 --- a/sql/sql_class.h +++ b/sql/sql_class.h @@ -1573,8 +1573,7 @@ class select_dumpvar :public select_result_interceptor { ha_rows row_count; public: List var_list; - List vars; - select_dumpvar(void) { var_list.empty(); vars.empty(); row_count=0;} + select_dumpvar() { var_list.empty(); row_count= 0;} ~select_dumpvar() {} int prepare(List &list, SELECT_LEX_UNIT *u); bool send_data(List &items); -- cgit v1.2.1 From 1c49e88e4c2ce5df1673f3df804fae089175f2cf Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 30 Nov 2006 13:09:48 -0500 Subject: Bug#20836 Selecting into variables results in wrong results being returned - Post-merge cleanup. - Disabled this bug's test for 5.x until 16861 is resolved. mysql-test/r/distinct.result: Bug#20836 Selecting into variables results in wrong results being returned - Remove results for this bug. When bug number 16861 is resolved, the result should match the 4.1 result. mysql-test/t/distinct.test: Bug#20836 Selecting into variables results in wrong results being returned - Disable the test for 20836. This test should remain disabled until bug 16861 is fixed. The results for the test should be the same as in 4.1. sql/sql_class.cc: Bug#20836 Selecting into variables results in wrong results being returned - Post-merge cleanup. --- sql/sql_class.cc | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) (limited to 'sql') diff --git a/sql/sql_class.cc b/sql/sql_class.cc index a1ad76f84e4..f3c450d28f5 100644 --- a/sql/sql_class.cc +++ b/sql/sql_class.cc @@ -1853,13 +1853,12 @@ bool select_dumpvar::send_data(List &items) { if (mv->local) { - if (thd->spcont->set_variable(current_thd, yy->get_var_idx(), - it.ref())) - DBUG_RETURN(1); + if (thd->spcont->set_variable(thd, mv->offset, &item)) + DBUG_RETURN(1); } else { - Item_func_set_user_var *suv= new Item_func_set_user_var(*ls, item); + Item_func_set_user_var *suv= new Item_func_set_user_var(mv->s, item); /* Item_func_set_user_var can't substitute something else on its @@ -1868,9 +1867,8 @@ bool select_dumpvar::send_data(List &items) we do not check var->fixed */ - suv->fix_fields(thd, (TABLE_LIST *) thd->lex->select_lex.table_list.first, - 0); - suv->check(); + suv->fix_fields(thd, 0); + suv->check(0); suv->update(); } } -- cgit v1.2.1