Uploaded image for project: 'MariaDB Server'
  1. MariaDB Server
  2. MDEV-12985

support percentile and median window functions

Details

    • 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:

      Ordered-set aggregates as window functions

      Syntax for case #2 (ordered-set aggregate, used as window function)

      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

          Activity

            dthompson David Thompson (Inactive) created issue -
            dthompson David Thompson (Inactive) made changes -
            Field Original Value New Value
            dthompson David Thompson (Inactive) made changes -
            varun Varun Gupta (Inactive) made changes -
            Assignee Varun Gupta [ varun ]
            varun Varun Gupta (Inactive) made changes -
            Status Open [ 1 ] In Progress [ 3 ]
            psergei Sergei Petrunia made changes -
            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}
            varun Varun Gupta (Inactive) made changes -
            Fix Version/s 10.3 [ 22126 ]
            ralf.gebhardt Ralf Gebhardt made changes -
            Epic Link PT-60 [ 62159 ]
            ratzpo Rasmus Johansson (Inactive) made changes -
            ratzpo Rasmus Johansson (Inactive) made changes -
            Sprint 10.3.1-2 [ 174 ]
            ratzpo Rasmus Johansson (Inactive) made changes -
            Rank Ranked higher
            varun Varun Gupta (Inactive) made changes -
            Assignee Varun Gupta [ varun ] Vicentiu Ciorbaru [ cvicentiu ]
            Status In Progress [ 3 ] In Review [ 10002 ]
            cvicentiu Vicențiu Ciorbaru made changes -
            Status In Review [ 10002 ] Stalled [ 10000 ]
            cvicentiu Vicențiu Ciorbaru made changes -
            Assignee Vicentiu Ciorbaru [ cvicentiu ] Varun Gupta [ varun ]
            varun Varun Gupta (Inactive) made changes -
            Status Stalled [ 10000 ] In Progress [ 3 ]
            varun Varun Gupta (Inactive) made changes -
            serg Sergei Golubchik made changes -
            Sprint 10.3.1-2 [ 174 ] 10.3.1-2, 10.3.3-1 [ 174, 200 ]
            varun Varun Gupta (Inactive) made changes -
            Assignee Varun Gupta [ varun ] Vicentiu Ciorbaru [ cvicentiu ]
            Status In Progress [ 3 ] In Review [ 10002 ]
            cvicentiu Vicențiu Ciorbaru made changes -
            Assignee Vicentiu Ciorbaru [ cvicentiu ] Varun Gupta [ varun ]
            Status In Review [ 10002 ] Stalled [ 10000 ]
            varun Varun Gupta (Inactive) made changes -
            Fix Version/s 10.3.3 [ 22644 ]
            Fix Version/s 10.3 [ 22126 ]
            Resolution Fixed [ 1 ]
            Status Stalled [ 10000 ] Closed [ 6 ]
            serg Sergei Golubchik made changes -
            Workflow MariaDB v3 [ 81072 ] MariaDB v4 [ 133274 ]
            alice Alice Sherepa made changes -

            People

              varun Varun Gupta (Inactive)
              dthompson David Thompson (Inactive)
              Votes:
              1 Vote for this issue
              Watchers:
              9 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Git Integration

                  Error rendering 'com.xiplink.jira.git.jira_git_plugin:git-issue-webpanel'. Please contact your Jira administrators.