Commit 8e2032e8 authored by unknown's avatar unknown

Merge rolltop.ignatz42.dyndns.org:/mnt/storeage/bug20836/my50-bug20836

into  rolltop.ignatz42.dyndns.org:/mnt/storeage/bug20836/my51-bug20836


mysql-test/r/distinct.result:
  Auto merged
sql/sql_class.cc:
  Auto merged
sql/sql_class.h:
  Auto merged
parents 02df1593 0969a7c4
......@@ -437,3 +437,70 @@ EXPLAIN SELECT DISTINCT a,a FROM t1 WHERE b < 12 ORDER BY a;
SELECT DISTINCT a,a FROM t1 WHERE b < 12 ORDER BY a;
DROP TABLE t1;
# The test case for bug#20836 should be re-enabled when bug#16861 is resolved
# The results for the test should be the same as in 4.1.
#
#Bug #20836: Selecting into variables results in wrong results being returned
#
#--disable_warnings
#DROP TABLE IF EXISTS t1;
#--enable_warnings
#
#CREATE TABLE t1 (id INT NOT NULL, fruit_id INT NOT NULL, fruit_name varchar(20)
#default NULL);
#
#INSERT INTO t1 VALUES (1,1,'ORANGE');
#INSERT INTO t1 VALUES (2,2,'APPLE');
#INSERT INTO t1 VALUES (3,2,'APPLE');
#INSERT INTO t1 VALUES (4,3,'PEAR');
#
#SELECT DISTINCT fruit_id, fruit_name INTO @v1, @v2 FROM t1 WHERE fruit_name =
#'APPLE';
#SELECT @v1, @v2;
#
#SELECT DISTINCT fruit_id, fruit_name INTO @v3, @v4 FROM t1 GROUP BY fruit_id,
#fruit_name HAVING fruit_name = 'APPLE';
#SELECT @v3, @v4;
#
#SELECT DISTINCT @v5:= fruit_id, @v6:= fruit_name INTO @v7, @v8 FROM t1 WHERE
#fruit_name = 'APPLE';
#SELECT @v5, @v6, @v7, @v8;
#
#SELECT DISTINCT @v5 + fruit_id, CONCAT(@v6, fruit_name) INTO @v9, @v10 FROM t1
#WHERE fruit_name = 'APPLE';
#SELECT @v5, @v6, @v7, @v8, @v9, @v10;
#
#SELECT DISTINCT @v11:= @v5 + fruit_id, @v12:= CONCAT(@v6, fruit_name) INTO
#@v13, @v14 FROM t1 WHERE fruit_name = 'APPLE';
#SELECT @v11, @v12, @v13, @v14;
#
#SELECT DISTINCT @v13, @v14 INTO @v15, @v16 FROM t1 WHERE fruit_name = 'APPLE';
#SELECT @v15, @v16;
#
#SELECT DISTINCT 2 + 2, 'Bob' INTO @v17, @v18 FROM t1 WHERE fruit_name =
#'APPLE';
#SELECT @v17, @v18;
#
#--disable_warnings
#DROP TABLE IF EXISTS t2;
#--enable_warnings
#
#CREATE TABLE t2 (fruit_id INT NOT NULL, fruit_name varchar(20)
#default NULL);
#
#SELECT DISTINCT fruit_id, fruit_name INTO OUTFILE
#'../tmp/data1.tmp' FROM t1 WHERE fruit_name = 'APPLE';
#LOAD DATA INFILE '../tmp/data1.tmp' INTO TABLE t2;
#--exec rm $MYSQL_TEST_DIR/var/tmp/data1.tmp
#
#SELECT DISTINCT @v19:= fruit_id, @v20:= fruit_name INTO OUTFILE
#'../tmp/data2.tmp' FROM t1 WHERE fruit_name = 'APPLE';
#LOAD DATA INFILE '../tmp/data2.tmp' INTO TABLE t2;
#--exec rm $MYSQL_TEST_DIR/var/tmp/data2.tmp
#
#SELECT @v19, @v20;
#SELECT * FROM t2;
#
#DROP TABLE t1;
#DROP TABLE t2;
......@@ -1613,53 +1613,21 @@ bool select_exists_subselect::send_data(List<Item> &items)
int select_dumpvar::prepare(List<Item> &list, SELECT_LEX_UNIT *u)
{
List_iterator_fast<Item> li(list);
List_iterator_fast<my_var> gl(var_list);
Item *item;
local_vars.empty(); // Clear list if SP
unit= u;
row_count= 0;
if (var_list.elements != list.elements)
{
my_message(ER_WRONG_NUMBER_OF_COLUMNS_IN_SELECT,
ER(ER_WRONG_NUMBER_OF_COLUMNS_IN_SELECT), MYF(0));
return 1;
}
while ((item=li++))
{
my_var *mv= gl++;
if (mv->local)
{
Item_splocal *var= new Item_splocal(mv->s, mv->offset, mv->type);
(void)local_vars.push_back(var);
#ifndef DBUG_OFF
var->m_sp= mv->sp;
#endif
}
else
{
Item_func_set_user_var *var= new Item_func_set_user_var(mv->s, item);
/*
Item_func_set_user_var can't substitute something else on its place =>
0 can 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
*/
var->fix_fields(thd, 0);
var->fix_length_and_dec();
vars.push_back(var);
}
}
}
return 0;
}
void select_dumpvar::cleanup()
{
vars.empty();
row_count=0;
row_count= 0;
}
......@@ -1968,13 +1936,10 @@ Statement_map::~Statement_map()
bool select_dumpvar::send_data(List<Item> &items)
{
List_iterator_fast<Item_func_set_user_var> li(vars);
List_iterator_fast<Item_splocal> var_li(local_vars);
List_iterator_fast<my_var> my_li(var_list);
List_iterator_fast<my_var> var_li(var_list);
List_iterator<Item> it(items);
Item_func_set_user_var *xx;
Item_splocal *yy;
my_var *zz;
Item *item;
my_var *mv;
DBUG_ENTER("select_dumpvar::send_data");
if (unit->offset_limit_cnt)
......@@ -1987,24 +1952,27 @@ bool select_dumpvar::send_data(List<Item> &items)
my_message(ER_TOO_MANY_ROWS, ER(ER_TOO_MANY_ROWS), MYF(0));
DBUG_RETURN(1);
}
while ((zz=my_li++) && (it++))
while ((mv= var_li++) && (item= it++))
{
if (zz->local)
if (mv->local)
{
if ((yy=var_li++))
{
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
{
if ((xx=li++))
{
xx->check(0);
xx->update();
}
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
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, 0);
suv->check(0);
suv->update();
}
}
DBUG_RETURN(0);
......
......@@ -2170,9 +2170,7 @@ class select_dumpvar :public select_result_interceptor {
ha_rows row_count;
public:
List<my_var> var_list;
List<Item_func_set_user_var> vars;
List<Item_splocal> local_vars;
select_dumpvar(void) { var_list.empty(); local_vars.empty(); vars.empty(); row_count=0;}
select_dumpvar() { var_list.empty(); row_count= 0;}
~select_dumpvar() {}
int prepare(List<Item> &list, SELECT_LEX_UNIT *u);
bool send_data(List<Item> &items);
......
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