[Commits] 59e0d3f0f61: MDEV-15424: Unreasonable SQL Error (1356) on select from view
revision-id: 59e0d3f0f61968f89f3272c68723744fde5263cc (mariadb-10.2.19-54-g59e0d3f0f61) parent(s): e3dda3d95ee4c09c2ed45ce886ecd25d1fc1ae92 author: Varun Gupta committer: Varun Gupta timestamp: 2018-12-15 02:32:07 +0530 message: 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. --- mysql-test/r/udf.result | 14 ++++++++++++++ mysql-test/r/win.result | 19 +++++++++++++++++++ mysql-test/t/udf.test | 13 +++++++++++++ mysql-test/t/win.test | 14 ++++++++++++++ sql/item.cc | 4 +++- sql/item_func.cc | 2 ++ 6 files changed, 65 insertions(+), 1 deletion(-) diff --git a/mysql-test/r/udf.result b/mysql-test/r/udf.result index 98aa2b50fc6..3a84caa828a 100644 --- a/mysql-test/r/udf.result +++ b/mysql-test/r/udf.result @@ -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; diff --git a/mysql-test/r/win.result b/mysql-test/r/win.result index 4ffa9f34c1d..c83cc6cd170 100644 --- a/mysql-test/r/win.result +++ b/mysql-test/r/win.result @@ -3457,3 +3457,22 @@ i row_number() over (partition by i order by i) deallocate prepare stmt; drop table t1; drop view v1; +# +# 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; diff --git a/mysql-test/t/udf.test b/mysql-test/t/udf.test index 42a813b0782..881e753de7d 100644 --- a/mysql-test/t/udf.test +++ b/mysql-test/t/udf.test @@ -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; diff --git a/mysql-test/t/win.test b/mysql-test/t/win.test index 807d394edd3..73bb8c46e3f 100644 --- a/mysql-test/t/win.test +++ b/mysql-test/t/win.test @@ -2216,3 +2216,17 @@ execute stmt; deallocate prepare stmt; drop table t1; drop view v1; + +--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; diff --git a/sql/item.cc b/sql/item.cc index 25fb9be22eb..40306b3cb72 100644 --- a/sql/item.cc +++ b/sql/item.cc @@ -7803,7 +7803,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; diff --git a/sql/item_func.cc b/sql/item_func.cc index dcf3a6f3c29..3e2f4257e12 100644 --- a/sql/item_func.cc +++ b/sql/item_func.cc @@ -3481,6 +3481,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;
participants (1)
-
Varun