mirror of
https://github.com/MariaDB/server.git
synced 2025-01-19 21:42:35 +01:00
1c6b982e02
Users expect window functions to produce a certain ordering of rows in the final result set. Although the standard does not require this, we already have the filesort result done for when we computed the window function. If there is no ORDER BY attached to the query, just keep it till the SELECT is completely evaluated and use that to print the result. Update test cases as many did not take care to guarantee a stable result.
36 lines
576 B
Text
36 lines
576 B
Text
create table t1 (
|
|
pk int primary key,
|
|
a int,
|
|
b int
|
|
);
|
|
|
|
|
|
insert into t1 values
|
|
( 1 , 0, 10),
|
|
( 2 , 0, 10),
|
|
( 3 , 1, 10),
|
|
( 4 , 1, 10),
|
|
( 8 , 2, 10),
|
|
( 5 , 2, 20),
|
|
( 6 , 2, 20),
|
|
( 7 , 2, 20),
|
|
( 9 , 4, 20),
|
|
(10 , 4, 20);
|
|
|
|
select a,
|
|
percent_rank() over (order by a),
|
|
cume_dist() over (order by a)
|
|
from t1;
|
|
|
|
select pk,
|
|
percent_rank() over (order by pk),
|
|
cume_dist() over (order by pk)
|
|
from t1 order by pk;
|
|
|
|
select a,
|
|
percent_rank() over (partition by a order by a),
|
|
cume_dist() over (partition by a order by a)
|
|
from t1;
|
|
|
|
drop table t1;
|
|
|