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

window functions as in the SQL standard

Details

    Description

      Spec draft

      Place in the optimizer

      Window functions are evaluated on the result set after the WHERE, GROUP BY and HAVING have been applied.

      • If we are operating after a temptable-based grouping operation, we can read its output (and apply HAVING on the fly)
      • if we are operating after a Join operation, or non-temptable based grouping, we will need to store the output of previous operation in a temptable and then work from there.

      Basic idea about operation

      Let's start with one window function:

      func_name(arg) OVER (PARTITION BY part_expr  ORDER BY order_expr  $window_spec)

      Window function is evaluated for each row of the result set. It is a function of row's partition, we need to look at the rows of the resultset that are ordered according to order_expr. $window_spec specifies at which rows we need to look. Sometimes it's certain preceding rows, sometimes it's certain following rows (and sometimes it's both?)

      Execution can be done as follows:

      • sort resultset rows by (part_expr, order_expr).
      • scan each partition (either in reverse or forward order) and compute the value of window function on the fly.

      Unresolved questions:

      • How to handle the context. If a window function depends on preceding and following rows, how do we keep track of those?
      • Whether we should use files or temp.tables for storing the sorted resultset (we will always have to store it, because filesort doesn't support pull-based reading of its resultset)

      Multiple window functions

      A query may use multiple window functions which use different PARTITION BY / ORDER BY expressions:

      SELECT 
         window_func1 OVER (PARTITION BY part_expr1 ORDER BY order_expr1)
         window_func2 OVER (PARTITION BY part_expr2 ORDER BY order_expr2)
      FROM ... WHERE ... etc

      The query should be evaluated as follows:

      • sort the result according to part_expr1/order_expr1, compute values of window_func1
      • sort the result according to part_expr2/order_expr2, compute values of window_func2

      Links

      Attachments

        Issue Links

          Activity

            serg Sergei Golubchik created issue -
            serg Sergei Golubchik made changes -
            Field Original Value New Value
            Labels optimizer
            dbart Daniel Bartholomew made changes -
            Assignee Sergei Petrunia [ psergey ]
            psergei Sergei Petrunia made changes -
            Fix Version/s 10.1.1 [ 16100 ]
            Fix Version/s 10.1.0 [ 12200 ]
            serg Sergei Golubchik made changes -
            Workflow defaullt [ 38931 ] MariaDB v2 [ 42505 ]
            psergei Sergei Petrunia made changes -
            Fix Version/s 10.2.0 [ 14601 ]
            Fix Version/s 10.1 [ 16100 ]
            psergei Sergei Petrunia made changes -
            Assignee Sergei Petrunia [ psergey ] Igor Babaev [ igor ]
            psergei Sergei Petrunia made changes -
            Assignee Igor Babaev [ igor ] Sergei Petrunia [ psergey ]
            psergei Sergei Petrunia made changes -
            Assignee Sergei Petrunia [ psergey ] Igor Babaev [ igor ]
            psergei Sergei Petrunia made changes -
            Description windowing functions as in the SQL standard windowing functions as in the SQL standard

            h1. Spec draft

            h2. Place in the optimizer
            Window functions are evaluated on the result set after the WHERE, GROUP BY and HAVING have been applied.
            * If we are operating after a temptable-based grouping operation, we can read its output (and apply HAVING on the fly)
            * if we are operating after a Join operation, or non-temptable based grouping, we will need to store the output of previous operation in a temptable and then work from there.

            h3. Basic idea about operation

            Let's start with one window function.

            SELECT
            psergei Sergei Petrunia made changes -
            Description windowing functions as in the SQL standard

            h1. Spec draft

            h2. Place in the optimizer
            Window functions are evaluated on the result set after the WHERE, GROUP BY and HAVING have been applied.
            * If we are operating after a temptable-based grouping operation, we can read its output (and apply HAVING on the fly)
            * if we are operating after a Join operation, or non-temptable based grouping, we will need to store the output of previous operation in a temptable and then work from there.

            h3. Basic idea about operation

            Let's start with one window function.

            SELECT
            windowing functions as in the SQL standard

            h1. Spec draft

            h2. Place in the optimizer
            Window functions are evaluated on the result set after the WHERE, GROUP BY and HAVING have been applied.
            * If we are operating after a temptable-based grouping operation, we can read its output (and apply HAVING on the fly)
            * if we are operating after a Join operation, or non-temptable based grouping, we will need to store the output of previous operation in a temptable and then work from there.

            h3. Basic idea about operation

            Let's start with one window function.



            SELECT
            psergei Sergei Petrunia made changes -
            Description windowing functions as in the SQL standard

            h1. Spec draft

            h2. Place in the optimizer
            Window functions are evaluated on the result set after the WHERE, GROUP BY and HAVING have been applied.
            * If we are operating after a temptable-based grouping operation, we can read its output (and apply HAVING on the fly)
            * if we are operating after a Join operation, or non-temptable based grouping, we will need to store the output of previous operation in a temptable and then work from there.

            h3. Basic idea about operation

            Let's start with one window function.



            SELECT
            windowing functions as in the SQL standard

            h1. Spec draft

            h2. Place in the optimizer
            Window functions are evaluated on the result set after the WHERE, GROUP BY and HAVING have been applied.
            * If we are operating after a temptable-based grouping operation, we can read its output (and apply HAVING on the fly)
            * if we are operating after a Join operation, or non-temptable based grouping, we will need to store the output of previous operation in a temptable and then work from there.

            h3. Basic idea about operation

            Let's start with one window function:

            {noformat}
            func_name(arg) OVER (PARTITION BY part_expr ORDER BY order_expr $window_spec)
            {noformat}

            Window function is evaluated for each row of the result set. It is a function of row's partition, we need to look at the rows of the resultset that are ordered according to order_expr. $window_spec specifies at which rows we need to look. Sometimes it's certain preceding rows, sometimes it's certain following rows (and sometimes it's both?)

            Execution can be done as follows:
            * sort resultset rows by (part_expr, order_expr).
            * scan each partition (either in reverse or forward order) and compute the value of window function on the fly.

            Unresolved questions:
            - How to handle the context. If a window function depends on preceding and following rows, how do we keep in mind those?
            psergei Sergei Petrunia made changes -
            Description windowing functions as in the SQL standard

            h1. Spec draft

            h2. Place in the optimizer
            Window functions are evaluated on the result set after the WHERE, GROUP BY and HAVING have been applied.
            * If we are operating after a temptable-based grouping operation, we can read its output (and apply HAVING on the fly)
            * if we are operating after a Join operation, or non-temptable based grouping, we will need to store the output of previous operation in a temptable and then work from there.

            h3. Basic idea about operation

            Let's start with one window function:

            {noformat}
            func_name(arg) OVER (PARTITION BY part_expr ORDER BY order_expr $window_spec)
            {noformat}

            Window function is evaluated for each row of the result set. It is a function of row's partition, we need to look at the rows of the resultset that are ordered according to order_expr. $window_spec specifies at which rows we need to look. Sometimes it's certain preceding rows, sometimes it's certain following rows (and sometimes it's both?)

            Execution can be done as follows:
            * sort resultset rows by (part_expr, order_expr).
            * scan each partition (either in reverse or forward order) and compute the value of window function on the fly.

            Unresolved questions:
            - How to handle the context. If a window function depends on preceding and following rows, how do we keep in mind those?
            windowing functions as in the SQL standard

            h1. Spec draft

            h2. Place in the optimizer
            Window functions are evaluated on the result set after the WHERE, GROUP BY and HAVING have been applied.
            * If we are operating after a temptable-based grouping operation, we can read its output (and apply HAVING on the fly)
            * if we are operating after a Join operation, or non-temptable based grouping, we will need to store the output of previous operation in a temptable and then work from there.

            h2. Basic idea about operation

            Let's start with one window function:

            {noformat}
            func_name(arg) OVER (PARTITION BY part_expr ORDER BY order_expr $window_spec)
            {noformat}

            Window function is evaluated for each row of the result set. It is a function of row's partition, we need to look at the rows of the resultset that are ordered according to order_expr. $window_spec specifies at which rows we need to look. Sometimes it's certain preceding rows, sometimes it's certain following rows (and sometimes it's both?)

            Execution can be done as follows:
            * sort resultset rows by (part_expr, order_expr).
            * scan each partition (either in reverse or forward order) and compute the value of window function on the fly.

            Unresolved questions:
            - How to handle the context. If a window function depends on preceding and following rows, how do we keep in mind those?
            psergei Sergei Petrunia made changes -
            Description windowing functions as in the SQL standard

            h1. Spec draft

            h2. Place in the optimizer
            Window functions are evaluated on the result set after the WHERE, GROUP BY and HAVING have been applied.
            * If we are operating after a temptable-based grouping operation, we can read its output (and apply HAVING on the fly)
            * if we are operating after a Join operation, or non-temptable based grouping, we will need to store the output of previous operation in a temptable and then work from there.

            h2. Basic idea about operation

            Let's start with one window function:

            {noformat}
            func_name(arg) OVER (PARTITION BY part_expr ORDER BY order_expr $window_spec)
            {noformat}

            Window function is evaluated for each row of the result set. It is a function of row's partition, we need to look at the rows of the resultset that are ordered according to order_expr. $window_spec specifies at which rows we need to look. Sometimes it's certain preceding rows, sometimes it's certain following rows (and sometimes it's both?)

            Execution can be done as follows:
            * sort resultset rows by (part_expr, order_expr).
            * scan each partition (either in reverse or forward order) and compute the value of window function on the fly.

            Unresolved questions:
            - How to handle the context. If a window function depends on preceding and following rows, how do we keep in mind those?
            windowing functions as in the SQL standard

            h1. Spec draft

            h2. Place in the optimizer
            Window functions are evaluated on the result set after the WHERE, GROUP BY and HAVING have been applied.
            * If we are operating after a temptable-based grouping operation, we can read its output (and apply HAVING on the fly)
            * if we are operating after a Join operation, or non-temptable based grouping, we will need to store the output of previous operation in a temptable and then work from there.

            h2. Basic idea about operation

            Let's start with one window function:

            {noformat}
            func_name(arg) OVER (PARTITION BY part_expr ORDER BY order_expr $window_spec)
            {noformat}

            Window function is evaluated for each row of the result set. It is a function of row's partition, we need to look at the rows of the resultset that are ordered according to order_expr. $window_spec specifies at which rows we need to look. Sometimes it's certain preceding rows, sometimes it's certain following rows (and sometimes it's both?)

            Execution can be done as follows:
            * sort resultset rows by (part_expr, order_expr).
            * scan each partition (either in reverse or forward order) and compute the value of window function on the fly.

            Unresolved questions:
            - How to handle the context. If a window function depends on preceding and following rows, how do we keep in mind those?

            h2. Multiple window functions
            A query may use multiple window functions which use different PARTITION BY / ORDER BY expressions:
            {noformat}
            SELECT
               window_func1 OVER (PARTITION BY part_expr1 ORDER BY order_expr1)
               window_func2 OVER (PARTITION BY part_expr2 ORDER BY order_expr2)
            FROM ... WHERE ... etc
            {noformat}

            The query should be evaluated as follows:
            * sort the result according to part_expr1/order_expr1, compute values of window_func1
            * sort the result according to part_expr2/order_expr2, compute values of window_func2
            psergei Sergei Petrunia made changes -
            Description windowing functions as in the SQL standard

            h1. Spec draft

            h2. Place in the optimizer
            Window functions are evaluated on the result set after the WHERE, GROUP BY and HAVING have been applied.
            * If we are operating after a temptable-based grouping operation, we can read its output (and apply HAVING on the fly)
            * if we are operating after a Join operation, or non-temptable based grouping, we will need to store the output of previous operation in a temptable and then work from there.

            h2. Basic idea about operation

            Let's start with one window function:

            {noformat}
            func_name(arg) OVER (PARTITION BY part_expr ORDER BY order_expr $window_spec)
            {noformat}

            Window function is evaluated for each row of the result set. It is a function of row's partition, we need to look at the rows of the resultset that are ordered according to order_expr. $window_spec specifies at which rows we need to look. Sometimes it's certain preceding rows, sometimes it's certain following rows (and sometimes it's both?)

            Execution can be done as follows:
            * sort resultset rows by (part_expr, order_expr).
            * scan each partition (either in reverse or forward order) and compute the value of window function on the fly.

            Unresolved questions:
            - How to handle the context. If a window function depends on preceding and following rows, how do we keep in mind those?

            h2. Multiple window functions
            A query may use multiple window functions which use different PARTITION BY / ORDER BY expressions:
            {noformat}
            SELECT
               window_func1 OVER (PARTITION BY part_expr1 ORDER BY order_expr1)
               window_func2 OVER (PARTITION BY part_expr2 ORDER BY order_expr2)
            FROM ... WHERE ... etc
            {noformat}

            The query should be evaluated as follows:
            * sort the result according to part_expr1/order_expr1, compute values of window_func1
            * sort the result according to part_expr2/order_expr2, compute values of window_func2
            windowing functions as in the SQL standard

            h1. Spec draft

            h2. Place in the optimizer
            Window functions are evaluated on the result set after the WHERE, GROUP BY and HAVING have been applied.
            * If we are operating after a temptable-based grouping operation, we can read its output (and apply HAVING on the fly)
            * if we are operating after a Join operation, or non-temptable based grouping, we will need to store the output of previous operation in a temptable and then work from there.

            h2. Basic idea about operation

            Let's start with one window function:

            {noformat}
            func_name(arg) OVER (PARTITION BY part_expr ORDER BY order_expr $window_spec)
            {noformat}

            Window function is evaluated for each row of the result set. It is a function of row's partition, we need to look at the rows of the resultset that are ordered according to order_expr. $window_spec specifies at which rows we need to look. Sometimes it's certain preceding rows, sometimes it's certain following rows (and sometimes it's both?)

            Execution can be done as follows:
            * sort resultset rows by (part_expr, order_expr).
            * scan each partition (either in reverse or forward order) and compute the value of window function on the fly.

            Unresolved questions:
            - How to handle the context. If a window function depends on preceding and following rows, how do we keep in mind those?

            - Whether we should use files or temp.tables for storing the sorted resultset (we will always have to store it, because filesort doesn't support pull-based reading of its resultset)

            h2. Multiple window functions
            A query may use multiple window functions which use different PARTITION BY / ORDER BY expressions:
            {noformat}
            SELECT
               window_func1 OVER (PARTITION BY part_expr1 ORDER BY order_expr1)
               window_func2 OVER (PARTITION BY part_expr2 ORDER BY order_expr2)
            FROM ... WHERE ... etc
            {noformat}

            The query should be evaluated as follows:
            * sort the result according to part_expr1/order_expr1, compute values of window_func1
            * sort the result according to part_expr2/order_expr2, compute values of window_func2
            psergei Sergei Petrunia made changes -
            Description windowing functions as in the SQL standard

            h1. Spec draft

            h2. Place in the optimizer
            Window functions are evaluated on the result set after the WHERE, GROUP BY and HAVING have been applied.
            * If we are operating after a temptable-based grouping operation, we can read its output (and apply HAVING on the fly)
            * if we are operating after a Join operation, or non-temptable based grouping, we will need to store the output of previous operation in a temptable and then work from there.

            h2. Basic idea about operation

            Let's start with one window function:

            {noformat}
            func_name(arg) OVER (PARTITION BY part_expr ORDER BY order_expr $window_spec)
            {noformat}

            Window function is evaluated for each row of the result set. It is a function of row's partition, we need to look at the rows of the resultset that are ordered according to order_expr. $window_spec specifies at which rows we need to look. Sometimes it's certain preceding rows, sometimes it's certain following rows (and sometimes it's both?)

            Execution can be done as follows:
            * sort resultset rows by (part_expr, order_expr).
            * scan each partition (either in reverse or forward order) and compute the value of window function on the fly.

            Unresolved questions:
            - How to handle the context. If a window function depends on preceding and following rows, how do we keep in mind those?

            - Whether we should use files or temp.tables for storing the sorted resultset (we will always have to store it, because filesort doesn't support pull-based reading of its resultset)

            h2. Multiple window functions
            A query may use multiple window functions which use different PARTITION BY / ORDER BY expressions:
            {noformat}
            SELECT
               window_func1 OVER (PARTITION BY part_expr1 ORDER BY order_expr1)
               window_func2 OVER (PARTITION BY part_expr2 ORDER BY order_expr2)
            FROM ... WHERE ... etc
            {noformat}

            The query should be evaluated as follows:
            * sort the result according to part_expr1/order_expr1, compute values of window_func1
            * sort the result according to part_expr2/order_expr2, compute values of window_func2
            windowing functions as in the SQL standard

            h1. Spec draft

            h2. Place in the optimizer
            Window functions are evaluated on the result set after the WHERE, GROUP BY and HAVING have been applied.
            * If we are operating after a temptable-based grouping operation, we can read its output (and apply HAVING on the fly)
            * if we are operating after a Join operation, or non-temptable based grouping, we will need to store the output of previous operation in a temptable and then work from there.

            h2. Basic idea about operation

            Let's start with one window function:

            {noformat}
            func_name(arg) OVER (PARTITION BY part_expr ORDER BY order_expr $window_spec)
            {noformat}

            Window function is evaluated for each row of the result set. It is a function of row's partition, we need to look at the rows of the resultset that are ordered according to order_expr. $window_spec specifies at which rows we need to look. Sometimes it's certain preceding rows, sometimes it's certain following rows (and sometimes it's both?)

            Execution can be done as follows:
            * sort resultset rows by (part_expr, order_expr).
            * scan each partition (either in reverse or forward order) and compute the value of window function on the fly.

            Unresolved questions:
            - How to handle the context. If a window function depends on preceding and following rows, how do we keep in mind those?

            - Whether we should use files or temp.tables for storing the sorted resultset (we will always have to store it, because filesort doesn't support pull-based reading of its resultset. I)

            h2. Multiple window functions
            A query may use multiple window functions which use different PARTITION BY / ORDER BY expressions:
            {noformat}
            SELECT
               window_func1 OVER (PARTITION BY part_expr1 ORDER BY order_expr1)
               window_func2 OVER (PARTITION BY part_expr2 ORDER BY order_expr2)
            FROM ... WHERE ... etc
            {noformat}

            The query should be evaluated as follows:
            * sort the result according to part_expr1/order_expr1, compute values of window_func1
            * sort the result according to part_expr2/order_expr2, compute values of window_func2
            psergei Sergei Petrunia made changes -
            Description windowing functions as in the SQL standard

            h1. Spec draft

            h2. Place in the optimizer
            Window functions are evaluated on the result set after the WHERE, GROUP BY and HAVING have been applied.
            * If we are operating after a temptable-based grouping operation, we can read its output (and apply HAVING on the fly)
            * if we are operating after a Join operation, or non-temptable based grouping, we will need to store the output of previous operation in a temptable and then work from there.

            h2. Basic idea about operation

            Let's start with one window function:

            {noformat}
            func_name(arg) OVER (PARTITION BY part_expr ORDER BY order_expr $window_spec)
            {noformat}

            Window function is evaluated for each row of the result set. It is a function of row's partition, we need to look at the rows of the resultset that are ordered according to order_expr. $window_spec specifies at which rows we need to look. Sometimes it's certain preceding rows, sometimes it's certain following rows (and sometimes it's both?)

            Execution can be done as follows:
            * sort resultset rows by (part_expr, order_expr).
            * scan each partition (either in reverse or forward order) and compute the value of window function on the fly.

            Unresolved questions:
            - How to handle the context. If a window function depends on preceding and following rows, how do we keep in mind those?

            - Whether we should use files or temp.tables for storing the sorted resultset (we will always have to store it, because filesort doesn't support pull-based reading of its resultset. I)

            h2. Multiple window functions
            A query may use multiple window functions which use different PARTITION BY / ORDER BY expressions:
            {noformat}
            SELECT
               window_func1 OVER (PARTITION BY part_expr1 ORDER BY order_expr1)
               window_func2 OVER (PARTITION BY part_expr2 ORDER BY order_expr2)
            FROM ... WHERE ... etc
            {noformat}

            The query should be evaluated as follows:
            * sort the result according to part_expr1/order_expr1, compute values of window_func1
            * sort the result according to part_expr2/order_expr2, compute values of window_func2
            windowing functions as in the SQL standard

            h1. Spec draft

            h2. Place in the optimizer
            Window functions are evaluated on the result set after the WHERE, GROUP BY and HAVING have been applied.
            * If we are operating after a temptable-based grouping operation, we can read its output (and apply HAVING on the fly)
            * if we are operating after a Join operation, or non-temptable based grouping, we will need to store the output of previous operation in a temptable and then work from there.

            h2. Basic idea about operation

            Let's start with one window function:

            {noformat}
            func_name(arg) OVER (PARTITION BY part_expr ORDER BY order_expr $window_spec)
            {noformat}

            Window function is evaluated for each row of the result set. It is a function of row's partition, we need to look at the rows of the resultset that are ordered according to order_expr. $window_spec specifies at which rows we need to look. Sometimes it's certain preceding rows, sometimes it's certain following rows (and sometimes it's both?)

            Execution can be done as follows:
            * sort resultset rows by (part_expr, order_expr).
            * scan each partition (either in reverse or forward order) and compute the value of window function on the fly.

            Unresolved questions:
            - How to handle the context. If a window function depends on preceding and following rows, how do we keep in mind those?

            - Whether we should use files or temp.tables for storing the sorted resultset (we will always have to store it, because filesort doesn't support pull-based reading of its resultset)

            h2. Multiple window functions
            A query may use multiple window functions which use different PARTITION BY / ORDER BY expressions:
            {noformat}
            SELECT
               window_func1 OVER (PARTITION BY part_expr1 ORDER BY order_expr1)
               window_func2 OVER (PARTITION BY part_expr2 ORDER BY order_expr2)
            FROM ... WHERE ... etc
            {noformat}

            The query should be evaluated as follows:
            * sort the result according to part_expr1/order_expr1, compute values of window_func1
            * sort the result according to part_expr2/order_expr2, compute values of window_func2
            psergei Sergei Petrunia made changes -
            Description windowing functions as in the SQL standard

            h1. Spec draft

            h2. Place in the optimizer
            Window functions are evaluated on the result set after the WHERE, GROUP BY and HAVING have been applied.
            * If we are operating after a temptable-based grouping operation, we can read its output (and apply HAVING on the fly)
            * if we are operating after a Join operation, or non-temptable based grouping, we will need to store the output of previous operation in a temptable and then work from there.

            h2. Basic idea about operation

            Let's start with one window function:

            {noformat}
            func_name(arg) OVER (PARTITION BY part_expr ORDER BY order_expr $window_spec)
            {noformat}

            Window function is evaluated for each row of the result set. It is a function of row's partition, we need to look at the rows of the resultset that are ordered according to order_expr. $window_spec specifies at which rows we need to look. Sometimes it's certain preceding rows, sometimes it's certain following rows (and sometimes it's both?)

            Execution can be done as follows:
            * sort resultset rows by (part_expr, order_expr).
            * scan each partition (either in reverse or forward order) and compute the value of window function on the fly.

            Unresolved questions:
            - How to handle the context. If a window function depends on preceding and following rows, how do we keep in mind those?

            - Whether we should use files or temp.tables for storing the sorted resultset (we will always have to store it, because filesort doesn't support pull-based reading of its resultset)

            h2. Multiple window functions
            A query may use multiple window functions which use different PARTITION BY / ORDER BY expressions:
            {noformat}
            SELECT
               window_func1 OVER (PARTITION BY part_expr1 ORDER BY order_expr1)
               window_func2 OVER (PARTITION BY part_expr2 ORDER BY order_expr2)
            FROM ... WHERE ... etc
            {noformat}

            The query should be evaluated as follows:
            * sort the result according to part_expr1/order_expr1, compute values of window_func1
            * sort the result according to part_expr2/order_expr2, compute values of window_func2
            windowing functions as in the SQL standard

            h1. Spec draft

            h2. Place in the optimizer
            Window functions are evaluated on the result set after the WHERE, GROUP BY and HAVING have been applied.
            * If we are operating after a temptable-based grouping operation, we can read its output (and apply HAVING on the fly)
            * if we are operating after a Join operation, or non-temptable based grouping, we will need to store the output of previous operation in a temptable and then work from there.

            h2. Basic idea about operation

            Let's start with one window function:

            {noformat}
            func_name(arg) OVER (PARTITION BY part_expr ORDER BY order_expr $window_spec)
            {noformat}

            Window function is evaluated for each row of the result set. It is a function of row's partition, we need to look at the rows of the resultset that are ordered according to order_expr. $window_spec specifies at which rows we need to look. Sometimes it's certain preceding rows, sometimes it's certain following rows (and sometimes it's both?)

            Execution can be done as follows:
            * sort resultset rows by (part_expr, order_expr).
            * scan each partition (either in reverse or forward order) and compute the value of window function on the fly.

            Unresolved questions:
            - How to handle the context. If a window function depends on preceding and following rows, how do we keep track of those?

            - Whether we should use files or temp.tables for storing the sorted resultset (we will always have to store it, because filesort doesn't support pull-based reading of its resultset)

            h2. Multiple window functions
            A query may use multiple window functions which use different PARTITION BY / ORDER BY expressions:
            {noformat}
            SELECT
               window_func1 OVER (PARTITION BY part_expr1 ORDER BY order_expr1)
               window_func2 OVER (PARTITION BY part_expr2 ORDER BY order_expr2)
            FROM ... WHERE ... etc
            {noformat}

            The query should be evaluated as follows:
            * sort the result according to part_expr1/order_expr1, compute values of window_func1
            * sort the result according to part_expr2/order_expr2, compute values of window_func2
            psergei Sergei Petrunia made changes -
            Description windowing functions as in the SQL standard

            h1. Spec draft

            h2. Place in the optimizer
            Window functions are evaluated on the result set after the WHERE, GROUP BY and HAVING have been applied.
            * If we are operating after a temptable-based grouping operation, we can read its output (and apply HAVING on the fly)
            * if we are operating after a Join operation, or non-temptable based grouping, we will need to store the output of previous operation in a temptable and then work from there.

            h2. Basic idea about operation

            Let's start with one window function:

            {noformat}
            func_name(arg) OVER (PARTITION BY part_expr ORDER BY order_expr $window_spec)
            {noformat}

            Window function is evaluated for each row of the result set. It is a function of row's partition, we need to look at the rows of the resultset that are ordered according to order_expr. $window_spec specifies at which rows we need to look. Sometimes it's certain preceding rows, sometimes it's certain following rows (and sometimes it's both?)

            Execution can be done as follows:
            * sort resultset rows by (part_expr, order_expr).
            * scan each partition (either in reverse or forward order) and compute the value of window function on the fly.

            Unresolved questions:
            - How to handle the context. If a window function depends on preceding and following rows, how do we keep track of those?

            - Whether we should use files or temp.tables for storing the sorted resultset (we will always have to store it, because filesort doesn't support pull-based reading of its resultset)

            h2. Multiple window functions
            A query may use multiple window functions which use different PARTITION BY / ORDER BY expressions:
            {noformat}
            SELECT
               window_func1 OVER (PARTITION BY part_expr1 ORDER BY order_expr1)
               window_func2 OVER (PARTITION BY part_expr2 ORDER BY order_expr2)
            FROM ... WHERE ... etc
            {noformat}

            The query should be evaluated as follows:
            * sort the result according to part_expr1/order_expr1, compute values of window_func1
            * sort the result according to part_expr2/order_expr2, compute values of window_func2
            windowing functions as in the SQL standard

            h1. Spec draft

            h2. Place in the optimizer
            Window functions are evaluated on the result set after the WHERE, GROUP BY and HAVING have been applied.
            * If we are operating after a temptable-based grouping operation, we can read its output (and apply HAVING on the fly)
            * if we are operating after a Join operation, or non-temptable based grouping, we will need to store the output of previous operation in a temptable and then work from there.

            h2. Basic idea about operation

            Let's start with one window function:

            {noformat}
            func_name(arg) OVER (PARTITION BY part_expr ORDER BY order_expr $window_spec)
            {noformat}

            Window function is evaluated for each row of the result set. It is a function of row's partition, we need to look at the rows of the resultset that are ordered according to order_expr. $window_spec specifies at which rows we need to look. Sometimes it's certain preceding rows, sometimes it's certain following rows (and sometimes it's both?)

            Execution can be done as follows:
            * sort resultset rows by (part_expr, order_expr).
            * scan each partition (either in reverse or forward order) and compute the value of window function on the fly.

            Unresolved questions:
            - How to handle the context. If a window function depends on preceding and following rows, how do we keep track of those?

            - Whether we should use files or temp.tables for storing the sorted resultset (we will always have to store it, because filesort doesn't support pull-based reading of its resultset)

            h2. Multiple window functions
            A query may use multiple window functions which use different PARTITION BY / ORDER BY expressions:
            {noformat}
            SELECT
               window_func1 OVER (PARTITION BY part_expr1 ORDER BY order_expr1)
               window_func2 OVER (PARTITION BY part_expr2 ORDER BY order_expr2)
            FROM ... WHERE ... etc
            {noformat}

            The query should be evaluated as follows:
            * sort the result according to part_expr1/order_expr1, compute values of window_func1
            * sort the result according to part_expr2/order_expr2, compute values of window_func2

            h2. Links
            * a tutorial http://sqlschool.modeanalytics.com/advanced/window-functions.html
            *
            psergei Sergei Petrunia made changes -
            ratzpo Rasmus Johansson (Inactive) made changes -
            Workflow MariaDB v2 [ 42505 ] MariaDB v3 [ 66745 ]
            serg Sergei Golubchik made changes -
            Summary windowing functions as in the SQL standard window functions as in the SQL standard
            serg Sergei Golubchik made changes -
            Description windowing functions as in the SQL standard

            h1. Spec draft

            h2. Place in the optimizer
            Window functions are evaluated on the result set after the WHERE, GROUP BY and HAVING have been applied.
            * If we are operating after a temptable-based grouping operation, we can read its output (and apply HAVING on the fly)
            * if we are operating after a Join operation, or non-temptable based grouping, we will need to store the output of previous operation in a temptable and then work from there.

            h2. Basic idea about operation

            Let's start with one window function:

            {noformat}
            func_name(arg) OVER (PARTITION BY part_expr ORDER BY order_expr $window_spec)
            {noformat}

            Window function is evaluated for each row of the result set. It is a function of row's partition, we need to look at the rows of the resultset that are ordered according to order_expr. $window_spec specifies at which rows we need to look. Sometimes it's certain preceding rows, sometimes it's certain following rows (and sometimes it's both?)

            Execution can be done as follows:
            * sort resultset rows by (part_expr, order_expr).
            * scan each partition (either in reverse or forward order) and compute the value of window function on the fly.

            Unresolved questions:
            - How to handle the context. If a window function depends on preceding and following rows, how do we keep track of those?

            - Whether we should use files or temp.tables for storing the sorted resultset (we will always have to store it, because filesort doesn't support pull-based reading of its resultset)

            h2. Multiple window functions
            A query may use multiple window functions which use different PARTITION BY / ORDER BY expressions:
            {noformat}
            SELECT
               window_func1 OVER (PARTITION BY part_expr1 ORDER BY order_expr1)
               window_func2 OVER (PARTITION BY part_expr2 ORDER BY order_expr2)
            FROM ... WHERE ... etc
            {noformat}

            The query should be evaluated as follows:
            * sort the result according to part_expr1/order_expr1, compute values of window_func1
            * sort the result according to part_expr2/order_expr2, compute values of window_func2

            h2. Links
            * a tutorial http://sqlschool.modeanalytics.com/advanced/window-functions.html
            *
            h1. Spec draft

            h2. Place in the optimizer
            Window functions are evaluated on the result set after the WHERE, GROUP BY and HAVING have been applied.
            * If we are operating after a temptable-based grouping operation, we can read its output (and apply HAVING on the fly)
            * if we are operating after a Join operation, or non-temptable based grouping, we will need to store the output of previous operation in a temptable and then work from there.

            h2. Basic idea about operation

            Let's start with one window function:

            {noformat}
            func_name(arg) OVER (PARTITION BY part_expr ORDER BY order_expr $window_spec)
            {noformat}

            Window function is evaluated for each row of the result set. It is a function of row's partition, we need to look at the rows of the resultset that are ordered according to order_expr. $window_spec specifies at which rows we need to look. Sometimes it's certain preceding rows, sometimes it's certain following rows (and sometimes it's both?)

            Execution can be done as follows:
            * sort resultset rows by (part_expr, order_expr).
            * scan each partition (either in reverse or forward order) and compute the value of window function on the fly.

            Unresolved questions:
            - How to handle the context. If a window function depends on preceding and following rows, how do we keep track of those?

            - Whether we should use files or temp.tables for storing the sorted resultset (we will always have to store it, because filesort doesn't support pull-based reading of its resultset)

            h2. Multiple window functions
            A query may use multiple window functions which use different PARTITION BY / ORDER BY expressions:
            {noformat}
            SELECT
               window_func1 OVER (PARTITION BY part_expr1 ORDER BY order_expr1)
               window_func2 OVER (PARTITION BY part_expr2 ORDER BY order_expr2)
            FROM ... WHERE ... etc
            {noformat}

            The query should be evaluated as follows:
            * sort the result according to part_expr1/order_expr1, compute values of window_func1
            * sort the result according to part_expr2/order_expr2, compute values of window_func2

            h2. Links
            * a tutorial http://sqlschool.modeanalytics.com/advanced/window-functions.html
            *
            serg Sergei Golubchik made changes -
            Fix Version/s 10.2 [ 14601 ]
            serg Sergei Golubchik made changes -
            psergei Sergei Petrunia made changes -
            Description h1. Spec draft

            h2. Place in the optimizer
            Window functions are evaluated on the result set after the WHERE, GROUP BY and HAVING have been applied.
            * If we are operating after a temptable-based grouping operation, we can read its output (and apply HAVING on the fly)
            * if we are operating after a Join operation, or non-temptable based grouping, we will need to store the output of previous operation in a temptable and then work from there.

            h2. Basic idea about operation

            Let's start with one window function:

            {noformat}
            func_name(arg) OVER (PARTITION BY part_expr ORDER BY order_expr $window_spec)
            {noformat}

            Window function is evaluated for each row of the result set. It is a function of row's partition, we need to look at the rows of the resultset that are ordered according to order_expr. $window_spec specifies at which rows we need to look. Sometimes it's certain preceding rows, sometimes it's certain following rows (and sometimes it's both?)

            Execution can be done as follows:
            * sort resultset rows by (part_expr, order_expr).
            * scan each partition (either in reverse or forward order) and compute the value of window function on the fly.

            Unresolved questions:
            - How to handle the context. If a window function depends on preceding and following rows, how do we keep track of those?

            - Whether we should use files or temp.tables for storing the sorted resultset (we will always have to store it, because filesort doesn't support pull-based reading of its resultset)

            h2. Multiple window functions
            A query may use multiple window functions which use different PARTITION BY / ORDER BY expressions:
            {noformat}
            SELECT
               window_func1 OVER (PARTITION BY part_expr1 ORDER BY order_expr1)
               window_func2 OVER (PARTITION BY part_expr2 ORDER BY order_expr2)
            FROM ... WHERE ... etc
            {noformat}

            The query should be evaluated as follows:
            * sort the result according to part_expr1/order_expr1, compute values of window_func1
            * sort the result according to part_expr2/order_expr2, compute values of window_func2

            h2. Links
            * a tutorial http://sqlschool.modeanalytics.com/advanced/window-functions.html
            *
            h1. Spec draft

            h2. Place in the optimizer
            Window functions are evaluated on the result set after the WHERE, GROUP BY and HAVING have been applied.
            * If we are operating after a temptable-based grouping operation, we can read its output (and apply HAVING on the fly)
            * if we are operating after a Join operation, or non-temptable based grouping, we will need to store the output of previous operation in a temptable and then work from there.

            h2. Basic idea about operation

            Let's start with one window function:

            {noformat}
            func_name(arg) OVER (PARTITION BY part_expr ORDER BY order_expr $window_spec)
            {noformat}

            Window function is evaluated for each row of the result set. It is a function of row's partition, we need to look at the rows of the resultset that are ordered according to order_expr. $window_spec specifies at which rows we need to look. Sometimes it's certain preceding rows, sometimes it's certain following rows (and sometimes it's both?)

            Execution can be done as follows:
            * sort resultset rows by (part_expr, order_expr).
            * scan each partition (either in reverse or forward order) and compute the value of window function on the fly.

            Unresolved questions:
            - How to handle the context. If a window function depends on preceding and following rows, how do we keep track of those?

            - Whether we should use files or temp.tables for storing the sorted resultset (we will always have to store it, because filesort doesn't support pull-based reading of its resultset)

            h2. Multiple window functions
            A query may use multiple window functions which use different PARTITION BY / ORDER BY expressions:
            {noformat}
            SELECT
               window_func1 OVER (PARTITION BY part_expr1 ORDER BY order_expr1)
               window_func2 OVER (PARTITION BY part_expr2 ORDER BY order_expr2)
            FROM ... WHERE ... etc
            {noformat}

            The query should be evaluated as follows:
            * sort the result according to part_expr1/order_expr1, compute values of window_func1
            * sort the result according to part_expr2/order_expr2, compute values of window_func2

            h2. Links
            * a tutorial http://sqlschool.modeanalytics.com/advanced/window-functions.html
            * SQL standard draft: see 5CD2-02-Foundation-2006-01.pdf
            ** pg. 62 - 4.15.3 window functions
            ** pg. 204 - <window function>
            psergei Sergei Petrunia made changes -
            psergei Sergei Petrunia made changes -
            psergei Sergei Petrunia made changes -
            psergei Sergei Petrunia made changes -
            psergei Sergei Petrunia made changes -
            igor Igor Babaev (Inactive) made changes -
            psergei Sergei Petrunia made changes -
            psergei Sergei Petrunia made changes -
            psergei Sergei Petrunia made changes -
            psergei Sergei Petrunia made changes -
            psergei Sergei Petrunia made changes -
            psergei Sergei Petrunia made changes -
            psergei Sergei Petrunia made changes -
            psergei Sergei Petrunia made changes -
            psergei Sergei Petrunia made changes -
            psergei Sergei Petrunia made changes -
            psergei Sergei Petrunia made changes -
            psergei Sergei Petrunia made changes -
            psergei Sergei Petrunia made changes -
            psergei Sergei Petrunia made changes -
            psergei Sergei Petrunia made changes -
            psergei Sergei Petrunia made changes -
            psergei Sergei Petrunia made changes -
            psergei Sergei Petrunia made changes -
            elenst Elena Stepanova made changes -
            elenst Elena Stepanova made changes -
            psergei Sergei Petrunia made changes -
            psergei Sergei Petrunia made changes -
            elenst Elena Stepanova made changes -
            Component/s Optimizer - Window functions [ 13502 ]
            psergei Sergei Petrunia made changes -
            psergei Sergei Petrunia made changes -
            psergei Sergei Petrunia made changes -
            GeoffMontee Geoff Montee (Inactive) made changes -
            abienemann Alexander Bienemann (Inactive) made changes -
            serg Sergei Golubchik made changes -
            Fix Version/s 10.2.2 [ 22013 ]
            Resolution Fixed [ 1 ]
            Status Open [ 1 ] Closed [ 6 ]
            serg Sergei Golubchik made changes -
            Workflow MariaDB v3 [ 66745 ] MariaDB v4 [ 132324 ]

            People

              igor Igor Babaev (Inactive)
              serg Sergei Golubchik
              Votes:
              17 Vote for this issue
              Watchers:
              24 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.