mirror of
https://github.com/MariaDB/server.git
synced 2025-09-02 09:41:40 +03:00
Fixed bug mdev-10660.
The method Item_sum::print did not print opening '(' after the name of simple window functions (like rank, dense_rank etc). As a result the view definitions with such window functions were formed invalid in .frm files.
This commit is contained in:
@@ -456,7 +456,7 @@ pk, c,
|
|||||||
row_number() over (partition by c order by pk
|
row_number() over (partition by c order by pk
|
||||||
range between unbounded preceding and current row) as r
|
range between unbounded preceding and current row) as r
|
||||||
from t1;
|
from t1;
|
||||||
ERROR HY000: Window frame is not allowed with 'row_number('
|
ERROR HY000: Window frame is not allowed with 'row_number'
|
||||||
select
|
select
|
||||||
pk, c,
|
pk, c,
|
||||||
rank() over w1 as r
|
rank() over w1 as r
|
||||||
@@ -2463,8 +2463,8 @@ drop table t1;
|
|||||||
#
|
#
|
||||||
# MDEV-11594: window function over implicit grouping
|
# MDEV-11594: window function over implicit grouping
|
||||||
#
|
#
|
||||||
create table test.t1 (id int);
|
create table t1 (id int);
|
||||||
insert into test.t1 values (1), (2), (3), (2);
|
insert into t1 values (1), (2), (3), (2);
|
||||||
select sum(id) over (order by sum(id)) from t1;
|
select sum(id) over (order by sum(id)) from t1;
|
||||||
sum(id) over (order by sum(id))
|
sum(id) over (order by sum(id))
|
||||||
1
|
1
|
||||||
@@ -2476,8 +2476,8 @@ drop table t1;
|
|||||||
# MDEV-9923: integer constant in order by list
|
# MDEV-9923: integer constant in order by list
|
||||||
# of window specification
|
# of window specification
|
||||||
#
|
#
|
||||||
create table test.t1 (id int);
|
create table t1 (id int);
|
||||||
insert into test.t1 values (1), (2), (3), (2);
|
insert into t1 values (1), (2), (3), (2);
|
||||||
select rank() over (order by 1) from t1;
|
select rank() over (order by 1) from t1;
|
||||||
rank() over (order by 1)
|
rank() over (order by 1)
|
||||||
1
|
1
|
||||||
@@ -2497,3 +2497,27 @@ rank() over (partition by id order by 2)
|
|||||||
1
|
1
|
||||||
1
|
1
|
||||||
drop table t1;
|
drop table t1;
|
||||||
|
#
|
||||||
|
# MDEV-10660: view using a simple window function
|
||||||
|
#
|
||||||
|
create table t1 (id int);
|
||||||
|
insert into t1 values (1), (2), (3), (2);
|
||||||
|
create view v1(id,rnk) as
|
||||||
|
select id, rank() over (order by id) from t1;
|
||||||
|
show create view v1;
|
||||||
|
View Create View character_set_client collation_connection
|
||||||
|
v1 CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v1` AS select `t1`.`id` AS `id`,rank() over ( order by `t1`.`id`) AS `rnk` from `t1` latin1 latin1_swedish_ci
|
||||||
|
select id, rank() over (order by id) from t1;
|
||||||
|
id rank() over (order by id)
|
||||||
|
1 1
|
||||||
|
2 2
|
||||||
|
3 4
|
||||||
|
2 2
|
||||||
|
select * from v1;
|
||||||
|
id rnk
|
||||||
|
1 1
|
||||||
|
2 2
|
||||||
|
3 4
|
||||||
|
2 2
|
||||||
|
drop view v1;
|
||||||
|
drop table t1;
|
||||||
|
@@ -1495,8 +1495,8 @@ drop table t1;
|
|||||||
--echo # MDEV-11594: window function over implicit grouping
|
--echo # MDEV-11594: window function over implicit grouping
|
||||||
--echo #
|
--echo #
|
||||||
|
|
||||||
create table test.t1 (id int);
|
create table t1 (id int);
|
||||||
insert into test.t1 values (1), (2), (3), (2);
|
insert into t1 values (1), (2), (3), (2);
|
||||||
|
|
||||||
select sum(id) over (order by sum(id)) from t1;
|
select sum(id) over (order by sum(id)) from t1;
|
||||||
|
|
||||||
@@ -1509,11 +1509,29 @@ drop table t1;
|
|||||||
--echo # of window specification
|
--echo # of window specification
|
||||||
--echo #
|
--echo #
|
||||||
|
|
||||||
create table test.t1 (id int);
|
create table t1 (id int);
|
||||||
insert into test.t1 values (1), (2), (3), (2);
|
insert into t1 values (1), (2), (3), (2);
|
||||||
|
|
||||||
select rank() over (order by 1) from t1;
|
select rank() over (order by 1) from t1;
|
||||||
select rank() over (order by 2) from t1;
|
select rank() over (order by 2) from t1;
|
||||||
select rank() over (partition by id order by 2) from t1;
|
select rank() over (partition by id order by 2) from t1;
|
||||||
|
|
||||||
drop table t1;
|
drop table t1;
|
||||||
|
|
||||||
|
--echo #
|
||||||
|
--echo # MDEV-10660: view using a simple window function
|
||||||
|
--echo #
|
||||||
|
|
||||||
|
create table t1 (id int);
|
||||||
|
insert into t1 values (1), (2), (3), (2);
|
||||||
|
|
||||||
|
create view v1(id,rnk) as
|
||||||
|
select id, rank() over (order by id) from t1;
|
||||||
|
|
||||||
|
show create view v1;
|
||||||
|
|
||||||
|
select id, rank() over (order by id) from t1;
|
||||||
|
select * from v1;
|
||||||
|
|
||||||
|
drop view v1;
|
||||||
|
drop table t1;
|
||||||
|
@@ -471,6 +471,13 @@ void Item_sum::print(String *str, enum_query_type query_type)
|
|||||||
/* orig_args is not filled with valid values until fix_fields() */
|
/* orig_args is not filled with valid values until fix_fields() */
|
||||||
Item **pargs= fixed ? orig_args : args;
|
Item **pargs= fixed ? orig_args : args;
|
||||||
str->append(func_name());
|
str->append(func_name());
|
||||||
|
/*
|
||||||
|
TODO:
|
||||||
|
The fact that func_name() may return a name with an extra '('
|
||||||
|
is really annoying. This shoud be fixed.
|
||||||
|
*/
|
||||||
|
if (!is_aggr_sum_func())
|
||||||
|
str->append('(');
|
||||||
for (uint i=0 ; i < arg_count ; i++)
|
for (uint i=0 ; i < arg_count ; i++)
|
||||||
{
|
{
|
||||||
if (i)
|
if (i)
|
||||||
@@ -594,7 +601,9 @@ Item *Item_sum::result_item(THD *thd, Field *field)
|
|||||||
|
|
||||||
bool Item_sum::check_vcol_func_processor(void *arg)
|
bool Item_sum::check_vcol_func_processor(void *arg)
|
||||||
{
|
{
|
||||||
return mark_unsupported_function(func_name(), ")", arg, VCOL_IMPOSSIBLE);
|
return mark_unsupported_function(func_name(),
|
||||||
|
is_aggr_sum_func() ? ")" : "()",
|
||||||
|
arg, VCOL_IMPOSSIBLE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@@ -409,10 +409,31 @@ public:
|
|||||||
Item_sum(THD *thd, Item_sum *item);
|
Item_sum(THD *thd, Item_sum *item);
|
||||||
enum Type type() const { return SUM_FUNC_ITEM; }
|
enum Type type() const { return SUM_FUNC_ITEM; }
|
||||||
virtual enum Sumfunctype sum_func () const=0;
|
virtual enum Sumfunctype sum_func () const=0;
|
||||||
|
bool is_aggr_sum_func()
|
||||||
|
{
|
||||||
|
switch (sum_func()) {
|
||||||
|
case COUNT_FUNC:
|
||||||
|
case COUNT_DISTINCT_FUNC:
|
||||||
|
case SUM_FUNC:
|
||||||
|
case SUM_DISTINCT_FUNC:
|
||||||
|
case AVG_FUNC:
|
||||||
|
case AVG_DISTINCT_FUNC:
|
||||||
|
case MIN_FUNC:
|
||||||
|
case MAX_FUNC:
|
||||||
|
case STD_FUNC:
|
||||||
|
case VARIANCE_FUNC:
|
||||||
|
case SUM_BIT_FUNC:
|
||||||
|
case UDF_SUM_FUNC:
|
||||||
|
case GROUP_CONCAT_FUNC:
|
||||||
|
return true;
|
||||||
|
default:
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
Resets the aggregate value to its default and aggregates the current
|
Resets the aggregate value to its default and aggregates the current
|
||||||
value of its attribute(s).
|
value of its attribute(s).
|
||||||
*/
|
*/
|
||||||
inline bool reset_and_add()
|
inline bool reset_and_add()
|
||||||
{
|
{
|
||||||
aggregator_clear();
|
aggregator_clear();
|
||||||
|
@@ -127,7 +127,7 @@ public:
|
|||||||
}
|
}
|
||||||
const char*func_name() const
|
const char*func_name() const
|
||||||
{
|
{
|
||||||
return "row_number(";
|
return "row_number";
|
||||||
}
|
}
|
||||||
|
|
||||||
Item *get_copy(THD *thd, MEM_ROOT *mem_root)
|
Item *get_copy(THD *thd, MEM_ROOT *mem_root)
|
||||||
|
Reference in New Issue
Block a user