Details
-
Task
-
Status: Closed (View Workflow)
-
Major
-
Resolution: Fixed
-
None
-
10.3.1-2, 10.3.3-1
Description
The percentile_cont and percentile_disc window functions are available in columnstore and many other databases. These allow calculation of percentiles. Percentile_cont will average 2 rows if one is not identified while Percentile_disc picks the first row in the window. Finally a median function should exist which is equivalent to percentile_cont(0.5).
These have slightly different syntax than other window function to specify the column:
percentile_cont(0.5) within group (order by amount) over (partition by owner) pct_cont,
percentile_disc(0.5) within group (order by amount) over (partition by owner) pct_disc
Some investigation
percentile_cont and percentile_disc are not specifically window functions. They originally are "ordered-set aggregate functions" (#1) which one can also use as window functions (#2):
Ordered-set aggreates
The syntax for case #1:
percentile_cont(fraction) WITHIN GROUP (ORDER BY sort_expression)
|
Note the lack of OVER clause.
Ordered-set aggregate functions are supported by:
- https://www.postgresql.org/docs/current/static/functions-aggregate.html
- http://docs.aws.amazon.com/redshift/latest/dg/c_Aggregate_Functions.html
Neither MariaDB nor MySQL support any "ordered-set aggregate functions".
Ordered-set aggregates as window functions
Syntax for case #2 (ordered-set aggregate, used as window function)
- http://docs.aws.amazon.com/redshift/latest/dg/r_WF_PERCENTILE_DISC.html
- https://docs.oracle.com/cd/B12037_01/server.101/b10759/functions100.htm#i1000909
PERCENTILE_DISC ( percentile )
|
WITHIN GROUP (ORDER BY expr)
|
OVER ( [ PARTITION BY expr_list ] )
|
(BTW: note that PostgreSQL doesn't support ordered-set-aggregates-as-window functions: https://www.postgresql.org/docs/current/static/functions-window.html ,
any built-in or user-defined normal aggregate function (but not ordered-set or hypothetical-set aggregates) can be used as a window function)
Attachments
Issue Links
- blocks
-
MCOL-624 MariaDB 10.2 WF create MEDIAN, PERCENTILE_CONT and PERCENTILE_DISC Window functions
-
- Closed
-
- is duplicated by
-
MDEV-4835 Add Median Function
-
- Closed
-
- is part of
-
MDEV-12987 complete window function support for columnstore parity
-
- Open
-
- relates to
-
MDEV-13854 Supporting datetime fields in the order by clause of Percentile functions
-
- Open
-
-
MDEV-27395 Named windows do not work with MEDIAN() window function.
-
- Open
-
Activity
Link | This issue is part of MDEV-12987 [ MDEV-12987 ] |
Assignee | Varun Gupta [ varun ] |
Status | Open [ 1 ] | In Progress [ 3 ] |
Description |
The percentile_cont and percentile_disc window functions are available in columnstore and many other databases. These allow calculation of percentiles. Percentile_cont will average 2 rows if one is not identified while Percentile_disc picks the first row in the window. Finally a median function should exist which is equivalent to percentile_cont(0.5).
These have slightly different syntax than other window function to specify the column: percentile_cont(0.5) within group (order by amount) over (partition by owner) pct_cont, percentile_disc(0.5) within group (order by amount) over (partition by owner) pct_disc |
The percentile_cont and percentile_disc window functions are available in columnstore and many other databases. These allow calculation of percentiles. Percentile_cont will average 2 rows if one is not identified while Percentile_disc picks the first row in the window. Finally a median function should exist which is equivalent to percentile_cont(0.5).
These have slightly different syntax than other window function to specify the column: percentile_cont(0.5) within group (order by amount) over (partition by owner) pct_cont, percentile_disc(0.5) within group (order by amount) over (partition by owner) pct_disc h2. Some investigation percentile_cont and percentile_disc are not specifically window functions. They originally are "ordered-set aggregate functions" (#1) which one can also use as window functions (#2): h3. Ordered-set aggreates The syntax for case #1: {noformat} percentile_cont(fraction) WITHIN GROUP (ORDER BY sort_expression) {noformat} Note the lack of OVER clause. Ordered-set aggregate functions are supported by: * https://www.postgresql.org/docs/current/static/functions-aggregate.html * http://docs.aws.amazon.com/redshift/latest/dg/c_Aggregate_Functions.html Neither MariaDB nor MySQL support any "ordered-set aggregate functions". h3. Ordered-set aggregates as window functions Syntax for case #2 (ordered-set aggregate, used as window function) * http://docs.aws.amazon.com/redshift/latest/dg/r_WF_PERCENTILE_DISC.html * https://docs.oracle.com/cd/B12037_01/server.101/b10759/functions100.htm#i1000909 {noformat} PERCENTILE_DISC ( percentile ) WITHIN GROUP (ORDER BY expr) OVER ( [ PARTITION BY expr_list ] ) {noformat} (BTW: note that PostgreSQL doesn't support ordered-set-aggregates-as-window functions: https://www.postgresql.org/docs/current/static/functions-window.html , {quote}any built-in or user-defined normal aggregate function (but not ordered-set or hypothetical-set aggregates) can be used as a window function) {quote} |
Fix Version/s | 10.3 [ 22126 ] |
Epic Link | PT-60 [ 62159 ] |
Sprint | 10.3.1-2 [ 174 ] |
Rank | Ranked higher |
Assignee | Varun Gupta [ varun ] | Vicentiu Ciorbaru [ cvicentiu ] |
Status | In Progress [ 3 ] | In Review [ 10002 ] |
Status | In Review [ 10002 ] | Stalled [ 10000 ] |
Assignee | Vicentiu Ciorbaru [ cvicentiu ] | Varun Gupta [ varun ] |
Status | Stalled [ 10000 ] | In Progress [ 3 ] |
Link | This issue relates to MDEV-13854 [ MDEV-13854 ] |
Sprint | 10.3.1-2 [ 174 ] | 10.3.1-2, 10.3.3-1 [ 174, 200 ] |
Assignee | Varun Gupta [ varun ] | Vicentiu Ciorbaru [ cvicentiu ] |
Status | In Progress [ 3 ] | In Review [ 10002 ] |
Assignee | Vicentiu Ciorbaru [ cvicentiu ] | Varun Gupta [ varun ] |
Status | In Review [ 10002 ] | Stalled [ 10000 ] |
Fix Version/s | 10.3.3 [ 22644 ] | |
Fix Version/s | 10.3 [ 22126 ] | |
Resolution | Fixed [ 1 ] | |
Status | Stalled [ 10000 ] | Closed [ 6 ] |
Workflow | MariaDB v3 [ 81072 ] | MariaDB v4 [ 133274 ] |
Link | This issue relates to MDEV-27395 [ MDEV-27395 ] |
[dthompson, a question from me and varun: Does ColumnStore need just "Ordered-set aggregates as window functions", or it needs both "Ordered-set aggregates as window functions" and "Ordered-set aggregates". IIRC it supported both?