Commit faf2a6e5 authored by Varun Gupta's avatar Varun Gupta

MDEV-20922: Adding an order by changes the query results

For Item_direct_view_ref , get value from val_* methods
instead of result* family
The val_* methods gets value from the item on which it is referred.
parent 359d91aa
......@@ -2792,3 +2792,19 @@ SELECT 1 IN ( SELECT COUNT( DISTINCT f2 ) FROM t1 WHERE f1 <= 4 );
1 IN ( SELECT COUNT( DISTINCT f2 ) FROM t1 WHERE f1 <= 4 )
0
drop table t1;
#
# MDEV-20922: Adding an order by changes the query results
#
CREATE TABLE t1(a int, b int);
INSERT INTO t1 values (1, 100), (2, 200), (3, 100), (4, 200);
create view v1 as select a, b+1 as x from t1;
SELECT x, COUNT(DISTINCT a) AS y FROM v1 GROUP BY x ORDER BY y;
x y
101 2
201 2
SELECT b+1 AS x, COUNT(DISTINCT a) AS y FROM t1 GROUP BY x ORDER BY y;
x y
101 2
201 2
drop view v1;
drop table t1;
......@@ -1915,3 +1915,17 @@ INSERT INTO t1 VALUES (0,'foo'),(1,'bar');
SELECT 1 IN ( SELECT COUNT( DISTINCT f2 ) FROM t1 WHERE f1 <= 4 );
drop table t1;
--echo #
--echo # MDEV-20922: Adding an order by changes the query results
--echo #
CREATE TABLE t1(a int, b int);
INSERT INTO t1 values (1, 100), (2, 200), (3, 100), (4, 200);
create view v1 as select a, b+1 as x from t1;
SELECT x, COUNT(DISTINCT a) AS y FROM v1 GROUP BY x ORDER BY y;
SELECT b+1 AS x, COUNT(DISTINCT a) AS y FROM t1 GROUP BY x ORDER BY y;
drop view v1;
drop table t1;
......@@ -8149,6 +8149,46 @@ Item *Item_direct_view_ref::replace_equal_field(THD *thd, uchar *arg)
}
double Item_direct_view_ref::val_result()
{
double tmp=(*ref)->val_result();
null_value=(*ref)->null_value;
return tmp;
}
longlong Item_direct_view_ref::val_int_result()
{
longlong tmp=(*ref)->val_int_result();
null_value=(*ref)->null_value;
return tmp;
}
String *Item_direct_view_ref::str_result(String* tmp)
{
tmp=(*ref)->str_result(tmp);
null_value=(*ref)->null_value;
return tmp;
}
my_decimal *Item_direct_view_ref::val_decimal_result(my_decimal *val)
{
my_decimal *tmp= (*ref)->val_decimal_result(val);
null_value=(*ref)->null_value;
return tmp;
}
bool Item_direct_view_ref::val_bool_result()
{
bool tmp= (*ref)->val_bool_result();
null_value=(*ref)->null_value;
return tmp;
}
bool Item_default_value::eq(const Item *item, bool binary_cmp) const
{
return item->type() == DEFAULT_VALUE_ITEM &&
......
......@@ -4477,6 +4477,14 @@ class Item_direct_view_ref :public Item_direct_ref
item_equal= NULL;
Item_direct_ref::cleanup();
}
/*
TODO move these val_*_result function to Item_dierct_ref (maybe)
*/
double val_result();
longlong val_int_result();
String *str_result(String* tmp);
my_decimal *val_decimal_result(my_decimal *val);
bool val_bool_result();
};
......
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