Commit 82a4d55d authored by Varun Gupta's avatar Varun Gupta

MDEV-15424: Unreasonable SQL Error (1356) on select from view

While printing a view containing a window function we were printing it as an
Item_field object instead of an Item_window_func object. This is incorrect and this
leads to us throwing an error ER_VIEW_INVALID.
Fixed by adjusting the Item_ref:print function.
Also made UDF function aware if there arguments have window function.
parent 0c2fc9b3
......@@ -465,3 +465,17 @@ a b
Hello HL
DROP FUNCTION METAPHON;
DROP TABLE t1;
#
# MDEV-15424: Unreasonal SQL Error (1356) on select from view
#
CREATE FUNCTION myfunc_int RETURNS INTEGER SONAME "UDF_EXAMPLE_LIB";
create table t1(a int , b int);
insert into t1 values(100, 54), (200, 199);
create view v1 as select myfunc_int(max(a) over (order by b) , b) from t1;
select * from v1;
myfunc_int(max(a) over (order by b) , b)
154
399
drop view v1;
drop function myfunc_int;
drop table t1;
......@@ -3470,3 +3470,21 @@ SELECT DISTINCT MIN(b1) OVER () FROM t1;
MIN(b1) OVER ()
1
drop table t1;
#
# MDEV-15424: Unreasonal SQL Error (1356) on select from view
#
create table t1 (id int, n1 int);
insert into t1 values (1,1), (2,1), (3,2), (4,4);
create view v1 as SELECT ifnull(max(n1) over (partition by n1),'aaa') FROM t1;
explain select * from v1;
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY <derived2> ALL NULL NULL NULL NULL 4
2 DERIVED t1 ALL NULL NULL NULL NULL 4 Using temporary
select * from v1;
ifnull(max(n1) over (partition by n1),'aaa')
1
1
2
4
drop table t1;
drop view v1;
......@@ -528,3 +528,16 @@ DROP FUNCTION METAPHON;
#INSERT INTO t1 (a) VALUES ('Hello');
#SELECT * FROM t1;
DROP TABLE t1;
--echo #
--echo # MDEV-15424: Unreasonal SQL Error (1356) on select from view
--echo #
--replace_result $UDF_EXAMPLE_SO UDF_EXAMPLE_LIB
eval CREATE FUNCTION myfunc_int RETURNS INTEGER SONAME "$UDF_EXAMPLE_SO";
create table t1(a int , b int);
insert into t1 values(100, 54), (200, 199);
create view v1 as select myfunc_int(max(a) over (order by b) , b) from t1;
select * from v1;
drop view v1;
drop function myfunc_int;
drop table t1;
......@@ -2227,3 +2227,16 @@ EXPLAIN
SELECT DISTINCT MIN(b1) OVER () FROM t1;
SELECT DISTINCT MIN(b1) OVER () FROM t1;
drop table t1;
--echo #
--echo # MDEV-15424: Unreasonal SQL Error (1356) on select from view
--echo #
create table t1 (id int, n1 int);
insert into t1 values (1,1), (2,1), (3,2), (4,4);
create view v1 as SELECT ifnull(max(n1) over (partition by n1),'aaa') FROM t1;
explain select * from v1;
select * from v1;
drop table t1;
drop view v1;
......@@ -7815,7 +7815,9 @@ void Item_ref::print(String *str, enum_query_type query_type)
{
if (ref)
{
if ((*ref)->type() != Item::CACHE_ITEM && ref_type() != VIEW_REF &&
if ((*ref)->type() != Item::CACHE_ITEM &&
(*ref)->type() != Item::WINDOW_FUNC_ITEM &&
ref_type() != VIEW_REF &&
!table_name && name && alias_name_used)
{
THD *thd= current_thd;
......
......@@ -3484,6 +3484,8 @@ udf_handler::fix_fields(THD *thd, Item_func_or_sum *func,
if (item->maybe_null)
func->maybe_null=1;
func->with_sum_func= func->with_sum_func || item->with_sum_func;
func->with_window_func= func->with_window_func ||
item->with_window_func;
func->with_field= func->with_field || item->with_field;
func->with_param= func->with_param || item->with_param;
func->with_subselect|= item->with_subselect;
......
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