Commit a74e8d36 authored by Igor Babaev's avatar Igor Babaev

For some window functions an order list must be present.

parent 13f9535f
......@@ -470,6 +470,17 @@ dense_rank() over (partition by c order by pk
rows between 1 preceding and 1 following) as r
from t1;
ERROR HY000: Window frame is not allowed with 'dense_rank'
select
pk, c,
rank() over w1 as r
from t1
window w1 as (partition by c);
ERROR HY000: No order list in window specification for 'rank'
select
pk, c,
dense_rank() over (partition by c) as r
from t1;
ERROR HY000: No order list in window specification for 'dense_rank'
drop table t0,t1;
#
# MDEV-9634: Window function produces incorrect value
......
......@@ -311,6 +311,19 @@ select
rows between 1 preceding and 1 following) as r
from t1;
--error ER_NO_ORDER_LIST_IN_WINDOW_SPEC
select
pk, c,
rank() over w1 as r
from t1
window w1 as (partition by c);
--error ER_NO_ORDER_LIST_IN_WINDOW_SPEC
select
pk, c,
dense_rank() over (partition by c) as r
from t1;
drop table t0,t1;
--echo #
......
......@@ -59,6 +59,11 @@ Item_window_func::fix_fields(THD *thd, Item **ref)
return true;
}
if (window_spec->order_list->elements == 0 && is_order_list_mandatory())
{
my_error(ER_NO_ORDER_LIST_IN_WINDOW_SPEC, MYF(0), window_func->func_name());
return true;
}
/*
TODO: why the last parameter is 'ref' in this call? What if window_func
decides to substitute itself for something else and does *ref=.... ?
......
......@@ -448,6 +448,19 @@ class Item_window_func : public Item_result_field
default:
return false;
}
}
bool is_order_list_mandatory()
{
switch (window_func->sum_func()) {
case Item_sum::RANK_FUNC:
case Item_sum::DENSE_RANK_FUNC:
case Item_sum::PERCENT_RANK_FUNC:
case Item_sum::CUME_DIST_FUNC:
return true;
default:
return false;
}
}
/*
......
......@@ -7150,6 +7150,8 @@ ER_BAD_COMBINATION_OF_WINDOW_FRAME_BOUND_SPECS
eng "Unacceptable combination of window frame bound specifications"
ER_NOT_ALLOWED_WINDOW_FRAME
eng "Window frame is not allowed with '%s'"
ER_NO_ORDER_LIST_IN_WINDOW_SPEC
eng "No order list in window specification for '%s'"
ER_RANGE_FRAME_NEEDS_SIMPLE_ORDERBY
eng "RANGE-type frame requires ORDER BY clause with single sort key"
ER_WRONG_TYPE_FOR_ROWS_FRAME
......
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