Commit 0d8dc74d authored by Alexander Barkov's avatar Alexander Barkov

Merge remote-tracking branch 'origin/10.2' into bb-10.2-ext

parents 1694c0e8 4ebdef2b
......@@ -2270,17 +2270,6 @@ pk c CNT
8 2 0.5000
9 2 0.6667
10 2 1.0000
Warnings:
Warning 1365 Division by 0
Warning 1365 Division by 0
Warning 1365 Division by 0
Warning 1365 Division by 0
Warning 1365 Division by 0
Warning 1365 Division by 0
Warning 1365 Division by 0
Warning 1365 Division by 0
Warning 1365 Division by 0
Warning 1365 Division by 0
create view v1 as select pk, c, c/count(*) over (partition by c order by pk
rows between 1 preceding and 2 following) as CNT
from t1;
......@@ -2299,17 +2288,6 @@ pk c CNT
8 2 0.5000
9 2 0.6667
10 2 1.0000
Warnings:
Warning 1365 Division by 0
Warning 1365 Division by 0
Warning 1365 Division by 0
Warning 1365 Division by 0
Warning 1365 Division by 0
Warning 1365 Division by 0
Warning 1365 Division by 0
Warning 1365 Division by 0
Warning 1365 Division by 0
Warning 1365 Division by 0
select pk, c, c/count(*) over w1 as CNT from t1
window w1 as (partition by c order by pk rows between 1 preceding and 2 following);
pk c CNT
......@@ -2323,17 +2301,6 @@ pk c CNT
8 2 0.5000
9 2 0.6667
10 2 1.0000
Warnings:
Warning 1365 Division by 0
Warning 1365 Division by 0
Warning 1365 Division by 0
Warning 1365 Division by 0
Warning 1365 Division by 0
Warning 1365 Division by 0
Warning 1365 Division by 0
Warning 1365 Division by 0
Warning 1365 Division by 0
Warning 1365 Division by 0
create view v2 as select pk, c, c/count(*) over w1 as CNT from t1
window w1 as (partition by c order by pk rows between 1 preceding and 2 following);
show create view v2;
......@@ -2351,17 +2318,6 @@ pk c CNT
8 2 0.5000
9 2 0.6667
10 2 1.0000
Warnings:
Warning 1365 Division by 0
Warning 1365 Division by 0
Warning 1365 Division by 0
Warning 1365 Division by 0
Warning 1365 Division by 0
Warning 1365 Division by 0
Warning 1365 Division by 0
Warning 1365 Division by 0
Warning 1365 Division by 0
Warning 1365 Division by 0
select pk, c, c/count(*) over w1 as CNT from t1
window w1 as (partition by c order by pk rows unbounded preceding);
pk c CNT
......@@ -2375,17 +2331,6 @@ pk c CNT
8 2 0.5000
9 2 0.4000
10 2 0.3333
Warnings:
Warning 1365 Division by 0
Warning 1365 Division by 0
Warning 1365 Division by 0
Warning 1365 Division by 0
Warning 1365 Division by 0
Warning 1365 Division by 0
Warning 1365 Division by 0
Warning 1365 Division by 0
Warning 1365 Division by 0
Warning 1365 Division by 0
create view v3 as select pk, c, c/count(*) over w1 as CNT from t1
window w1 as (partition by c order by pk rows unbounded preceding);
show create view v3;
......@@ -2403,17 +2348,6 @@ pk c CNT
8 2 0.5000
9 2 0.4000
10 2 0.3333
Warnings:
Warning 1365 Division by 0
Warning 1365 Division by 0
Warning 1365 Division by 0
Warning 1365 Division by 0
Warning 1365 Division by 0
Warning 1365 Division by 0
Warning 1365 Division by 0
Warning 1365 Division by 0
Warning 1365 Division by 0
Warning 1365 Division by 0
select pk, c, c/count(*) over (partition by c order by pk
range between 3 preceding and current row) as CNT
from t1;
......@@ -2428,17 +2362,6 @@ pk c CNT
8 2 0.5000
9 2 0.5000
10 2 0.5000
Warnings:
Warning 1365 Division by 0
Warning 1365 Division by 0
Warning 1365 Division by 0
Warning 1365 Division by 0
Warning 1365 Division by 0
Warning 1365 Division by 0
Warning 1365 Division by 0
Warning 1365 Division by 0
Warning 1365 Division by 0
Warning 1365 Division by 0
create view v4 as select pk, c, c/count(*) over (partition by c order by pk
range between 3 preceding and current row) as CNT
from t1;
......@@ -2457,17 +2380,6 @@ pk c CNT
8 2 0.5000
9 2 0.5000
10 2 0.5000
Warnings:
Warning 1365 Division by 0
Warning 1365 Division by 0
Warning 1365 Division by 0
Warning 1365 Division by 0
Warning 1365 Division by 0
Warning 1365 Division by 0
Warning 1365 Division by 0
Warning 1365 Division by 0
Warning 1365 Division by 0
Warning 1365 Division by 0
drop view v1,v2,v3,v4;
drop table t0,t1;
#
......@@ -3096,3 +3008,50 @@ select i, rank() over (order by i) rnk from t1 group by 1+2;
i rnk
2 1
drop table t1;
#
# MDEV-11907: window function as the second operand of division
#
create table t1 (pk int, c int);
insert into t1 values (1,1),(2,1),(3,1),(4,1),(5,2);
set @sql_mode_save= @@sql_mode;
set sql_mode='ERROR_FOR_DIVISION_BY_ZERO';
select pk, c, c/count(*) over
(partition by c order by pk
rows between 1 preceding and 2 following) as CNT
from t1;
pk c CNT
1 1 0.3333
2 1 0.2500
3 1 0.3333
4 1 0.5000
5 2 2.0000
show warnings;
Level Code Message
set sql_mode=@sql_mode_save;
drop table t1;
#
# MDEV-12336: several functions over a window function
#
create table t1 (name varchar(10), cnt int);
insert into t1 values ('Fred', 23), ('Fred', 35), ('Joe', 10);
select q.name, q.row_cnt,
round( 100 * ( q.row_cnt /
sum(q.row_cnt) over
(
order by q.name
rows between
unbounded preceding and
unbounded following
)
),2
) pct_of_total
from
(
select name, count(*) row_cnt, sum(cnt) sum_cnt
from t1
group by 1
) q;
name row_cnt pct_of_total
Fred 2 66.67
Joe 1 33.33
drop table t1;
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -583,9 +583,10 @@ sidea DOUBLE,
sideb DOUBLE,
sidec DOUBLE AS (SQRT(sidea * sidea + sideb * sideb))
);
SELECT * FROM information_schema.columns WHERE table_name='gcol_t1';
TABLE_CATALOG TABLE_SCHEMA TABLE_NAME COLUMN_NAME ORDINAL_POSITION COLUMN_DEFAULT IS_NULLABLE DATA_TYPE CHARACTER_MAXIMUM_LENGTH CHARACTER_OCTET_LENGTH NUMERIC_PRECISION NUMERIC_SCALE DATETIME_PRECISION CHARACTER_SET_NAME COLLATION_NAME COLUMN_TYPE COLUMN_KEY EXTRA PRIVILEGES COLUMN_COMMENT IS_GENERATED GENERATION_EXPRESSION
def test gcol_t1 sidea 1 NULL YES double NULL NULL 22 NULL NULL NULL NULL double select,insert,update,references NEVER NULL
def test gcol_t1 sideb 2 NULL YES double NULL NULL 22 NULL NULL NULL NULL double select,insert,update,references NEVER NULL
def test gcol_t1 sidec 3 NULL YES double NULL NULL 22 NULL NULL NULL NULL double VIRTUAL GENERATED select,insert,update,references ALWAYS sqrt(`sidea` * `sidea` + `sideb` * `sideb`)
SELECT table_schema,table_name,column_name,extra,is_generated,generation_expression
FROM information_schema.columns WHERE table_name='gcol_t1';
table_schema table_name column_name extra is_generated generation_expression
test gcol_t1 sidea NEVER NULL
test gcol_t1 sideb NEVER NULL
test gcol_t1 sidec VIRTUAL GENERATED ALWAYS sqrt(`sidea` * `sidea` + `sideb` * `sideb`)
DROP TABLE gcol_t1;
......@@ -547,6 +547,7 @@ CREATE TABLE gcol_t1 (
sidec DOUBLE AS (SQRT(sidea * sidea + sideb * sideb))
);
SELECT * FROM information_schema.columns WHERE table_name='gcol_t1';
SELECT table_schema,table_name,column_name,extra,is_generated,generation_expression
FROM information_schema.columns WHERE table_name='gcol_t1';
DROP TABLE gcol_t1;
......@@ -1809,3 +1809,50 @@ select i, row_number() over () from t1 group by 1+2;
select i, rank() over (order by i) rnk from t1 group by 1+2;
drop table t1;
--echo #
--echo # MDEV-11907: window function as the second operand of division
--echo #
create table t1 (pk int, c int);
insert into t1 values (1,1),(2,1),(3,1),(4,1),(5,2);
set @sql_mode_save= @@sql_mode;
set sql_mode='ERROR_FOR_DIVISION_BY_ZERO';
select pk, c, c/count(*) over
(partition by c order by pk
rows between 1 preceding and 2 following) as CNT
from t1;
show warnings;
set sql_mode=@sql_mode_save;
drop table t1;
--echo #
--echo # MDEV-12336: several functions over a window function
--echo #
create table t1 (name varchar(10), cnt int);
insert into t1 values ('Fred', 23), ('Fred', 35), ('Joe', 10);
select q.name, q.row_cnt,
round( 100 * ( q.row_cnt /
sum(q.row_cnt) over
(
order by q.name
rows between
unbounded preceding and
unbounded following
)
),2
) pct_of_total
from
(
select name, count(*) row_cnt, sum(cnt) sum_cnt
from t1
group by 1
) q;
drop table t1;
......@@ -1986,6 +1986,9 @@ void Item::split_sum_func2(THD *thd, Ref_ptr_array ref_pointer_array,
&ref_pointer_array[el], 0, name))))
return; // fatal_error is set
}
else if (type() == FUNC_ITEM &&
((Item_func *) this)->with_window_func)
return;
else
{
if (!(item_ref= (new (thd->mem_root)
......
......@@ -23278,6 +23278,9 @@ copy_funcs(Item **func_ptr, const THD *thd)
Item *func;
for (; (func = *func_ptr) ; func_ptr++)
{
if (func->type() == Item::FUNC_ITEM &&
((Item_func *) func)->with_window_func)
continue;
func->save_in_result_field(1);
/*
Need to check the THD error state because Item::val_xxx() don't
......
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