Browse Source

For some window functions an order list must be present.

pull/216/head
Igor Babaev 10 years ago
parent
commit
a74e8d36dd
  1. 11
      mysql-test/r/win.result
  2. 13
      mysql-test/t/win.test
  3. 5
      sql/item_windowfunc.cc
  4. 13
      sql/item_windowfunc.h
  5. 2
      sql/share/errmsg-utf8.txt

11
mysql-test/r/win.result

@ -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

13
mysql-test/t/win.test

@ -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 #

5
sql/item_windowfunc.cc

@ -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=.... ?

13
sql/item_windowfunc.h

@ -448,6 +448,19 @@ public:
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;
}
}
/*

2
sql/share/errmsg-utf8.txt

@ -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

Loading…
Cancel
Save