-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch '10.3' of github.com:MariaDB/server into 10.3
- Loading branch information
Showing
11 changed files
with
1,077 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
#cmakedefine SOURCE_REVISION "@SOURCE_REVISION@" | ||
#define SOURCE_REVISION "@SOURCE_REVISION@" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,326 @@ | ||
CREATE TABLE t1 (name CHAR(10), test double, score DECIMAL(19,4)); | ||
INSERT INTO t1 VALUES | ||
('Chun', 0, 3), ('Chun', 0, 7), | ||
('Kaolin', 0.5, 3), ('Kaolin', 0.6, 7), | ||
('Kaolin', 0.5, 4), | ||
('Tatiana', 0.8, 4), ('Tata', 0.8, 4); | ||
# | ||
# Test invalid syntax | ||
# | ||
# Order by clause has more than one element | ||
select percentile_disc(0.5) within group(order by score,test) over (partition by name) from t1; | ||
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'test) over (partition by name) from t1' at line 1 | ||
select percentile_cont(0.5) within group(order by score,test) over (partition by name) from t1; | ||
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'test) over (partition by name) from t1' at line 1 | ||
# Order by clause has no element | ||
select percentile_disc(0.5) within group() over (partition by name) from t1; | ||
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ') over (partition by name) from t1' at line 1 | ||
select percentile_cont(0.5) within group() over (partition by name) from t1; | ||
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ') over (partition by name) from t1' at line 1 | ||
# No parameters to the percentile functions | ||
select percentile_disc() within group() over (partition by name) from t1; | ||
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ') within group() over (partition by name) from t1' at line 1 | ||
select percentile_cont() within group() over (partition by name) from t1; | ||
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ') within group() over (partition by name) from t1' at line 1 | ||
# | ||
# Test simple syntax | ||
# | ||
select name, percentile_cont(0.5) within group(order by score) over (partition by name) as c from t1; | ||
name c | ||
Chun 5.0000000000 | ||
Chun 5.0000000000 | ||
Kaolin 4.0000000000 | ||
Kaolin 4.0000000000 | ||
Kaolin 4.0000000000 | ||
Tatiana 4.0000000000 | ||
Tata 4.0000000000 | ||
select name, percentile_disc(0.5) within group(order by score) over (partition by name) as c from t1; | ||
name c | ||
Chun 3.0000000000 | ||
Chun 3.0000000000 | ||
Kaolin 4.0000000000 | ||
Kaolin 4.0000000000 | ||
Kaolin 4.0000000000 | ||
Tatiana 4.0000000000 | ||
Tata 4.0000000000 | ||
# no partition clause | ||
select name, percentile_disc(0.5) within group(order by score) over () from t1; | ||
name percentile_disc(0.5) within group(order by score) over () | ||
Chun 4.0000000000 | ||
Chun 4.0000000000 | ||
Kaolin 4.0000000000 | ||
Kaolin 4.0000000000 | ||
Kaolin 4.0000000000 | ||
Tatiana 4.0000000000 | ||
Tata 4.0000000000 | ||
select name, percentile_cont(0.5) within group(order by score) over () from t1; | ||
name percentile_cont(0.5) within group(order by score) over () | ||
Chun 4.0000000000 | ||
Chun 4.0000000000 | ||
Kaolin 4.0000000000 | ||
Kaolin 4.0000000000 | ||
Kaolin 4.0000000000 | ||
Tatiana 4.0000000000 | ||
Tata 4.0000000000 | ||
# argument set to null | ||
select name, percentile_cont(null) within group(order by score) over (partition by name) from t1; | ||
ERROR HY000: percentile_cont function only accepts arguments that can be converted to numerical types | ||
select name, percentile_disc(null) within group(order by score) over (partition by name) from t1; | ||
ERROR HY000: percentile_disc function only accepts arguments that can be converted to numerical types | ||
#subqueries having percentile functions | ||
select * from ( select name , percentile_cont(0.5) within group ( order by score) over (partition by name ) from t1 ) as t; | ||
name percentile_cont(0.5) within group ( order by score) over (partition by name ) | ||
Chun 5.0000000000 | ||
Chun 5.0000000000 | ||
Kaolin 4.0000000000 | ||
Kaolin 4.0000000000 | ||
Kaolin 4.0000000000 | ||
Tatiana 4.0000000000 | ||
Tata 4.0000000000 | ||
select * from ( select name , percentile_disc(0.5) within group ( order by score) over (partition by name ) from t1 ) as t; | ||
name percentile_disc(0.5) within group ( order by score) over (partition by name ) | ||
Chun 3.0000000000 | ||
Chun 3.0000000000 | ||
Kaolin 4.0000000000 | ||
Kaolin 4.0000000000 | ||
Kaolin 4.0000000000 | ||
Tatiana 4.0000000000 | ||
Tata 4.0000000000 | ||
select name from t1 a where (select percentile_disc(0.5) within group (order by score) over (partition by name) from t1 b limit 1) >= 0.5; | ||
name | ||
Chun | ||
Chun | ||
Kaolin | ||
Kaolin | ||
Kaolin | ||
Tatiana | ||
Tata | ||
#disallowed fields in order by | ||
select score, percentile_cont(0.5) within group(order by name) over (partition by score) from t1; | ||
ERROR HY000: Numeric datatype is required for percentile_cont function | ||
select score, percentile_disc(0.5) within group(order by name) over (partition by score) from t1; | ||
ERROR HY000: Numeric datatype is required for percentile_disc function | ||
#parameter value should be in the range of [0,1] | ||
select percentile_disc(1.5) within group(order by score) over (partition by name) from t1; | ||
ERROR HY000: Argument to the percentile_disc function does not belong to the range [0,1] | ||
select percentile_cont(1.5) within group(order by score) over (partition by name) from t1; | ||
ERROR HY000: Argument to the percentile_cont function does not belong to the range [0,1] | ||
#Argument should remain constant for the entire partition | ||
select name,percentile_cont(test) within group(order by score) over (partition by name) from t1; | ||
ERROR HY000: Argument to the percentile_cont function is not a constant for a partition | ||
select name, percentile_disc(test) within group(order by score) over (partition by name) from t1; | ||
ERROR HY000: Argument to the percentile_disc function is not a constant for a partition | ||
#only numerical types are allowed as argument to percentile functions | ||
select name, percentile_cont(name) within group(order by score) over (partition by name) from t1; | ||
ERROR HY000: percentile_cont function only accepts arguments that can be converted to numerical types | ||
select name, percentile_disc(name) within group(order by score) over (partition by name) from t1; | ||
ERROR HY000: percentile_disc function only accepts arguments that can be converted to numerical types | ||
#complete query with partition column | ||
select name,cume_dist() over (partition by name order by score), percentile_disc(0.5) within group(order by score) over (partition by name) as c from t1; | ||
name cume_dist() over (partition by name order by score) c | ||
Chun 0.5000000000 3.0000000000 | ||
Chun 1.0000000000 3.0000000000 | ||
Kaolin 0.3333333333 4.0000000000 | ||
Kaolin 1.0000000000 4.0000000000 | ||
Kaolin 0.6666666667 4.0000000000 | ||
Tatiana 1.0000000000 4.0000000000 | ||
Tata 1.0000000000 4.0000000000 | ||
select name, percentile_cont(0.5) within group(order by score) over (partition by name) as c from t1; | ||
name c | ||
Chun 5.0000000000 | ||
Chun 5.0000000000 | ||
Kaolin 4.0000000000 | ||
Kaolin 4.0000000000 | ||
Kaolin 4.0000000000 | ||
Tatiana 4.0000000000 | ||
Tata 4.0000000000 | ||
select name,cume_dist() over (partition by name order by score) as b, percentile_disc(0.1) within group(order by score) over (partition by name) as c from t1; | ||
name b c | ||
Chun 0.5000000000 3.0000000000 | ||
Chun 1.0000000000 3.0000000000 | ||
Kaolin 0.3333333333 3.0000000000 | ||
Kaolin 1.0000000000 3.0000000000 | ||
Kaolin 0.6666666667 3.0000000000 | ||
Tatiana 1.0000000000 4.0000000000 | ||
Tata 1.0000000000 4.0000000000 | ||
select name,cume_dist() over (partition by name order by score) as b, percentile_disc(0.2) within group(order by score) over (partition by name) as c from t1; | ||
name b c | ||
Chun 0.5000000000 3.0000000000 | ||
Chun 1.0000000000 3.0000000000 | ||
Kaolin 0.3333333333 3.0000000000 | ||
Kaolin 1.0000000000 3.0000000000 | ||
Kaolin 0.6666666667 3.0000000000 | ||
Tatiana 1.0000000000 4.0000000000 | ||
Tata 1.0000000000 4.0000000000 | ||
select name,cume_dist() over (partition by name order by score) as b, percentile_disc(0.3) within group(order by score) over (partition by name) as c from t1; | ||
name b c | ||
Chun 0.5000000000 3.0000000000 | ||
Chun 1.0000000000 3.0000000000 | ||
Kaolin 0.3333333333 3.0000000000 | ||
Kaolin 1.0000000000 3.0000000000 | ||
Kaolin 0.6666666667 3.0000000000 | ||
Tatiana 1.0000000000 4.0000000000 | ||
Tata 1.0000000000 4.0000000000 | ||
select name,cume_dist() over (partition by name order by score) as b, percentile_disc(0.4) within group(order by score) over (partition by name) as c from t1; | ||
name b c | ||
Chun 0.5000000000 3.0000000000 | ||
Chun 1.0000000000 3.0000000000 | ||
Kaolin 0.3333333333 4.0000000000 | ||
Kaolin 1.0000000000 4.0000000000 | ||
Kaolin 0.6666666667 4.0000000000 | ||
Tatiana 1.0000000000 4.0000000000 | ||
Tata 1.0000000000 4.0000000000 | ||
select name,cume_dist() over (partition by name order by score) as b, percentile_disc(0.5) within group(order by score) over (partition by name) as c from t1; | ||
name b c | ||
Chun 0.5000000000 3.0000000000 | ||
Chun 1.0000000000 3.0000000000 | ||
Kaolin 0.3333333333 4.0000000000 | ||
Kaolin 1.0000000000 4.0000000000 | ||
Kaolin 0.6666666667 4.0000000000 | ||
Tatiana 1.0000000000 4.0000000000 | ||
Tata 1.0000000000 4.0000000000 | ||
select name,cume_dist() over (partition by name order by score) as b, percentile_disc(0.6) within group(order by score) over (partition by name) as c from t1; | ||
name b c | ||
Chun 0.5000000000 7.0000000000 | ||
Chun 1.0000000000 7.0000000000 | ||
Kaolin 0.3333333333 4.0000000000 | ||
Kaolin 1.0000000000 4.0000000000 | ||
Kaolin 0.6666666667 4.0000000000 | ||
Tatiana 1.0000000000 4.0000000000 | ||
Tata 1.0000000000 4.0000000000 | ||
select name,cume_dist() over (partition by name order by score) as b, percentile_disc(0.7) within group(order by score) over (partition by name) as c from t1; | ||
name b c | ||
Chun 0.5000000000 7.0000000000 | ||
Chun 1.0000000000 7.0000000000 | ||
Kaolin 0.3333333333 7.0000000000 | ||
Kaolin 1.0000000000 7.0000000000 | ||
Kaolin 0.6666666667 7.0000000000 | ||
Tatiana 1.0000000000 4.0000000000 | ||
Tata 1.0000000000 4.0000000000 | ||
select name,cume_dist() over (partition by name order by score) as b, percentile_disc(0.8) within group(order by score) over (partition by name) as c from t1; | ||
name b c | ||
Chun 0.5000000000 7.0000000000 | ||
Chun 1.0000000000 7.0000000000 | ||
Kaolin 0.3333333333 7.0000000000 | ||
Kaolin 1.0000000000 7.0000000000 | ||
Kaolin 0.6666666667 7.0000000000 | ||
Tatiana 1.0000000000 4.0000000000 | ||
Tata 1.0000000000 4.0000000000 | ||
select name,cume_dist() over (partition by name order by score) as b, percentile_disc(0.9) within group(order by score) over (partition by name) as c from t1; | ||
name b c | ||
Chun 0.5000000000 7.0000000000 | ||
Chun 1.0000000000 7.0000000000 | ||
Kaolin 0.3333333333 7.0000000000 | ||
Kaolin 1.0000000000 7.0000000000 | ||
Kaolin 0.6666666667 7.0000000000 | ||
Tatiana 1.0000000000 4.0000000000 | ||
Tata 1.0000000000 4.0000000000 | ||
select name,cume_dist() over (partition by name order by score) as b, percentile_disc(1) within group(order by score) over (partition by name) as c from t1; | ||
name b c | ||
Chun 0.5000000000 7.0000000000 | ||
Chun 1.0000000000 7.0000000000 | ||
Kaolin 0.3333333333 7.0000000000 | ||
Kaolin 1.0000000000 7.0000000000 | ||
Kaolin 0.6666666667 7.0000000000 | ||
Tatiana 1.0000000000 4.0000000000 | ||
Tata 1.0000000000 4.0000000000 | ||
select median(score) over (partition by name), percentile_cont(0) within group(order by score) over (partition by name) as c from t1; | ||
median(score) over (partition by name) c | ||
5.0000000000 3.0000000000 | ||
5.0000000000 3.0000000000 | ||
4.0000000000 3.0000000000 | ||
4.0000000000 3.0000000000 | ||
4.0000000000 3.0000000000 | ||
4.0000000000 4.0000000000 | ||
4.0000000000 4.0000000000 | ||
select median(score) over (partition by name), percentile_cont(0.1) within group(order by score) over (partition by name) as c from t1; | ||
median(score) over (partition by name) c | ||
5.0000000000 3.4000000000 | ||
5.0000000000 3.4000000000 | ||
4.0000000000 3.2000000000 | ||
4.0000000000 3.2000000000 | ||
4.0000000000 3.2000000000 | ||
4.0000000000 4.0000000000 | ||
4.0000000000 4.0000000000 | ||
select median(score) over (partition by name), percentile_cont(0.2) within group(order by score) over (partition by name) as c from t1; | ||
median(score) over (partition by name) c | ||
5.0000000000 3.8000000000 | ||
5.0000000000 3.8000000000 | ||
4.0000000000 3.4000000000 | ||
4.0000000000 3.4000000000 | ||
4.0000000000 3.4000000000 | ||
4.0000000000 4.0000000000 | ||
4.0000000000 4.0000000000 | ||
select median(score) over (partition by name), percentile_cont(0.3) within group(order by score) over (partition by name) as c from t1; | ||
median(score) over (partition by name) c | ||
5.0000000000 4.2000000000 | ||
5.0000000000 4.2000000000 | ||
4.0000000000 3.6000000000 | ||
4.0000000000 3.6000000000 | ||
4.0000000000 3.6000000000 | ||
4.0000000000 4.0000000000 | ||
4.0000000000 4.0000000000 | ||
select median(score) over (partition by name), percentile_cont(0.4) within group(order by score) over (partition by name) as c from t1; | ||
median(score) over (partition by name) c | ||
5.0000000000 4.6000000000 | ||
5.0000000000 4.6000000000 | ||
4.0000000000 3.8000000000 | ||
4.0000000000 3.8000000000 | ||
4.0000000000 3.8000000000 | ||
4.0000000000 4.0000000000 | ||
4.0000000000 4.0000000000 | ||
select median(score) over (partition by name), percentile_cont(0.5) within group(order by score) over (partition by name) as c from t1; | ||
median(score) over (partition by name) c | ||
5.0000000000 5.0000000000 | ||
5.0000000000 5.0000000000 | ||
4.0000000000 4.0000000000 | ||
4.0000000000 4.0000000000 | ||
4.0000000000 4.0000000000 | ||
4.0000000000 4.0000000000 | ||
4.0000000000 4.0000000000 | ||
select median(score) over (partition by name), percentile_cont(0.6) within group(order by score) over (partition by name) as c from t1; | ||
median(score) over (partition by name) c | ||
5.0000000000 5.4000000000 | ||
5.0000000000 5.4000000000 | ||
4.0000000000 4.6000000000 | ||
4.0000000000 4.6000000000 | ||
4.0000000000 4.6000000000 | ||
4.0000000000 4.0000000000 | ||
4.0000000000 4.0000000000 | ||
select median(score) over (partition by name), percentile_cont(0.7) within group(order by score) over (partition by name) as c from t1; | ||
median(score) over (partition by name) c | ||
5.0000000000 5.8000000000 | ||
5.0000000000 5.8000000000 | ||
4.0000000000 5.2000000000 | ||
4.0000000000 5.2000000000 | ||
4.0000000000 5.2000000000 | ||
4.0000000000 4.0000000000 | ||
4.0000000000 4.0000000000 | ||
select median(score) over (partition by name), percentile_cont(0.8) within group(order by score) over (partition by name) as c from t1; | ||
median(score) over (partition by name) c | ||
5.0000000000 6.2000000000 | ||
5.0000000000 6.2000000000 | ||
4.0000000000 5.8000000000 | ||
4.0000000000 5.8000000000 | ||
4.0000000000 5.8000000000 | ||
4.0000000000 4.0000000000 | ||
4.0000000000 4.0000000000 | ||
select median(score) over (partition by name), percentile_cont(0.9) within group(order by score) over (partition by name) as c from t1; | ||
median(score) over (partition by name) c | ||
5.0000000000 6.6000000000 | ||
5.0000000000 6.6000000000 | ||
4.0000000000 6.4000000000 | ||
4.0000000000 6.4000000000 | ||
4.0000000000 6.4000000000 | ||
4.0000000000 4.0000000000 | ||
4.0000000000 4.0000000000 | ||
select median(score) over (partition by name), percentile_cont(1) within group(order by score) over (partition by name) as c from t1; | ||
median(score) over (partition by name) c | ||
5.0000000000 7.0000000000 | ||
5.0000000000 7.0000000000 | ||
4.0000000000 7.0000000000 | ||
4.0000000000 7.0000000000 | ||
4.0000000000 7.0000000000 | ||
4.0000000000 4.0000000000 | ||
4.0000000000 4.0000000000 | ||
drop table t1; |
Oops, something went wrong.